Skip to content

Commit

Permalink
Add purge script, add install documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jajm committed Apr 10, 2019
1 parent 1f8af34 commit a1705ef
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
7 changes: 0 additions & 7 deletions INSTALL.md

This file was deleted.

31 changes: 31 additions & 0 deletions Koha/Plugin/Com/BibLibre/TransitionBibliographique.pm
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,35 @@ sub get_marc_record {
return $marc_record;
};

sub purge {
my ($self, $older_than) = @_;

my $dbh = C4::Context->dbh;
my $jobs_table = $self->get_qualified_table_name('jobs');
my $jobs = $dbh->selectall_arrayref(qq{
SELECT * FROM $jobs_table
WHERE state = 'finished'
AND finished_at < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL ? DAY)
ORDER BY enqueued_at ASC
}, { Slice => {} }, $older_than);

my $delete_sth = $dbh->prepare(qq{
DELETE FROM $jobs_table
WHERE id = ?
});

foreach my $job (@$jobs) {
say STDERR "Removing job " . $job->{id};

$job->{args} = decode_json($job->{args});
my $filepath = $job->{args}->{filepath};

say STDERR "Removing file $filepath";
unlink $filepath or say STDERR "Could not unlink file $filepath: $!";

say STDERR "Removing database entry";
$delete_sth->execute($job->{id}) or say STDERR "Could not remove database entry: " . $delete_sth->errstr;
}
}

1;
45 changes: 45 additions & 0 deletions Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/purge.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/perl

use Modern::Perl;
use Getopt::Long;

use Koha::Plugins;

use Koha::Plugin::Com::BibLibre::TransitionBibliographique;

my $help;
my $older_than = 30;

GetOptions(
'help' => \$help,
'older-than=i' => \$older_than,
) or die usage();

if ($help) {
print usage();
exit;
}

my $plugin = Koha::Plugin::Com::BibLibre::TransitionBibliographique->new({
enable_plugins => 1,
});
$plugin->purge($older_than);

sub usage {
my $usage = <<'EOF';
purge.pl [options]
purge.pl --help
Remove finished jobs and related files
Options
--older-than=DAYS
Remove jobs that are finished since more than DAYS days ago.
Defaults to 30
--help
Display this help message
EOF

return $usage;
}
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ transition bibliographique

- Koha 18.11 minimum
- Modules Perl:
- Catmandu
- Catmandu::Exporter::MARC
- [Catmandu](https://metacpan.org/pod/Catmandu)
- [Catmandu::MARC](https://metacpan.org/pod/Catmandu::MARC)
- YAML

# Installation
Expand All @@ -21,3 +21,26 @@ transition bibliographique
4. Si besoin, modifier `config.yaml`
5. Mettre `Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/export.pl`
en cronjob et lancer manuellement le script une première fois.
6. Mettre
`Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/job-runner.pl`
en cronjob.
7. (Optionnel) Mettre
`Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/purge.pl` en
cronjob

# Cronjobs

Tous les cronjobs doivent être lancés quotidiennement, de préférence la nuit
pour ne pas gêner l'utilisation normale de Koha.

Exemple:

```
PERL5LIB=/path/to/koha
KOHA_CONF=/path/to/koha-conf.xml
PATH_TO_PLUGIN=/path/to/plugin
0 22 * * * $PATH_TO_PLUGIN/Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/export.pl
50 22 * * * $PATH_TO_PLUGIN/Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/purge.pl --older-than=30
0 23 * * * $PATH_TO_PLUGIN/Koha/Plugin/Com/BibLibre/TransitionBibliographique/cron/job-runner.pl
```

0 comments on commit a1705ef

Please sign in to comment.