diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/CDBI.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/CDBI.pm index ee57f93bb..a31363a1a 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/CDBI.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/CDBI.pm @@ -4,20 +4,30 @@ use strict; require Storable; use Lemonldap::NG::Common::Conf::_DBI; -our $VERSION = '1.1.0'; +our $VERSION = '1.4.0'; our @ISA = qw(Lemonldap::NG::Common::Conf::_DBI); sub store { my ( $self, $fields ) = @_; my $cfgNum = $fields->{cfgNum}; + my $req; + my $lastCfg = $self->lastCfg; + $fields = Storable::nfreeze($fields); - my $tmp = $self->_dbh->prepare( - "insert into $self->{dbiTable} (cfgNum,data) values (?,?)"); - unless ($tmp) { + + if ( $lastCfg == $cfgNum ) { + $req = $self->_dbh->prepare( + "UPDATE $self->{dbiTable} SET data=? WHERE cfgNum=?" ); + } + else { + $req = $self->_dbh->prepare( + "INSERT INTO $self->{dbiTable} (data,cfgNum) VALUES (?,?)" ); + } + unless ($req) { $self->logError; return UNKNOWN_ERROR; } - unless ( $tmp->execute( $cfgNum, $fields ) ) { + unless ( $req->execute( $fields, $cfgNum ) ) { $self->logError; return UNKNOWN_ERROR; } diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RDBI.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RDBI.pm index 4ef23869a..f483b8a56 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RDBI.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RDBI.pm @@ -12,17 +12,32 @@ sub store { $self->{noQuotes} = 1; $fields = $self->serialize($fields); - my $req = $self->_dbh->prepare( - "INSERT INTO $self->{dbiTable} (cfgNum,field,value) VALUES (?,?,?)" - ); + my $req; + my $lastCfg = $self->lastCfg; + + if ( $lastCfg == $fields->{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 (?,?,?)" + ); + } unless ($req) { $self->logError; return UNKNOWN_ERROR; } $self->_dbh->{AutoCommit} = 0; - while ( my ( $k, $v ) = each %$fields ) { - unless ( $req->execute( $fields->{cfgNum}, $k, $v ) ) { + my @execValues; + if ( $lastCfg == $fields->{cfgNum} ) { + @execValues = ( $k, $v, $fields->{cfgNum}, $k ); + } + else { @execValues = ( $fields->{cfgNum}, $k, $v ); } + unless ( $req->execute(@execValues) ) { $self->logError; $self->_dbh->do("ROLLBACK"); $self->_dbh->{AutoCommit} = 1;