Commit 1b42ea06 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

A name of the source by which user was actually included will be stored in...

A name of the source by which user was actually included will be stored in inclusion_label_* field of the table.
parent d5b31fec
......@@ -136,7 +136,13 @@
<td>
[% IF u.subscribed %][%|loc%]subscribed[%END%][% END ~%]
[% IF u.subscribed && u.inclusion.defined() %]<br />[% END ~%]
[% IF u.inclusion.defined() %][%|loc%]included[%END%][% END %]
[% IF u.inclusion.defined() ~%]
[% IF u.inclusion_label ~%]
[% u.inclusion_label %]
[%~ ELSE ~%]
[%|loc%]included[%END%]
[%~ END %]
[%~ END %]
</td>
<td>
[% u.date %]
......
......@@ -137,6 +137,11 @@ my %full_db_struct = (
'the last time when list user is synchronized with external data source',
'order' => 12.7,
},
'inclusion_label_subscriber' => {
'struct' => 'varchar(15)',
'doc' => 'name of data source',
'order' => 12.8,
},
'comment_subscriber' => {
'struct' => 'varchar(150)',
'doc' => 'free form name',
......@@ -945,6 +950,11 @@ my %full_db_struct = (
'the last time when list user is synchronized with external data source',
'order' => 7.7,
},
'inclusion_label_admin' => {
'struct' => 'varchar(15)',
'doc' => 'name of data source',
'order' => 7.8,
},
'reception_admin' => {
'struct' => 'varchar(20)',
'doc' =>
......
......@@ -3743,6 +3743,7 @@ sub update_list_admin {
update_date => 'update_epoch_admin',
inclusion => 'inclusion_admin',
inclusion_ext => 'inclusion_ext_admin',
inclusion_label => 'inclusion_label_admin',
gecos => 'comment_admin',
password => 'password_user',
email => 'user_admin',
......@@ -3760,6 +3761,7 @@ sub update_list_admin {
update_date => 'admin_table',
inclusion => 'admin_table',
inclusion_ext => 'admin_table',
inclusion_label => 'admin_table',
gecos => 'admin_table',
password => 'user_table',
email => 'admin_table',
......@@ -4018,6 +4020,7 @@ sub add_list_member {
list_subscriber, robot_subscriber,
date_epoch_subscriber, update_epoch_subscriber,
inclusion_subscriber, inclusion_ext_subscriber,
inclusion_label_subscriber,
reception_subscriber, topics_subscriber,
visibility_subscriber, subscribed_subscriber,
custom_attribute_subscriber,
......@@ -4030,6 +4033,7 @@ sub add_list_member {
$name, $self->{'domain'},
$new_user->{'date'}, $new_user->{'update_date'},
$new_user->{'inclusion'}, $new_user->{'inclusion_ext'},
$new_user->{'inclusion_label'},
$new_user->{'reception'}, $new_user->{'topics'},
$new_user->{'visibility'}, $new_user->{'subscribed'},
$new_user->{'custom_attribute'},
......@@ -4522,6 +4526,7 @@ sub restore_users {
}
} else {
my $changed = 0;
my %map_field = _map_list_admin_cols();
while (my $para = <$lock_fh>) {
my $user = {
......@@ -4535,7 +4540,8 @@ sub restore_users {
or
/^\s*(date|update_date|inclusion|inclusion_ext)\s+(\d+)\s*$/
or /^\s*(reception)\s+(mail|nomail)\s*$/
or /^\s*(visibility)\s+(conceal|noconceal)\s*$/) {
or /^\s*(visibility)\s+(conceal|noconceal)\s*$/
or (/^\s*(\w+)\s+(.+)\s*$/ and $map_field{$1})) {
($1 => $2);
} else {
();
......
......@@ -84,7 +84,10 @@ sub _get_data_sources {
);
# Special case: include_file is not paragraph.
if ($ptype eq 'include_file') {
@config = map { {name => $_, path => $_} } @config;
@config = map {
my $name = substr [split m{/}, $_]->[-1], 0, 15;
{name => $name, path => $_};
} @config;
}
my $type = $config_user_map{$ptype};
push @dss, map {
......@@ -102,7 +105,10 @@ sub _get_data_sources {
map { @{$_->{$ptype} || []} } @config_files;
# Special case: include_file is not paragraph.
if ($ptype eq 'include_file') {
@config = map { {name => $_, path => $_} } @config;
@config = map {
my $name = substr [split m{/}, $_]->[-1], 0, 15;
{name => $name, path => $_};
} @config;
}
my $type = $config_user_map{$ptype};
push @dss, map {
......@@ -204,7 +210,7 @@ sub _twist {
# III. Expire outdated entries.
# Choose most earlier time of succeeding inclusions (if any of
# data sources have not succeeded yet, Unix epoch will be chosen).
# data sources have not succeeded yet, time is not defined).
$last_start_time = $start_time;
foreach my $id (map { $_->get_short_id } @$dss) {
unless (defined $start_times{$id}) {
......@@ -365,6 +371,9 @@ sub __update_user {
# 3. If user (has not been updated by the other data sources and) exists:
# UPDATE inclusion.
if ($is_external_ds) {
# Already updated by the other non-external data source but not yet
# by any other external ones:
# Update inclusion_ext (and inclusion) field, but not inclusion_label.
return unless $sth = $sdm->do_prepared_query(
qq{UPDATE ${t}_table
SET inclusion_$t = ?, inclusion_ext_$t = ?
......@@ -376,20 +385,28 @@ sub __update_user {
);
return (updated => 0) if $sth->rows;
# Not yet updated by any other data sources:
# Update inclusion_ext (and inclusion), and assign inclusion_label.
return unless $sth = $sdm->do_prepared_query(
qq{UPDATE ${t}_table
SET inclusion_$t = ?, inclusion_ext_$t = ?
SET inclusion_$t = ?, inclusion_ext_$t = ?,
inclusion_label_$t = ?,
WHERE user_$t = ? AND list_$t = ? AND robot_$t = ?$r},
$time, $time,
$ds->name,
$email, $list->{'name'}, $list->{'domain'}
);
return (updated => 1) if $sth->rows;
} else {
# Not yet updated by any other data sources:
# Update inclusion, and assign inclusion_label.
return unless $sth = $sdm->do_prepared_query(
qq{UPDATE ${t}_table
SET inclusion_$t = ?
SET inclusion_$t = ?,
inclusion_label_$t = ?
WHERE user_$t = ? AND list_$t = ? AND robot_$t = ?$r},
$time,
$ds->name,
$email, $list->{'name'}, $list->{'domain'}
);
return (updated => 1) if $sth->rows;
......@@ -397,7 +414,8 @@ sub __update_user {
# 4. Otherwise, i.e. a new user:
# INSERT new user with:
# email, gecos, subscribed=0, date, update, inclusion and
# email, gecos, subscribed=0, date, update, inclusion,
# (optional) inclusion_ext, inclusion_label and
# default attributes.
my $user = {
email => $email,
......@@ -407,6 +425,7 @@ sub __update_user {
update_date => $time,
inclusion => $time,
($is_external_ds ? (inclusion_ext => $time) : ()),
inclusion_label => $ds->name,
};
my @defkeys = @{$ds->{_defkeys} || []};
my @defvals = @{$ds->{_defvals} || []};
......@@ -487,7 +506,8 @@ sub _expire_users {
unless (
$sdm->do_prepared_query(
qq{UPDATE ${t}_table
SET inclusion_$t = NULL, inclusion_ext_$t = NULL
SET inclusion_$t = NULL, inclusion_ext_$t = NULL,
inclusion_label_$t = NULL
WHERE subscribed_$t = 1 AND
inclusion_$t IS NOT NULL AND inclusion_$t < ? AND
list_$t = ? AND robot_$t = ?$r},
......
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