Bugzilla – Attachment 101297 Details for
Bug 24152
Add the ability to purge pseudonymized data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24152: Add method Koha::Objects->filter_by_last_update
Bug-24152-Add-method-KohaObjects-filterbylastupdat.patch (text/plain), 5.17 KB, created by
Jonathan Druart
on 2020-03-20 16:02:54 UTC
(
hide
)
Description:
Bug 24152: Add method Koha::Objects->filter_by_last_update
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-03-20 16:02:54 UTC
Size:
5.17 KB
patch
obsolete
>From 2171c41fa79e5a657d22bf341b783ede939b0ce7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 24 Sep 2019 18:05:38 -0300 >Subject: [PATCH] Bug 24152: Add method Koha::Objects->filter_by_last_update > >Signed-off-by: Signed-off-by: Sonia Bouis <sonia.bouis@univ-lyon3.fr> >--- > Koha/Objects.pm | 13 +++++ > misc/cronjobs/cleanup_database.pl | 79 +++++++++---------------------- > 2 files changed, 36 insertions(+), 56 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 9184a235a8..647c5e3fa5 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -171,6 +171,19 @@ sub search_related { > } > } > >+sub filter_by_last_update { >+ my ( $self, $params ) = @_; >+ my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp'; >+ return $self->_resultset->search( >+ { >+ $timestamp_column_name => { >+ '<' => >+ [ \'DATE_SUB(CURDATE(), INTERVAL ? DAY)', $params->{days} ] >+ } >+ } >+ ); >+} >+ > =head3 single > > my $object = Koha::Objects->search({}, { rows => 1 })->single >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index a1a9cae442..3b899e9150 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -42,6 +42,14 @@ use Getopt::Long; > use C4::Log; > use C4::Accounts; > use Koha::UploadedFiles; >+use Koha::Old::Biblios; >+use Koha::Old::Items; >+use Koha::Old::Biblioitems; >+use Koha::Old::Checkouts; >+use Koha::Old::Holds; >+use Koha::Old::Patrons; >+use Koha::Item::Transfers; >+ > > sub usage { > print STDERR <<USAGE; >@@ -395,88 +403,47 @@ if ($oauth_tokens) { > > if ($pStatistics) { > print "Purging statistics older than $pStatistics days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM statistics >- WHERE datetime < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- $sth->execute($pStatistics); >+ Koha::Statistics->filter_by_last_update( >+ { timestamp_column_name => 'datetime', days => $pStatistics } )->delete; > print "Done with purging statistics.\n" if $verbose; > } > > if ($pDeletedCatalog) { > print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose; >- my $sth1 = $dbh->prepare( >- q{ >- DELETE FROM deleteditems >- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- my $sth2 = $dbh->prepare( >- q{ >- DELETE FROM deletedbiblioitems >- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- my $sth3 = $dbh->prepare( >- q{ >- DELETE FROM deletedbiblio >- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- # deletedbiblio_metadata is managed by FK with deletedbiblio >- $sth1->execute($pDeletedCatalog); >- $sth2->execute($pDeletedCatalog); >- $sth3->execute($pDeletedCatalog); >+ Koha::Old::Items ->filter_by_last_update( { days => $pDeletedCatalog } )->delete; >+ Koha::Old::Biblioitems->filter_by_last_update( { days => $pDeletedCatalog } )->delete; >+ Koha::Old::Biblios ->filter_by_last_update( { days => $pDeletedCatalog } )->delete; > print "Done with purging deleted catalog.\n" if $verbose; > } > > if ($pDeletedPatrons) { > print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM deletedborrowers >- WHERE updated_on < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- $sth->execute($pDeletedPatrons); >+ Koha::Old::Patrons->filter_by_last_update( >+ { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } ) >+ ->delete; > print "Done with purging deleted patrons.\n" if $verbose; > } > > if ($pOldIssues) { > print "Purging old checkouts older than $pOldIssues days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM old_issues >- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- $sth->execute($pOldIssues); >+ Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } )->delete; > print "Done with purging old issues.\n" if $verbose; > } > > if ($pOldReserves) { > print "Purging old reserves older than $pOldReserves days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM old_reserves >- WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY) >- } >- ); >- $sth->execute($pOldReserves); >+ Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } )->delete; > print "Done with purging old reserves.\n" if $verbose; > } > > if ($pTransfers) { > print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM branchtransfers >- WHERE datearrived < DATE_SUB(CURDATE(), INTERVAL ? DAY) >+ Koha::Item::Transfers->filter_by_last_update( >+ { >+ timestamp_column_name => 'datearrived', >+ days => $pTransfers, > } >- ); >- $sth->execute($pTransfers); >+ )->delete; > print "Done with purging transfers.\n" if $verbose; > } > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24152
:
95977
|
95978
|
95979
|
97253
|
97254
|
97255
|
101297
|
101298
|
101299
|
105817
|
105818
|
105819
|
106051
|
106052
|
106053
|
106054
|
106196