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