Fix RDBI when configuration is forced (Closes: #2493)
This commit is contained in:
parent
499e811ecf
commit
7a219e1a61
|
@ -16,30 +16,23 @@ sub store {
|
|||
|
||||
my $req;
|
||||
my $lastCfg = $self->lastCfg;
|
||||
$req = $self->_dbh->prepare(
|
||||
"INSERT INTO $self->{dbiTable} (cfgNum,field,value) VALUES (?,?,?)");
|
||||
|
||||
if ( $lastCfg == $cfgNum ) {
|
||||
$req = $self->_dbh->prepare(
|
||||
"UPDATE $self->{dbiTable} SET field=?, value=? WHERE cfgNum=? AND field=?"
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
$req = $self->_dbh->prepare(
|
||||
"INSERT INTO $self->{dbiTable} (cfgNum,field,value) VALUES (?,?,?)"
|
||||
);
|
||||
my $r =
|
||||
$self->_dbh->prepare("DELETE FROM $self->{dbiTable} where cfgNum=?");
|
||||
$r->execute($cfgNum);
|
||||
}
|
||||
unless ($req) {
|
||||
$self->logError;
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
while ( my ( $k, $v ) = each %$fields ) {
|
||||
my @execValues;
|
||||
if ( $lastCfg == $cfgNum ) {
|
||||
@execValues = ( $k, $v, $cfgNum, $k );
|
||||
}
|
||||
else { @execValues = ( $cfgNum, $k, $v ); }
|
||||
my @execValues = ( $cfgNum, $k, $v );
|
||||
my $execute;
|
||||
eval { $execute = $req->execute(@execValues); };
|
||||
print STDERR $@ if $@;
|
||||
unless ($execute) {
|
||||
$self->logError;
|
||||
$self->_dbh->do("ROLLBACK");
|
||||
|
|
|
@ -44,7 +44,6 @@ SKIP: {
|
|||
ok(
|
||||
$h->_dbh->do(
|
||||
"CREATE TABLE lmConfig ( cfgNum int not null, field varchar(255) NOT NULL DEFAULT '', value longblob, PRIMARY KEY (cfgNum,field))"
|
||||
|
||||
),
|
||||
'Test database created'
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@ use Test::More;
|
|||
|
||||
my $count = 0;
|
||||
my $file = 't/conf.db';
|
||||
my $maintests = 1;
|
||||
my $maintests = 8;
|
||||
my ( $res, $client );
|
||||
eval { unlink $file };
|
||||
|
||||
|
@ -25,16 +25,27 @@ SKIP: {
|
|||
}
|
||||
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$file");
|
||||
$dbh->do('CREATE TABLE lmConfig (cfgNum int, data text)')
|
||||
or die $DBI::errstr;
|
||||
$dbh->do(
|
||||
"CREATE TABLE lmConfig ( cfgNum int not null, field varchar(255) NOT NULL DEFAULT '', value longblob, PRIMARY KEY (cfgNum,field))"
|
||||
) or die $DBI::errstr;
|
||||
use_ok('Lemonldap::NG::Common::Conf');
|
||||
my $h;
|
||||
ok(
|
||||
$h = new Lemonldap::NG::Common::Conf( {
|
||||
type => 'RDBI',
|
||||
dbiChain => "DBI:SQLite:dbname=$file",
|
||||
dbiUser => '',
|
||||
dbiPassword => '',
|
||||
}
|
||||
),
|
||||
'RDBI object'
|
||||
);
|
||||
{
|
||||
local $/ = undef;
|
||||
open my $f, '<', 't/conf/lmConf-1.json';
|
||||
my $content = <$f>;
|
||||
close $f;
|
||||
my $sth = $dbh->prepare('INSERT INTO lmConfig VALUES(1,?)')
|
||||
or die $DBI::errstr;
|
||||
$sth->execute($content) or die $DBI::errstr;
|
||||
ok( $h->store( from_json($content) ), 'Conf 1 saved' );
|
||||
}
|
||||
|
||||
use_ok('Lemonldap::NG::Manager::Cli::Lib');
|
||||
|
@ -44,23 +55,16 @@ SKIP: {
|
|||
),
|
||||
'Client object'
|
||||
);
|
||||
count(1);
|
||||
|
||||
use_ok('Lemonldap::NG::Manager::Cli');
|
||||
count(1);
|
||||
|
||||
my @args = (qw(-yes 1 -force 1 set ldapSetPassword 0));
|
||||
$ENV{LLNG_DEFAULTCONFFILE} = 't/lemonldap-ng-DBI-conf.ini';
|
||||
Lemonldap::NG::Manager::Cli->run(@args);
|
||||
my $res = $dbh->selectall_arrayref('SELECT * FROM lmConfig');
|
||||
my $conf = from_json( $res->[0]->[1] );
|
||||
ok( (
|
||||
defined( $conf->{ldapSetPassword} )
|
||||
and $conf->{ldapSetPassword} == 0
|
||||
),
|
||||
'Key inserted'
|
||||
);
|
||||
count(1);
|
||||
my $res = $dbh->selectrow_hashref(
|
||||
"SELECT * FROM lmConfig WHERE field='ldapSetPassword'");
|
||||
ok( $res, 'Key inserted' );
|
||||
ok( $res and $res->{value} == '0', 'Value is 0' );
|
||||
}
|
||||
|
||||
eval { unlink $file };
|
||||
|
|
|
@ -6,7 +6,7 @@ localSessionStorageOptions =
|
|||
|
||||
[configuration]
|
||||
|
||||
type=CDBI
|
||||
type=RDBI
|
||||
dbiChain=dbi:SQLite:dbname=t/conf.db
|
||||
|
||||
[portal]
|
||||
|
|
Loading…
Reference in New Issue
Block a user