View | Details | Raw Unified | Return to bug 21336
Collapse All | Expand All

(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 1362-1373 sub anonymize { Link Here
1362
        split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') };
1362
        split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') };
1363
    $mandatory->{userid} = 1; # needed since sub store does not clear field
1363
    $mandatory->{userid} = 1; # needed since sub store does not clear field
1364
    my @columns = $self->_result->result_source->columns;
1364
    my @columns = $self->_result->result_source->columns;
1365
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1365
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|anonymized/ } @columns;
1366
    push @columns, 'dateofbirth'; # add this date back in
1366
    push @columns, 'dateofbirth'; # add this date back in
1367
    foreach my $col (@columns) {
1367
    foreach my $col (@columns) {
1368
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1368
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1369
    }
1369
    }
1370
    $self->flgAnonymized(1)->store;
1370
    $self->anonymized(1)->store;
1371
}
1371
}
1372
1372
1373
sub _anonymize_column {
1373
sub _anonymize_column {
(-)a/Koha/Patrons.pm (-2 / +2 lines)
Lines 293-299 sub search_anonymize_candidates { Link Here
293
    my $dt = dt_from_string()->subtract( days => $delay );
293
    my $dt = dt_from_string()->subtract( days => $delay );
294
    my $str = $parser->format_datetime($dt);
294
    my $str = $parser->format_datetime($dt);
295
    $cond->{dateexpiry} = { '<=' => $str };
295
    $cond->{dateexpiry} = { '<=' => $str };
296
    $cond->{flgAnonymized} = [ undef, 0 ]; # not yet done
296
    $cond->{anonymized} = 0; # not yet done
297
    if( $params->{locked} ) {
297
    if( $params->{locked} ) {
298
        my $fails = C4::Context->preference('FailedLoginAttempts');
298
        my $fails = C4::Context->preference('FailedLoginAttempts');
299
        $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef
299
        $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef
Lines 324-330 sub search_anonymized { Link Here
324
    my $dt = dt_from_string()->subtract( days => $delay );
324
    my $dt = dt_from_string()->subtract( days => $delay );
325
    my $str = $parser->format_datetime($dt);
325
    my $str = $parser->format_datetime($dt);
326
    $cond->{dateexpiry} = { '<=' => $str };
326
    $cond->{dateexpiry} = { '<=' => $str };
327
    $cond->{flgAnonymized} = 1;
327
    $cond->{anonymized} = 1;
328
    return $class->search( $cond );
328
    return $class->search( $cond );
329
}
329
}
330
330
(-)a/Koha/Schema/Result/Borrower.pm (-13 / +7 lines)
Lines 451-462 __PACKAGE__->table("borrowers"); Link Here
451
  data_type: 'mediumtext'
451
  data_type: 'mediumtext'
452
  is_nullable: 1
452
  is_nullable: 1
453
453
454
=head2 flgAnonymized
454
=head2 anonymized
455
455
456
  accessor: 'flg_anonymized'
457
  data_type: 'tinyint'
456
  data_type: 'tinyint'
458
  default_value: 0
457
  default_value: 0
459
  is_nullable: 1
458
  is_nullable: 0
460
459
461
=cut
460
=cut
462
461
Lines 660-672 __PACKAGE__->add_columns( Link Here
660
  { data_type => "integer", default_value => 0, is_nullable => 1 },
659
  { data_type => "integer", default_value => 0, is_nullable => 1 },
661
  "overdrive_auth_token",
660
  "overdrive_auth_token",
662
  { data_type => "mediumtext", is_nullable => 1 },
661
  { data_type => "mediumtext", is_nullable => 1 },
663
  "flgAnonymized",
662
  "anonymized",
664
  {
663
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
665
    accessor      => "flg_anonymized",
666
    data_type     => "tinyint",
667
    default_value => 0,
668
    is_nullable   => 1,
669
  },
670
);
664
);
671
665
672
=head1 PRIMARY KEY
666
=head1 PRIMARY KEY
Lines 1535-1542 Composing rels: L</aqorder_users> -> ordernumber Link Here
1535
__PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber");
1529
__PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber");
1536
1530
1537
1531
1538
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-17 11:11:33
1532
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-04-16 18:53:11
1539
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZkPU/EUsZVXiRoQ1E8NMbw
1533
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ehheuLbVpMKvKtLpSI73DA
1540
1534
1541
__PACKAGE__->belongs_to(
1535
__PACKAGE__->belongs_to(
1542
    "guarantor",
1536
    "guarantor",
Lines 1545-1551 __PACKAGE__->belongs_to( Link Here
1545
);
1539
);
1546
1540
1547
__PACKAGE__->add_columns(
1541
__PACKAGE__->add_columns(
1548
    '+lost' => { is_boolean => 1 },
1542
    '+lost'          => { is_boolean => 1 },
1549
    '+gonenoaddress' => { is_boolean => 1 }
1543
    '+gonenoaddress' => { is_boolean => 1 }
1550
);
1544
);
1551
1545
(-)a/Koha/Schema/Result/Deletedborrower.pm (-12 / +6 lines)
Lines 448-459 __PACKAGE__->table("deletedborrowers"); Link Here
448
  data_type: 'mediumtext'
448
  data_type: 'mediumtext'
449
  is_nullable: 1
449
  is_nullable: 1
450
450
451
=head2 flgAnonymized
451
=head2 anonymized
452
452
453
  accessor: 'flg_anonymized'
454
  data_type: 'tinyint'
453
  data_type: 'tinyint'
455
  default_value: 0
454
  default_value: 0
456
  is_nullable: 1
455
  is_nullable: 0
457
456
458
=cut
457
=cut
459
458
Lines 645-662 __PACKAGE__->add_columns( Link Here
645
  { data_type => "integer", default_value => 0, is_nullable => 1 },
644
  { data_type => "integer", default_value => 0, is_nullable => 1 },
646
  "overdrive_auth_token",
645
  "overdrive_auth_token",
647
  { data_type => "mediumtext", is_nullable => 1 },
646
  { data_type => "mediumtext", is_nullable => 1 },
648
  "flgAnonymized",
647
  "anonymized",
649
  {
648
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
650
    accessor      => "flg_anonymized",
651
    data_type     => "tinyint",
652
    default_value => 0,
653
    is_nullable   => 1,
654
  },
655
);
649
);
656
650
657
651
658
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-17 11:11:33
652
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-04-16 18:53:12
659
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9XbNY+E7YqzsiUldTFg6Zg
653
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d/vqm936LpPrgj9fvpyDUQ
660
654
661
655
662
# You can replace this text with custom code or comments, and it will be preserved on regeneration
656
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/installer/data/mysql/atomicupdate/bug_21336_followup.perl (+20 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
4
    if ( column_exists( 'borrowers', 'flgAnonymized' ) ) {
5
        $dbh->do(q{
6
            ALTER TABLE borrowers
7
                CHANGE `flgAnonymized` `anonymized` TINYINT(1) NOT NULL DEFAULT 0
8
        });
9
    }
10
11
    if ( column_exists( 'deletedborrowers', 'flgAnonymized' ) ) {
12
        $dbh->do(q{
13
            ALTER TABLE deletedborrowers
14
                CHANGE `flgAnonymized` `anonymized` TINYINT(1) NOT NULL DEFAULT 0
15
        });
16
    }
17
18
    SetVersion( $DBversion );
19
    print "Upgrade to $DBversion done (Bug 21336 - (follow-up) Rename flgAnonymized column)\n";
20
}
(-)a/installer/data/mysql/kohastructure.sql (-2 / +2 lines)
Lines 609-615 CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower Link Here
609
  `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
609
  `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
610
  `login_attempts` int(4) default 0, -- number of failed login attemps
610
  `login_attempts` int(4) default 0, -- number of failed login attemps
611
  `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
611
  `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
612
  `flgAnonymized` tinyint DEFAULT 0, -- flag for data anonymization
612
  `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization
613
  KEY borrowernumber (borrowernumber),
613
  KEY borrowernumber (borrowernumber),
614
  KEY `cardnumber` (`cardnumber`),
614
  KEY `cardnumber` (`cardnumber`),
615
  KEY `sms_provider_id` (`sms_provider_id`)
615
  KEY `sms_provider_id` (`sms_provider_id`)
Lines 1644-1650 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
1644
  `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
1644
  `lang` varchar(25) NOT NULL default 'default', -- lang to use to send notices to this patron
1645
  `login_attempts` int(4) default 0, -- number of failed login attemps
1645
  `login_attempts` int(4) default 0, -- number of failed login attemps
1646
  `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
1646
  `overdrive_auth_token` MEDIUMTEXT default NULL, -- persist OverDrive auth token
1647
  `flgAnonymized` tinyint DEFAULT 0, -- flag for data anonymization
1647
  `anonymized` TINYINT(1) NOT NULL DEFAULT 0, -- flag for data anonymization
1648
  UNIQUE KEY `cardnumber` (`cardnumber`),
1648
  UNIQUE KEY `cardnumber` (`cardnumber`),
1649
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
1649
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
1650
  KEY `categorycode` (`categorycode`),
1650
  KEY `categorycode` (`categorycode`),
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +13 lines)
Lines 18037-18044 if( CheckVersion( $DBversion ) ) { Link Here
18037
18037
18038
$DBversion = '18.12.00.049';
18038
$DBversion = '18.12.00.049';
18039
if( CheckVersion( $DBversion ) ) {
18039
if( CheckVersion( $DBversion ) ) {
18040
    $dbh->do( "ALTER TABLE borrowers ADD COLUMN flgAnonymized tinyint DEFAULT 0" ) if !column_exists('borrowers', 'flgAnonymized');
18040
18041
    $dbh->do( "ALTER TABLE deletedborrowers ADD COLUMN flgAnonymized tinyint DEFAULT 0" ) if !column_exists('deletedborrowers', 'flgAnonymized');
18041
    $dbh->do(q{
18042
        ALTER TABLE borrowers
18043
            ADD COLUMN flgAnonymized tinyint DEFAULT 0
18044
            AFTER `overdrive_auth_token`
18045
    }) if !column_exists('borrowers', 'flgAnonymized');
18046
18047
    $dbh->do(q{
18048
        ALTER TABLE deletedborrowers
18049
            ADD COLUMN flgAnonymized tinyint DEFAULT 0
18050
            AFTER `overdrive_auth_token`
18051
    }) if !column_exists('deletedborrowers', 'flgAnonymized');
18052
18042
    SetVersion( $DBversion );
18053
    SetVersion( $DBversion );
18043
    print "Upgrade to $DBversion done (Bug 21336 - Add field flgAnonymized)\n";
18054
    print "Upgrade to $DBversion done (Bug 21336 - Add field flgAnonymized)\n";
18044
}
18055
}
(-)a/t/db_dependent/Koha/Patrons.t (-6 / +5 lines)
Lines 1663-1671 subtest 'search_anonymize_candidates' => sub { Link Here
1663
    plan tests => 5;
1663
    plan tests => 5;
1664
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1664
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1665
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
1665
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
1666
    $patron1->flgAnonymized(0);
1666
    $patron1->anonymized(0);
1667
    $patron1->dateexpiry( dt_from_string->add(days => 1) )->store;
1667
    $patron1->dateexpiry( dt_from_string->add(days => 1) )->store;
1668
    $patron2->flgAnonymized(undef);
1668
    $patron2->anonymized(0);
1669
    $patron2->dateexpiry( dt_from_string->add(days => 1) )->store;
1669
    $patron2->dateexpiry( dt_from_string->add(days => 1) )->store;
1670
1670
1671
    t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} );
1671
    t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} );
Lines 1713-1721 subtest 'search_anonymized' => sub { Link Here
1713
1713
1714
    t::lib::Mocks::mock_preference( 'PatronRemovalDelay', 1 );
1714
    t::lib::Mocks::mock_preference( 'PatronRemovalDelay', 1 );
1715
    $patron1->dateexpiry( dt_from_string );
1715
    $patron1->dateexpiry( dt_from_string );
1716
    $patron1->flgAnonymized(0)->store;
1716
    $patron1->anonymized(0)->store;
1717
    my $cnt = Koha::Patrons->search_anonymized->count;
1717
    my $cnt = Koha::Patrons->search_anonymized->count;
1718
    $patron1->flgAnonymized(1)->store;
1718
    $patron1->anonymized(1)->store;
1719
    is( Koha::Patrons->search_anonymized->count, $cnt, 'Number unchanged' );
1719
    is( Koha::Patrons->search_anonymized->count, $cnt, 'Number unchanged' );
1720
    $patron1->dateexpiry( dt_from_string->subtract(days => 1) )->store;
1720
    $patron1->dateexpiry( dt_from_string->subtract(days => 1) )->store;
1721
    is( Koha::Patrons->search_anonymized->count, $cnt+1, 'Found patron1' );
1721
    is( Koha::Patrons->search_anonymized->count, $cnt+1, 'Found patron1' );
Lines 1775-1781 subtest 'anonymize' => sub { Link Here
1775
    my $surname = $patron1->surname; # expect change, no clear
1775
    my $surname = $patron1->surname; # expect change, no clear
1776
    my $branchcode = $patron1->branchcode; # expect skip
1776
    my $branchcode = $patron1->branchcode; # expect skip
1777
    $patron1->anonymize;
1777
    $patron1->anonymize;
1778
    is($patron1->flgAnonymized, 1, 'Check flag' );
1778
    is($patron1->anonymized, 1, 'Check flag' );
1779
1779
1780
    is( $patron1->dateofbirth, undef, 'Birth date cleared' );
1780
    is( $patron1->dateofbirth, undef, 'Birth date cleared' );
1781
    is( $patron1->firstname, undef, 'First name cleared' );
1781
    is( $patron1->firstname, undef, 'First name cleared' );
1782
- 

Return to bug 21336