Fix file extension for notifications (#2089)

This commit is contained in:
Christophe Maudoux 2020-02-11 20:14:25 +01:00
parent a75c35fe29
commit c9eb48b59e
3 changed files with 19 additions and 7 deletions

View File

@ -4,7 +4,7 @@ use strict;
use Mouse;
use JSON qw(to_json);
our $VERSION = '2.0.7';
our $VERSION = '2.0.8';
extends 'Lemonldap::NG::Common::Module';
@ -19,6 +19,11 @@ sub import {
}
}
has extension => (
is => 'rw',
default => 'json'
);
has notifField => (
is => 'rw',
builder => sub {
@ -31,6 +36,12 @@ has notifField => (
}
);
sub BUILD {
my $self = shift;
$self->extension('xml') if $self->p->conf->{oldNotifFormat};
$self->logger->debug('Use extension "' . $self->extension . '" to store notification files');
}
sub getNotifications {
my ( $self, $uid ) = @_;
my $forAll = $self->get( $self->conf->{notificationWildcard} );

View File

@ -14,11 +14,8 @@ our $VERSION = '2.0.8';
extends 'Lemonldap::NG::Common::Notifications';
our $ext = 'json';
sub import {
shift;
$ext = 'xml' if ( $_[0] eq 'XML' );
return Lemonldap::NG::Common::Notifications->import(@_);
}
@ -38,6 +35,7 @@ has fileNameSeparator => ( is => 'rw', default => '_' );
# If $ref is set, returns only notification corresponding to this reference.
sub get {
my ( $self, $uid, $ref ) = @_;
my $ext = $self->extension;
return () unless ($uid);
my $fns = $self->{fileNameSeparator};
my $identifier = &getIdentifier( $self, $uid, $ref );
@ -64,6 +62,7 @@ sub get {
# keys date, uid, ref and condition.
sub getAll {
my $self = shift;
my $ext = $self->extension;
opendir D, $self->{dirName};
my @notif;
my $fns = $self->{fileNameSeparator};
@ -89,6 +88,7 @@ sub getAll {
# keys date, uid, ref and condition.
sub getExisting {
my $self = shift;
my $ext = $self->extension;
opendir D, $self->{dirName};
my @notif;
my $fns = $self->{fileNameSeparator};
@ -113,6 +113,7 @@ sub getExisting {
# @param $myref identifier returned by get() or getAll()
sub delete {
my ( $self, $myref ) = @_;
my $ext = $self->extension;
my $new = ( $myref =~ /(.*?)(?:\.$ext)$/ )[0] . '.done';
return rename( $self->{dirName} . "/$myref", $self->{dirName} . "/$new" );
}
@ -129,6 +130,7 @@ sub purge {
# Insert a new notification
sub newNotif {
my ( $self, $date, $uid, $ref, $condition, $content ) = @_;
my $ext = $self->extension;
my $fns = $self->{fileNameSeparator};
$fns ||= '_';
my @t = split( /\D+/, $date );

View File

@ -5,6 +5,7 @@ use Lemonldap::NG::Common::Notifications::LDAP "JSON";
use Lemonldap::NG::Common::Logger::Std;
my $res;
my $notif ;
my $maintests = 11;
my $logLevel = 'error';
require 't/test-lib.pm';
@ -25,13 +26,11 @@ my $notificationStorageOptions = {
ldapConfBase => $ldapConfBase,
};
my $notif =
Lemonldap::NG::Common::Notifications::LDAP->new($notificationStorageOptions);
SKIP: {
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
require 't/test-ldap.pm';
use Net::LDAP;
$notif = Lemonldap::NG::Common::Notifications::LDAP->new($notificationStorageOptions);
my $ldap = Net::LDAP->new($ldapServer);
my $mesg = $ldap->bind( $ldapBindDN, password => $ldapBindPassword );
is( $mesg->code, 0, "Bind to LDAP server" ) or diag $mesg->error;