Skip to content

Commit 1b42ea0

Browse files
committed
A name of the source by which user was actually included will be stored in inclusion_label_* field of the table.
1 parent d5b31fe commit 1b42ea0

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

default/web_tt2/subscriber_table.tt2

+7-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@
136136
<td>
137137
[% IF u.subscribed %][%|loc%]subscribed[%END%][% END ~%]
138138
[% IF u.subscribed && u.inclusion.defined() %]<br />[% END ~%]
139-
[% IF u.inclusion.defined() %][%|loc%]included[%END%][% END %]
139+
[% IF u.inclusion.defined() ~%]
140+
[% IF u.inclusion_label ~%]
141+
[% u.inclusion_label %]
142+
[%~ ELSE ~%]
143+
[%|loc%]included[%END%]
144+
[%~ END %]
145+
[%~ END %]
140146
</td>
141147
<td>
142148
[% u.date %]

src/lib/Sympa/DatabaseDescription.pm

+10
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ my %full_db_struct = (
137137
'the last time when list user is synchronized with external data source',
138138
'order' => 12.7,
139139
},
140+
'inclusion_label_subscriber' => {
141+
'struct' => 'varchar(15)',
142+
'doc' => 'name of data source',
143+
'order' => 12.8,
144+
},
140145
'comment_subscriber' => {
141146
'struct' => 'varchar(150)',
142147
'doc' => 'free form name',
@@ -945,6 +950,11 @@ my %full_db_struct = (
945950
'the last time when list user is synchronized with external data source',
946951
'order' => 7.7,
947952
},
953+
'inclusion_label_admin' => {
954+
'struct' => 'varchar(15)',
955+
'doc' => 'name of data source',
956+
'order' => 7.8,
957+
},
948958
'reception_admin' => {
949959
'struct' => 'varchar(20)',
950960
'doc' =>

src/lib/Sympa/List.pm

+7-1
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,7 @@ sub update_list_admin {
37433743
update_date => 'update_epoch_admin',
37443744
inclusion => 'inclusion_admin',
37453745
inclusion_ext => 'inclusion_ext_admin',
3746+
inclusion_label => 'inclusion_label_admin',
37463747
gecos => 'comment_admin',
37473748
password => 'password_user',
37483749
email => 'user_admin',
@@ -3760,6 +3761,7 @@ sub update_list_admin {
37603761
update_date => 'admin_table',
37613762
inclusion => 'admin_table',
37623763
inclusion_ext => 'admin_table',
3764+
inclusion_label => 'admin_table',
37633765
gecos => 'admin_table',
37643766
password => 'user_table',
37653767
email => 'admin_table',
@@ -4018,6 +4020,7 @@ sub add_list_member {
40184020
list_subscriber, robot_subscriber,
40194021
date_epoch_subscriber, update_epoch_subscriber,
40204022
inclusion_subscriber, inclusion_ext_subscriber,
4023+
inclusion_label_subscriber,
40214024
reception_subscriber, topics_subscriber,
40224025
visibility_subscriber, subscribed_subscriber,
40234026
custom_attribute_subscriber,
@@ -4030,6 +4033,7 @@ sub add_list_member {
40304033
$name, $self->{'domain'},
40314034
$new_user->{'date'}, $new_user->{'update_date'},
40324035
$new_user->{'inclusion'}, $new_user->{'inclusion_ext'},
4036+
$new_user->{'inclusion_label'},
40334037
$new_user->{'reception'}, $new_user->{'topics'},
40344038
$new_user->{'visibility'}, $new_user->{'subscribed'},
40354039
$new_user->{'custom_attribute'},
@@ -4522,6 +4526,7 @@ sub restore_users {
45224526
}
45234527
} else {
45244528
my $changed = 0;
4529+
my %map_field = _map_list_admin_cols();
45254530

45264531
while (my $para = <$lock_fh>) {
45274532
my $user = {
@@ -4535,7 +4540,8 @@ sub restore_users {
45354540
or
45364541
/^\s*(date|update_date|inclusion|inclusion_ext)\s+(\d+)\s*$/
45374542
or /^\s*(reception)\s+(mail|nomail)\s*$/
4538-
or /^\s*(visibility)\s+(conceal|noconceal)\s*$/) {
4543+
or /^\s*(visibility)\s+(conceal|noconceal)\s*$/
4544+
or (/^\s*(\w+)\s+(.+)\s*$/ and $map_field{$1})) {
45394545
($1 => $2);
45404546
} else {
45414547
();

src/lib/Sympa/Request/Handler/include.pm

+27-7
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ sub _get_data_sources {
8484
);
8585
# Special case: include_file is not paragraph.
8686
if ($ptype eq 'include_file') {
87-
@config = map { {name => $_, path => $_} } @config;
87+
@config = map {
88+
my $name = substr [split m{/}, $_]->[-1], 0, 15;
89+
{name => $name, path => $_};
90+
} @config;
8891
}
8992
my $type = $config_user_map{$ptype};
9093
push @dss, map {
@@ -102,7 +105,10 @@ sub _get_data_sources {
102105
map { @{$_->{$ptype} || []} } @config_files;
103106
# Special case: include_file is not paragraph.
104107
if ($ptype eq 'include_file') {
105-
@config = map { {name => $_, path => $_} } @config;
108+
@config = map {
109+
my $name = substr [split m{/}, $_]->[-1], 0, 15;
110+
{name => $name, path => $_};
111+
} @config;
106112
}
107113
my $type = $config_user_map{$ptype};
108114
push @dss, map {
@@ -204,7 +210,7 @@ sub _twist {
204210
# III. Expire outdated entries.
205211

206212
# Choose most earlier time of succeeding inclusions (if any of
207-
# data sources have not succeeded yet, Unix epoch will be chosen).
213+
# data sources have not succeeded yet, time is not defined).
208214
$last_start_time = $start_time;
209215
foreach my $id (map { $_->get_short_id } @$dss) {
210216
unless (defined $start_times{$id}) {
@@ -365,6 +371,9 @@ sub __update_user {
365371
# 3. If user (has not been updated by the other data sources and) exists:
366372
# UPDATE inclusion.
367373
if ($is_external_ds) {
374+
# Already updated by the other non-external data source but not yet
375+
# by any other external ones:
376+
# Update inclusion_ext (and inclusion) field, but not inclusion_label.
368377
return unless $sth = $sdm->do_prepared_query(
369378
qq{UPDATE ${t}_table
370379
SET inclusion_$t = ?, inclusion_ext_$t = ?
@@ -376,28 +385,37 @@ sub __update_user {
376385
);
377386
return (updated => 0) if $sth->rows;
378387

388+
# Not yet updated by any other data sources:
389+
# Update inclusion_ext (and inclusion), and assign inclusion_label.
379390
return unless $sth = $sdm->do_prepared_query(
380391
qq{UPDATE ${t}_table
381-
SET inclusion_$t = ?, inclusion_ext_$t = ?
392+
SET inclusion_$t = ?, inclusion_ext_$t = ?,
393+
inclusion_label_$t = ?,
382394
WHERE user_$t = ? AND list_$t = ? AND robot_$t = ?$r},
383395
$time, $time,
396+
$ds->name,
384397
$email, $list->{'name'}, $list->{'domain'}
385398
);
386399
return (updated => 1) if $sth->rows;
387400
} else {
401+
# Not yet updated by any other data sources:
402+
# Update inclusion, and assign inclusion_label.
388403
return unless $sth = $sdm->do_prepared_query(
389404
qq{UPDATE ${t}_table
390-
SET inclusion_$t = ?
405+
SET inclusion_$t = ?,
406+
inclusion_label_$t = ?
391407
WHERE user_$t = ? AND list_$t = ? AND robot_$t = ?$r},
392408
$time,
409+
$ds->name,
393410
$email, $list->{'name'}, $list->{'domain'}
394411
);
395412
return (updated => 1) if $sth->rows;
396413
}
397414

398415
# 4. Otherwise, i.e. a new user:
399416
# INSERT new user with:
400-
# email, gecos, subscribed=0, date, update, inclusion and
417+
# email, gecos, subscribed=0, date, update, inclusion,
418+
# (optional) inclusion_ext, inclusion_label and
401419
# default attributes.
402420
my $user = {
403421
email => $email,
@@ -407,6 +425,7 @@ sub __update_user {
407425
update_date => $time,
408426
inclusion => $time,
409427
($is_external_ds ? (inclusion_ext => $time) : ()),
428+
inclusion_label => $ds->name,
410429
};
411430
my @defkeys = @{$ds->{_defkeys} || []};
412431
my @defvals = @{$ds->{_defvals} || []};
@@ -487,7 +506,8 @@ sub _expire_users {
487506
unless (
488507
$sdm->do_prepared_query(
489508
qq{UPDATE ${t}_table
490-
SET inclusion_$t = NULL, inclusion_ext_$t = NULL
509+
SET inclusion_$t = NULL, inclusion_ext_$t = NULL,
510+
inclusion_label_$t = NULL
491511
WHERE subscribed_$t = 1 AND
492512
inclusion_$t IS NOT NULL AND inclusion_$t < ? AND
493513
list_$t = ? AND robot_$t = ?$r},

0 commit comments

Comments
 (0)