Proper new Lemonldap::NG::Common::Notification

This commit is contained in:
Sandro Cazzaniga 2012-07-19 14:17:32 +00:00
parent 8cff113ce5
commit d6ab796359

View File

@ -1,8 +1,8 @@
##@file
# Notification system for Lemonldap::NG portal and manager
# Notification system for Lemonldap::NG
##@class
# Notification system for Lemonldap::NG portal and manager
# Notification system for Lemonldap::NG
package Lemonldap::NG::Common::Notification;
use strict;
@ -21,7 +21,7 @@ our ( $msg, $parser );
## @cmethod Lemonldap::NG::Common::Notification new(hashref storage)
# Constructor.
# @param $storage same syntax as Lemonldap::NG::Common::Conf object
# @return Lemonldap::NG::Common::Notification object
# @return Lemonldap::NG::Portal::Notification object
sub new {
my ( $class, $storage ) = splice @_;
my $self = bless {}, $class;
@ -98,7 +98,7 @@ sub getNotification {
# Prepare HTML code
@files = map { $n->{$_} } sort keys %$n;
my $i = 0;
my $i = 0; # Files count
foreach my $file (@files) {
eval {
my $xml = $parser->parse_string($file);
@ -106,8 +106,7 @@ sub getNotification {
# Browse notifications in file
foreach my $notif (
$xml->documentElement->getElementByTagName('notification')
)
$xml->documentElement->getElementsByTagName('notification') )
{
# Get the reference
@ -162,7 +161,7 @@ sub getNotification {
};
if ($@) {
$self->lmLog(
"Bad XML File: a notification for $uid was not done ($@)",
"Bad XML file: a notification for $uid was not done ($@)",
'warn' );
return 0;
}
@ -256,7 +255,7 @@ sub checkNotification {
# 3. Join results
my $files = {};
if ( $user and $all ) { $files = { %$user, %$all }; }
else { $files = { $user ? $user : $all; }
else { $files = $user ? $user : $all; }
unless ($files) {
$self->lmLog( "Can't find notification $refs->{$ref} for $uid",
@ -265,11 +264,11 @@ sub checkNotification {
}
# Browse found files
foreach my $files ( keys %$files ) {
foreach my $file ( keys %$files ) {
my $xml;
eval { $xml = $parser->parse_string( $files->{$file} ) };
if ($@) {
$self->lmLog( "Bad XML notifications for $uid", 'error' );
$self->lmLog( "Bad XML notification for $uid", 'error' );
next;
}
@ -291,19 +290,22 @@ sub checkNotification {
$self->lmLog(
"$uid has accepted notification $refs->{$ref}",
'notice' );
# 1. Register acceptation in persistent session
my $time = time();
my $notifkey = "notification_" . $refs->{$ref};
$portal->updatePersistentSession(
{ $notifkey => $time },
);
$self->lmLog("Notification " . $refs->{$ref}
$self->lmLog(
"Notification "
. $refs->{$ref}
. " registered in persistent session",
'debug'
);
# 2. Delete it if not a wildcard notification
if ( exists $user->{$file} ) {
@ -311,8 +313,12 @@ sub checkNotification {
$self->lmLog(
"Notification " . $refs->{$ref} . " deleted",
'debug' );
}
else {
$self->lmLog("Unable to delete notification $refs->{$ref} for $uid", 'warn');
$self->lmLog(
"Unable to delete notification $refs->{$ref} for $uid",
'error'
);
}
}
}
@ -457,7 +463,6 @@ sub _newNotif {
1;
__END__
=head1 NAME
@ -468,7 +473,7 @@ Lemonldap::NG::Common::Notification - Provides notification messages system.
=head1 SYNOPSIS
use Lemonldap::NG::Common;
use Lemonldap::NG::Portal;
=head1 DESCRIPTION
@ -477,7 +482,6 @@ Lemonldap::NG::Common::Notification.
=head1 SEE ALSO
L<Lemonldap::NG::Portal>,
L<Lemonldap::NG::Manager>,
=head1 AUTHOR
@ -502,3 +506,5 @@ it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.
=cut