Commit a9fa0776 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

[-change] Database fields update_admin & update_subscriber were obsoleted.

parent f14e405e
......@@ -100,11 +100,17 @@ my %full_db_struct = (
'doc' => 'FIXME',
'order' => 10,
},
'date_subscriber' => {
'struct' => 'datetime',
#'date_subscriber' => {
# 'struct' => 'datetime',
# 'doc' => 'date of subscription',
# 'not_null' => 1,
# 'order' => 11,
#},
'date_epoch_subscriber' => {
'struct' => 'int(11)',
'doc' => 'date of subscription',
'not_null' => 1,
'order' => 11,
'order' => 11.5,
},
# Obsoleted as of 6.2.25b.2. Use update_epoch_subscriber.
#'update_subscriber' => {
......@@ -890,11 +896,17 @@ my %full_db_struct = (
'privilege level for this owner, value //normal// or //privileged//. The related privilege are listed in edit_list.conf. ',
'order' => 5,
},
'date_admin' => {
'struct' => 'datetime',
#'date_admin' => {
# 'struct' => 'datetime',
# 'doc' => 'date this user become a list admin',
# 'not_null' => 1,
# 'order' => 6,
#},
'date_epoch_admin' => {
'struct' => 'int(11)',
'doc' => 'date this user become a list admin',
'not_null' => 1,
'order' => 6,
'order' => 6.5,
},
# Obsoleted as of 6.2.25b.2. Use update_epoch_admin.
#'update_admin' => {
......
......@@ -2477,6 +2477,7 @@ sub get_exclusion {
# Mapping between var and field names.
sub _map_list_member_cols {
my %map_field = (
date => 'date_epoch_subscriber',
update_date => 'update_epoch_subscriber',
gecos => 'comment_subscriber',
email => 'user_subscriber',
......@@ -2516,12 +2517,7 @@ sub _list_member_cols {
my %map_field = _map_list_member_cols();
return join ', ', map {
my $col;
if ($_ eq 'date') {
$col = $sdm->get_canonical_read_date($map_field{$_});
} else {
$col = $map_field{$_};
}
my $col = $map_field{$_};
($col eq $_) ? $col : sprintf('%s AS "%s"', $col, $_);
} sort keys %map_field;
}
......@@ -2898,21 +2894,19 @@ sub _get_admins {
unless (
$sdm and $sth = $sdm->do_prepared_query(
sprintf(
q{SELECT user_admin AS email, comment_admin AS gecos,
role_admin AS "role",
reception_admin AS reception,
visibility_admin AS visibility,
%s AS "date", update_epoch_admin AS update_date,
info_admin AS info, profile_admin AS profile,
subscribed_admin AS subscribed,
included_admin AS included,
include_sources_admin AS id
FROM admin_table
WHERE list_admin = ? AND robot_admin = ?
ORDER BY user_admin},
$sdm->get_canonical_read_date('date_admin')
),
q{SELECT user_admin AS email, comment_admin AS gecos,
role_admin AS "role",
reception_admin AS reception,
visibility_admin AS visibility,
date_epoch_admin AS "date",
update_epoch_admin AS update_date,
info_admin AS info, profile_admin AS profile,
subscribed_admin AS subscribed,
included_admin AS included,
include_sources_admin AS id
FROM admin_table
WHERE list_admin = ? AND robot_admin = ?
ORDER BY user_admin},
$self->{'name'},
$self->{'domain'}
)
......@@ -3431,11 +3425,7 @@ sub update_list_member {
die sprintf 'Unknown database field %s', $field
unless $map_field{$field};
if ($field eq 'date') {
push @set_list,
sprintf('%s = %s',
$map_field{$field}, $sdm->get_canonical_write_date($value));
} elsif ($field eq 'custom_attribute') {
if ($field eq 'custom_attribute') {
push @set_list, sprintf('%s = ?', $map_field{$field});
push @val_list,
Sympa::Tools::Data::encode_custom_attribute($value);
......@@ -3566,7 +3556,7 @@ sub update_list_admin {
my %map_field = (
reception => 'reception_admin',
visibility => 'visibility_admin',
date => 'date_admin',
date => 'date_epoch_admin',
update_date => 'update_epoch_admin',
gecos => 'comment_admin',
password => 'password_user',
......@@ -3619,18 +3609,14 @@ sub update_list_admin {
}
if ($map_table{$field} eq $table) {
if ($field eq 'date') {
$value = $sdm->get_canonical_write_date($value);
} elsif ($value and $value eq 'NULL') { # get_null_value?
if ($value and $value eq 'NULL') { #FIXME:get_null_value?
if ($Conf::Conf{'db_type'} eq 'mysql') {
$value = '\N';
}
} elsif ($numeric_field{$map_field{$field}}) {
$value ||= 0; #FIXME:Can't have a null value
} else {
if ($numeric_field{$map_field{$field}}) {
$value ||= 0; ## Can't have a null value
} else {
$value = $sdm->quote($value);
}
$value = $sdm->quote($value);
}
my $set = sprintf "%s=%s", $map_field{$field}, $value;
......@@ -3835,27 +3821,24 @@ sub add_list_member {
unless (
$sdm
and $sdm->do_prepared_query(
sprintf(
q{INSERT INTO subscriber_table
(user_subscriber, comment_subscriber,
list_subscriber, robot_subscriber,
date_subscriber, update_epoch_subscriber,
reception_subscriber, topics_subscriber,
visibility_subscriber, subscribed_subscriber,
included_subscriber, include_sources_subscriber,
custom_attribute_subscriber,
suspend_subscriber,
suspend_start_date_subscriber,
suspend_end_date_subscriber,
number_messages_subscriber)
VALUES (?, ?, ?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, 0)},
$sdm->get_canonical_write_date($new_user->{'date'})
),
q{INSERT INTO subscriber_table
(user_subscriber, comment_subscriber,
list_subscriber, robot_subscriber,
date_epoch_subscriber, update_epoch_subscriber,
reception_subscriber, topics_subscriber,
visibility_subscriber, subscribed_subscriber,
included_subscriber, include_sources_subscriber,
custom_attribute_subscriber,
suspend_subscriber,
suspend_start_date_subscriber,
suspend_end_date_subscriber,
number_messages_subscriber)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0)},
$who,
$new_user->{'gecos'},
$name,
$self->{'domain'},
$new_user->{'date'},
$new_user->{'update_date'},
$new_user->{'reception'},
$new_user->{'topics'},
......@@ -3975,21 +3958,19 @@ sub add_list_admin {
unless (
$sdm
and $sdm->do_prepared_query(
sprintf(
q{INSERT INTO admin_table
(user_admin, comment_admin, list_admin, robot_admin,
date_admin, update_epoch_admin, reception_admin,
visibility_admin,
subscribed_admin,
included_admin, include_sources_admin,
role_admin, info_admin, profile_admin)
VALUES (?, ?, ?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?)},
$sdm->get_canonical_write_date($new_admin_user->{'date'})
),
q{INSERT INTO admin_table
(user_admin, comment_admin, list_admin, robot_admin,
date_epoch_admin, update_epoch_admin, reception_admin,
visibility_admin,
subscribed_admin,
included_admin, include_sources_admin,
role_admin, info_admin, profile_admin)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)},
$who,
$new_admin_user->{'gecos'},
$name,
$self->{'domain'},
$new_admin_user->{'date'},
$new_admin_user->{'update_date'},
$new_admin_user->{'reception'},
$new_admin_user->{'visibility'},
......
......@@ -1727,28 +1727,49 @@ sub upgrade {
);
}
if (lower_version($previous_version, '6.2.25b.2')) {
# Database field type datetime was deprecated. Unix time will be used.
if (lower_version($previous_version, '6.2.25b.3')) {
my $sdm = Sympa::DatabaseManager->instance;
$log->syslog('notice', 'Upgrading subscriber_table.');
# update_subscriber (datetime) was obsoleted.
# Use update_epoch_subscriber (int).
# date_subscriber & update_subscriber (datetime) was obsoleted.
# Use date_epoch_subscriber & update_epoch_subscriber (int).
$sdm->do_prepared_query(
sprintf(
q{UPDATE subscriber_table
SET date_epoch_subscriber = %s
WHERE date_subscriber IS NOT NULL AND
date_epoch_subscriber IS NULL},
$sdm->get_canonical_read_date('date_subscriber')
)
);
$sdm->do_prepared_query(
sprintf(
q{UPDATE subscriber_table
SET update_epoch_subscriber = %s
WHERE update_subscriber IS NOT NULL},
WHERE update_subscriber IS NOT NULL AND
update_epoch_subscriber IS NULL},
$sdm->get_canonical_read_date('update_subscriber')
)
);
$log->syslog('notice', 'Upgrading admin_table.');
# update_admin (datetime) was obsoleted.
# Use update_epoch_admin (int).
# date_admin & update_admin (datetime) was obsoleted.
# Use date_epoch_admin & update_epoch_admin (int).
$sdm->do_prepared_query(
sprintf(
q{UPDATE admin_table
SET date_epoch_admin = %s
WHERE date_admin IS NOT NULL AND
date_epoch_admin IS NULL},
$sdm->get_canonical_read_date('date_admin')
)
);
$sdm->do_prepared_query(
sprintf(
q{UPDATE admin_table
SET update_epoch_admin = %s
WHERE update_admin IS NOT NULL},
WHERE update_admin IS NOT NULL AND
update_epoch_admin IS NULL},
$sdm->get_canonical_read_date('update_admin')
)
);
......
Supports Markdown
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