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