Commit d46d6ce6 authored by sikeda's avatar sikeda
Browse files

[dev] Use Sympa::DatabaseManager instead of SDM.

ToDo: Sympa::List still uses SDM.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12175 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent a1864cff
......@@ -23,22 +23,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib '--modulesdir--';
use lib split(/:/, $ENV{SYMPALIB} || ''), '--modulesdir--';
use strict;
use warnings;
use Conf;
use Sympa::Constants;
use SDM;
use Sympa::DatabaseManager;
## Load sympa config
Conf::load(Sympa::Constants::CONFIG) or die 'config_error';
chdir $Conf::Conf{'home'};
SDM::check_db_connect('just_try') or die "Can't connect to database";
my $sdm = Sympa::DatabaseManager->instance
or die 'Can\'t connect to database';
my $sth = SDM::do_query(
my $sth = $sdm->do_query(
q{SELECT user_subscriber, comment_subscriber
FROM subscriber_table}
) or die 'Unable to execute SQL statement';
......@@ -49,7 +50,7 @@ while ($user = $sth->fetchrow_hashref('NAME_lc')) {
printf "\nUser: %s", $user->{'user_subscriber'};
unless ($user->{'comment_subscriber'}) {
my $sth2 = SDM::do_prepared_query(
my $sth2 = $sdm->do_prepared_query(
q{SELECT gecos_user
FROM user_table
WHERE email_user = ?},
......@@ -61,7 +62,7 @@ while ($user = $sth->fetchrow_hashref('NAME_lc')) {
if ($gecos) {
printf " =>%s", $gecos;
my $sth2 = SDM::do_prepared_query(
my $sth2 = $sdm->do_prepared_query(
q{UPDATE subscriber_table
SET comment_subscriber = ?
WHERE user_subscriber = ?},
......@@ -76,4 +77,4 @@ while ($user = $sth->fetchrow_hashref('NAME_lc')) {
$sth->finish();
## Disconnect from Database
SDM::db_disconnect();
Sympa::DatabaseManager->disconnect();
......@@ -23,7 +23,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib '--modulesdir--';
use lib split(/:/, $ENV{SYMPALIB} || ''), '--modulesdir--';
use strict;
use warnings;
use English qw(-no_match_vars);
......@@ -34,8 +34,8 @@ use Pod::Usage;
use Sympa::Bulk;
use Conf;
use Sympa::Constants;
use Sympa::DatabaseManager;
use Sympa::Log;
use SDM;
use Sympa::Spool;
my %options;
......@@ -81,10 +81,13 @@ exit 0;
sub process {
my $bulk = Sympa::Bulk->new;
my $sth = SDM::do_prepared_query(
my $sdm = Sympa::DatabaseManager->instance
or die 'Can\'t connect to database';
my $sth = $sdm->do_prepared_query(
q{SELECT *
FROM bulkmailer_table
WHERE returnpath_bulkmailer IS NOT NULL}
FROM bulkmailer_table
WHERE returnpath_bulkmailer IS NOT NULL}
);
unless ($sth) {
die
......@@ -118,10 +121,10 @@ sub process {
# Fetch message
my $messagekey = $row_mailer->{messagekey_bulkmailer};
my $sth2 = SDM::do_prepared_query(
my $sth2 = $sdm->do_prepared_query(
q{SELECT *
FROM bulkspool_table
WHERE messagekey_bulkspool = ?},
FROM bulkspool_table
WHERE messagekey_bulkspool = ?},
$messagekey
);
unless ($sth2) {
......
......@@ -23,25 +23,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib '--modulesdir--';
use lib split(/:/, $ENV{SYMPALIB} || ''), '--modulesdir--';
use strict;
use warnings;
use Sympa::Auth;
use Conf;
use SDM;
use Sympa::DatabaseManager;
use Sympa::Tools::Password;
die "Crypt::CipherSaber not installed ; cannot crypt passwords"
unless Sympa::Tools::Password::ciphersaber_installed();
die 'Error in configuration'
unless Conf::load(Conf::get_sympa_conf(), 'no_db');
die 'Can\'t connect to database'
unless SDM::check_db_connect('just_try');
my $sdm = Sympa::DatabaseManager->instacne
or die 'Can\'t connect to database';
print "Recoding password using MD5 fingerprint.\n";
my $sth = SDM::do_query(q{SELECT email_user, password_user from user_table});
my $sth = $sdm->do_query(q{SELECT email_user, password_user from user_table});
unless ($sth) {
die 'Unable to prepare SQL statement';
}
......@@ -75,10 +75,10 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
## Updating Db
unless (
SDM::do_prepared_query(
$sdm->do_prepared_query(
q{UPDATE user_table
SET password_user = ?
WHERE email_user = ?},
SET password_user = ?
WHERE email_user = ?},
Sympa::Auth::password_fingerprint($clear_password),
$user->{'email_user'}
)
......
......@@ -31,6 +31,7 @@ use SOAP::Lite;
## Sympa API
use Conf;
use Sympa::DatabaseManager;
use Sympa::List;
use Sympa::Log;
use Sympa::SOAP;
......@@ -62,7 +63,7 @@ $log->syslog('info', 'SympaSOAP started');
$UID = $EUID; ## UID
$GID = $EGID; ## GID
unless (SDM::check_db_connect()) {
unless (Sympa::DatabaseManager->instance) {
$log->syslog('err', 'SympaSOAP requires a RDBMS to run');
}
......
......@@ -34,10 +34,10 @@ use Storable;
use Sympa;
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::LockedFile;
use Sympa::Log;
use SDM;
use tools;
use Sympa::Tools::Data;
use Sympa::Tools::File;
......@@ -453,7 +453,6 @@ sub get_parameters_group {
## fetch the value from parameter $label of robot $robot from conf_table
sub get_db_conf {
my $robot = shift;
my $label = shift;
......@@ -462,11 +461,14 @@ sub get_db_conf {
$robot = '*' unless (-f $Conf{'etc'} . '/' . $robot . '/robot.conf');
unless ($robot) { $robot = '*' }
my $sdm = Sympa::DatabaseManager->instance;
unless (
$sth = SDM::do_query(
"SELECT value_conf AS value FROM conf_table WHERE (robot_conf =%s AND label_conf =%s)",
SDM::quote($robot),
SDM::quote($label)
$sdm
and $sth = $sdm->do_prepared_query(
q{SELECT value_conf AS value
FROM conf_table
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label
)
) {
$log->syslog(
......@@ -501,11 +503,14 @@ sub set_robot_conf {
$robot = '*';
}
my $sdm = Sympa::DatabaseManager->instance;
unless (
$sth = SDM::do_query(
"SELECT count(*) FROM conf_table WHERE (robot_conf=%s AND label_conf =%s)",
SDM::quote($robot),
SDM::quote($label)
$sdm
and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM conf_table
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label
)
) {
$log->syslog(
......@@ -522,11 +527,11 @@ sub set_robot_conf {
if ($count == 0) {
unless (
$sth = SDM::do_query(
"INSERT INTO conf_table (robot_conf, label_conf, value_conf) VALUES (%s,%s,%s)",
SDM::quote($robot),
SDM::quote($label),
SDM::quote($value)
$sth = $sdm->do_prepared_query(
q{INSERT INTO conf_table
(robot_conf, label_conf, value_conf)
VALUES (?, ?, ?)},
$robot, $label, $value
)
) {
$log->syslog(
......@@ -540,13 +545,12 @@ sub set_robot_conf {
}
} else {
unless (
$sth = SDM::do_query(
"UPDATE conf_table SET robot_conf=%s, label_conf=%s, value_conf=%s WHERE ( robot_conf =%s AND label_conf =%s)",
SDM::quote($robot),
SDM::quote($label),
SDM::quote($value),
SDM::quote($robot),
SDM::quote($label)
$sth = $sdm->do_prepared_query(
q{UPDATE conf_table
SET robot_conf = ?, label_conf = ?, value_conf = ?
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label, $value,
$robot, $label
)
) {
$log->syslog(
......
......@@ -45,6 +45,7 @@ use File::Copy qw();
use Sympa;
use Conf;
use Sympa::Constants;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::List;
use Sympa::LockedFile;
......@@ -52,7 +53,6 @@ use Sympa::Log;
use Sympa::Regexps;
use Sympa::Robot;
use Sympa::Scenario;
use SDM;
use Sympa::Template;
use Sympa::Tools::File;
use Sympa::User;
......@@ -963,14 +963,18 @@ sub rename_list {
Sympa::List::rename_list_db($list, $param{'new_listname'},
$param{'new_robot'});
}
## Move stats
my $sdm = Sympa::DatabaseManager->instance;
# Move stats
unless (
SDM::do_query(
"UPDATE stat_table SET list_stat=%s, robot_stat=%s WHERE (list_stat = %s AND robot_stat = %s )",
SDM::quote($param{'new_listname'}),
SDM::quote($param{'new_robot'}),
SDM::quote($list->{'name'}),
SDM::quote($robot)
$sdm
and $sdm->do_prepared_query(
q{UPDATE stat_table
SET list_stat = ?, robot_stat = ?
WHERE list_stat = ? AND robot_stat = ?},
$param{'new_listname'}, $param{'new_robot'},
$list->{'name'}, $robot
)
) {
$log->syslog(
......@@ -983,14 +987,14 @@ sub rename_list {
);
}
## Move stat counters
# Move stat counters
unless (
SDM::do_query(
"UPDATE stat_counter_table SET list_counter=%s, robot_counter=%s WHERE (list_counter = %s AND robot_counter = %s )",
SDM::quote($param{'new_listname'}),
SDM::quote($param{'new_robot'}),
SDM::quote($list->{'name'}),
SDM::quote($robot)
$sdm->do_prepared_query(
q{UPDATE stat_counter_table
SET list_counter = ?, robot_counter = ?
WHERE list_counter = ? AND robot_counter = ?},
$param{'new_listname'}, $param{'new_robot'},
$list->{'name'}, $robot
)
) {
$log->syslog(
......
......@@ -32,10 +32,10 @@ use POSIX qw();
use Sympa;
use Conf;
use Sympa::Database;
use Sympa::DatabaseManager;
use Sympa::Log;
use Sympa::Report;
use Sympa::Robot;
use SDM;
use Sympa::Session;
use tools;
use Sympa::Tools::Data;
......@@ -483,17 +483,20 @@ sub create_one_time_ticket {
# $email, $robot, $data_string, $remote_addr, $ticket);
my $date = time;
my $sth;
my $sdm = Sympa::DatabaseManager->instance;
unless (
SDM::do_prepared_query(
$sdm
and $sdm->do_prepared_query(
q{INSERT INTO one_time_ticket_table
(ticket_one_time_ticket, robot_one_time_ticket,
email_one_time_ticket, date_one_time_ticket, data_one_time_ticket,
remote_addr_one_time_ticket, status_one_time_ticket)
VALUES (?, ?, ?, ?, ?, ?, ?)},
(ticket_one_time_ticket, robot_one_time_ticket,
email_one_time_ticket, date_one_time_ticket,
data_one_time_ticket,
remote_addr_one_time_ticket, status_one_time_ticket)
VALUES (?, ?, ?, ?, ?, ?, ?)},
$ticket, $robot,
$email, time, $data_string,
$email, time,
$data_string,
$remote_addr, 'open'
)
) {
......@@ -516,18 +519,19 @@ sub get_one_time_ticket {
my $addr = shift;
my $sth;
my $sdm = Sympa::DatabaseManager->instance;
unless (
$sth = SDM::do_prepared_query(
$sdm
and $sth = $sdm->do_prepared_query(
q{SELECT ticket_one_time_ticket AS ticket,
robot_one_time_ticket AS robot,
email_one_time_ticket AS email,
date_one_time_ticket AS "date",
data_one_time_ticket AS data,
remote_addr_one_time_ticket AS remote_addr,
status_one_time_ticket as status
FROM one_time_ticket_table
WHERE ticket_one_time_ticket = ? AND robot_one_time_ticket = ?},
robot_one_time_ticket AS robot,
email_one_time_ticket AS email,
date_one_time_ticket AS "date",
data_one_time_ticket AS data,
remote_addr_one_time_ticket AS remote_addr,
status_one_time_ticket as status
FROM one_time_ticket_table
WHERE ticket_one_time_ticket = ? AND robot_one_time_ticket = ?},
$ticket_number, $robot
)
) {
......@@ -575,7 +579,7 @@ sub get_one_time_ticket {
if ($result eq 'success') {
unless (
$sth = SDM::do_prepared_query(
$sth = $sdm->do_prepared_query(
q{UPDATE one_time_ticket_table
SET status_one_time_ticket = ?
WHERE ticket_one_time_ticket = ? AND
......
......@@ -413,9 +413,9 @@ sub unset_primary_key {
unless (
$sth = $self->do_query(
q{SELECT tc.constraint_name
FROM information_schema.table_constraints AS tc
WHERE tc.table_catalog = %s AND tc.table_name = %s AND
tc.constraint_type = 'PRIMARY KEY'},
FROM information_schema.table_constraints AS tc
WHERE tc.table_catalog = %s AND tc.table_name = %s AND
tc.constraint_type = 'PRIMARY KEY'},
$self->quote($self->{'db_name'}), $self->quote($param->{'table'})
)
) {
......
......@@ -730,8 +730,8 @@ sub _get_create_table {
unless (
$sth = $self->do_query(
q{SELECT sql
FROM sqlite_master
WHERE type = 'table' AND name = '%s'},
FROM sqlite_master
WHERE type = 'table' AND name = '%s'},
$table
)
) {
......
......@@ -48,6 +48,7 @@ use Sympa::Admin;
use Conf;
use Sympa::Config_XML;
use Sympa::Constants;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::List;
use Sympa::Log;
......@@ -594,25 +595,26 @@ sub modify_list {
}
## rename forbidden files
# foreach my $f (@{$custom->{'forbidden'}{'file'}}) {
# unless (rename ("$list->{'dir'}"."/"."info","$list->{'dir'}"."/"."info.orig")) {
################
# }
# if ($f eq 'info') {
# $hash_list->{'config'}{'description'} =~ s/\r\n|\r/\n/g;
# unless (open INFO, '>', "$list_dir/info") {
################
# }
# print INFO $hash_list->{'config'}{'description'};
# close INFO;
# }
# }
#foreach my $f (@{$custom->{'forbidden'}{'file'}}) {
# unless (rename "$list->{'dir'}"."/"."info",
# "$list->{'dir'}"."/"."info.orig") {
# ###############
# }
# if ($f eq 'info') {
# $hash_list->{'config'}{'description'} =~ s/\r\n|\r/\n/g;
# unless (open INFO, '>', "$list_dir/info") {
# ###############
# }
# print INFO $hash_list->{'config'}{'description'};
# close INFO;
# }
#}
## notify owner for forbidden customizing
if ( #(scalar $custom->{'forbidden'}{'file'}) ||
(scalar @{$custom->{'forbidden'}{'param'}})
) {
# my $forbidden_files = join(',',@{$custom->{'forbidden'}{'file'}});
#my $forbidden_files = join(',',@{$custom->{'forbidden'}{'file'}});
my $forbidden_param = join(',', @{$custom->{'forbidden'}{'param'}});
$log->syslog('notice',
"These parameters aren't allowed in the new family definition, they are erased by a new instantiation family : \n $forbidden_param"
......@@ -1064,12 +1066,12 @@ sub instantiate {
my $answer;
unless ($close_unknown) {
# while (($answer ne 'y') && ($answer ne 'n')) {
#while (($answer ne 'y') && ($answer ne 'n')) {
print STDOUT
"The list $l isn't defined in the new instantiation family, do you want to close it ? (y or n)";
$answer = <STDIN>;
chomp($answer);
#######################
#######################
$answer ||= 'y';
#}
}
......@@ -2127,25 +2129,26 @@ sub _update_existing_list {
}
## rename forbidden files
# foreach my $f (@{$custom->{'forbidden'}{'file'}}) {
# unless (rename ("$list->{'dir'}"."/"."info","$list->{'dir'}"."/"."info.orig")) {
################
# }
# if ($f eq 'info') {
# $hash_list->{'config'}{'description'} =~ s/\r\n|\r/\n/g;
# unless (open INFO, '>', "$list_dir/info") {
################
# }
# print INFO $hash_list->{'config'}{'description'};
# close INFO;
# }
# }
#foreach my $f (@{$custom->{'forbidden'}{'file'}}) {
# unless (rename "$list->{'dir'}"."/"."info",
# "$list->{'dir'}"."/"."info.orig") {
# ###############
# }
# if ($f eq 'info') {
# $hash_list->{'config'}{'description'} =~ s/\r\n|\r/\n/g;
# unless (open INFO, '>', "$list_dir/info") {
# ###############
# }
# print INFO $hash_list->{'config'}{'description'};
# close INFO;
# }
#}
## notify owner for forbidden customizing
if ( #(scalar $custom->{'forbidden'}{'file'}) ||
(scalar @{$custom->{'forbidden'}{'param'}})
) {
# my $forbidden_files = join(',',@{$custom->{'forbidden'}{'file'}});
#my $forbidden_files = join(',',@{$custom->{'forbidden'}{'file'}});
my $forbidden_param = join(',', @{$custom->{'forbidden'}{'param'}});
$log->syslog('notice',
"These parameters aren't allowed in the new family definition, they are erased by a new instantiation family : \n $forbidden_param"
......@@ -2261,14 +2264,13 @@ sub _get_customizing {
}
## FILES
# foreach my $f (keys %{$config_changes->{'file'}}) {
# my $privilege; # =may_edit($f)
# unless ($privilege eq 'write') {
# push @{$result->{'forbidden'}{'file'}},$f;
# }
# }
#foreach my $f (keys %{$config_changes->{'file'}}) {
# my $privilege; # =may_edit($f)
#
# unless ($privilege eq 'write') {
# push @{$result->{'forbidden'}{'file'}},$f;
# }
#}
## PARAMETERS
......@@ -2412,25 +2414,24 @@ sub _set_status_changes {
Sympa::Admin::remove_aliases($list, $self->{'robot'});
}
## ## subscribers
## if (($old_status ne 'pending') && ($old_status ne 'open')) {
##
## if ($list->{'admin'}{'user_data_source'} eq 'file') {
## $list->{'users'} = Sympa::List::_load_list_members_file(
## $list->{'dir'} . '/subscribers.closed.dump');
## } elsif ($list->{'admin'}{'user_data_source'} eq 'database') {
## unless (-f $list->{'dir'} . '/subscribers.closed.dump') {
## $log->syslog('notice', 'No subscribers to restore');
## }
## my @users = Sympa::List::_load_list_members_file(
## $list->{'dir'} . '/subscribers.closed.dump');
##
## ## Insert users in database
## foreach my $user (@users) {
## $list->add_list_member($user);
## }
## }
## }
### subscribers
#if (($old_status ne 'pending') && ($old_status ne 'open')) {
# if ($list->{'admin'}{'user_data_source'} eq 'file') {
# $list->{'users'} = Sympa::List::_load_list_members_file(
# $list->{'dir'} . '/subscribers.closed.dump');
# } elsif ($list->{'admin'}{'user_data_source'} eq 'database') {
# unless (-f $list->{'dir'} . '/subscribers.closed.dump') {
# $log->syslog('notice', 'No subscribers to restore');
# }
# my @users = Sympa::List::_load_list_members_file(
# $list->{'dir'} . '/subscribers.closed.dump');
#
# ## Insert users in database
# foreach my $user (@users) {
# $list->add_list_member($user);
# }
# }
#}
return $result;
}
......@@ -2806,8 +2807,10 @@ sub insert_delete_exclusion {
## Insert: family, user and date
## Add dummy list_exclusion column to satisfy constraint.
my $sdm;
unless (
SDM::do_prepared_query(
$sdm = Sympa::DatabaseManager->instance
and $sdm->do_prepared_query(
q{INSERT INTO exclusion_table
(list_exclusion, family_exclusion, robot_exclusion,
user_exclusion, date_exclusion)
......
......@@ -30,9 +30,9 @@ use Encode qw();
use Sympa;
use Conf;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::Log;
use SDM;
use Sympa::Tools::File;
my $language = Sympa::Language->instance;
......@@ -85,12 +85,16 @@ sub get_netidtoemail_db {
push @sth_stack, $sth;
my $sdm = Sympa::DatabaseManager->instance;
unless (
$sth = SDM::do_query(
"SELECT email_netidmap FROM netidmap_table WHERE netid_netidmap = %s and serviceid_netidmap = %s and robot_netidmap = %s",
SDM::quote($netid),
SDM::quote($idpname),