Commit 3f91d876 authored by Clément OUDOT's avatar Clément OUDOT
Browse files

Adapt convertConfig script to new Conf (#820)

parent d2d84b1c
......@@ -106,10 +106,11 @@ sub new {
return $self;
}
## @method int saveConf(hashRef conf)
## @method int saveConf(hashRef conf, hash args)
# Serialize $conf and call store().
# @param $conf Lemonldap::NG configuration hashRef
# @return Number of the saved configuration, 0 if case of error.
# @param %args Parameters
# @return Number of the saved configuration, 0 in case of error.
sub saveConf {
my ( $self, $conf, %args ) = @_;
......@@ -120,7 +121,7 @@ sub saveConf {
return CONFIG_WAS_CHANGED if ( $conf->{cfgNum} != $last );
return DATABASE_LOCKED if ( $self->isLocked() or not $self->lock() );
}
$conf->{cfgNum} = $last + 1 unless ( $self->{cfgNumFixed} );
$conf->{cfgNum} = $last + 1 unless ( $args{cfgNumFixed} );
delete $conf->{cipher};
# Try to store configuration
......
......@@ -34,10 +34,10 @@ foreach ( $opts{current}, $opts{new} ) {
exit 3;
}
}
my $old = Lemonldap::NG::Common::Conf->new(
{
confFile => $opts{current},
noCache => 1,
}
);
unless ($old) {
......@@ -45,12 +45,16 @@ unless ($old) {
"Failed to get current conf : $Lemonldap::NG::Common::Conf::msg\n";
exit 4;
}
my %newargs = (
force => 1,
noCache => 1,
cfgNumFixed => 1,
);
my $new = Lemonldap::NG::Common::Conf->new(
{
confFile => $opts{new},
force => 1,
noCache => 1,
cfgNumFixed => 1,
confFile => $opts{new},
}
);
unless ($new) {
......@@ -58,6 +62,7 @@ unless ($new) {
"Failed to create new conf object : $Lemonldap::NG::Common::Conf::msg\n";
exit 5;
}
my @available;
if ( $opts{latest} ) {
@available = $old->lastCfg();
......@@ -65,15 +70,16 @@ if ( $opts{latest} ) {
else {
@available = $old->available();
}
foreach (@available) {
my $conf = $old->getConf( { cfgNum => $_ } );
my $conf = $old->getConf( { cfgNum => $_, noCache => 1 } );
unless ($conf) {
print STDERR
"\nFailed to get conf $_ : $Lemonldap::NG::Common::Conf::msg\n";
next if ( $opts{force} );
exit 6;
}
if ( my $r = $new->saveConf($conf) ) {
if ( my $r = $new->saveConf( $conf, %newargs ) ) {
print "Conf $conf->{cfgNum} stored\n";
next;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment