diff --git a/config/catmandu.local.yml-example b/config/catmandu.local.yml-example index 88c2bc181..09fb3950c 100644 --- a/config/catmandu.local.yml-example +++ b/config/catmandu.local.yml-example @@ -2,7 +2,10 @@ default_lang: en host: "http://localhost:5001" -# Specity the ipranges which can download (local) files +## Uncomment when audit messages need to be displayed +# audit: 1 + +## Specity the ipranges which can download (local) files ip_range: - 157.193.0.0/16 - 127.0.0.1 diff --git a/cpanfile b/cpanfile index ad19f7b8e..f2c085adf 100644 --- a/cpanfile +++ b/cpanfile @@ -28,6 +28,7 @@ requires 'Catmandu::DBI', '>=0.0510'; requires 'Catmandu::BibTeX'; requires 'Catmandu::XML'; requires 'Catmandu::ArXiv'; +requires 'Catmandu::LDAP'; requires 'Catmandu::Importer::getJSON'; requires 'Catmandu::Identifier', '>=0.05'; requires 'Catmandu::RIS', '>=0.04'; diff --git a/etc/librecat-audit.initd b/etc/librecat-audit.initd index 004ff4887..36964a760 100644 --- a/etc/librecat-audit.initd +++ b/etc/librecat-audit.initd @@ -16,6 +16,8 @@ SERVER_USER="biblio" SERVER_GROUP="biblio" WORKERS=1 LIBRECAT_DIR="/opt/librecat" +# If a config.yml is in a layers directory, use this line: +# LIBRECAT_LAYERS="/opt/librecat-ugent" lock_file=/var/lock/subsys/audit.librecat @@ -24,7 +26,7 @@ do_start() if [ ! -f "$lock_file" ] ; then cd $LIBRECAT_DIR echo -n $"Starting ${SCRIPT}: " - sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "bin/librecat worker audit start --workers ${WORKERS} --supervise" > /dev/null 2>&1 + sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "LIBRECAT_LAYERS=${LIBRECAT_LAYERS} bin/librecat worker audit start --workers ${WORKERS} --supervise" > /dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then touch $lock_file @@ -43,7 +45,7 @@ do_stop() { cd $LIBRECAT_DIR echo -n $"Stopping $SCRIPT: " - sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "bin/librecat worker audit stop --workers ${WORKERS} --supervise" > /dev/null 2>&1 + sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "LIBRECAT_LAYERS=${LIBRECAT_LAYERS} bin/librecat worker audit stop --workers ${WORKERS} --supervise" > /dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then touch $lock_file @@ -58,7 +60,7 @@ do_stop() do_status() { cd $LIBRECAT_DIR - sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "bin/librecat queue" + sudo -u ${SERVER_USER} -g ${SERVER_GROUP} $CARTON exec "LIBRECAT_LAYERS=${LIBRECAT_LAYERS} bin/librecat queue status" } case "$1" in diff --git a/lib/LibreCat/Cmd/queue.pm b/lib/LibreCat/Cmd/queue.pm index b59bf750f..bb44c8dfe 100644 --- a/lib/LibreCat/Cmd/queue.pm +++ b/lib/LibreCat/Cmd/queue.pm @@ -2,6 +2,8 @@ package LibreCat::Cmd::queue; use Catmandu::Sane; use Catmandu; +use LibreCat::App::Helper; +use Carp; use Net::Telnet::Gearman; use parent 'LibreCat::Cmd'; @@ -10,7 +12,8 @@ sub description { return <usage_error("should be one of $commands"); + } + + if ($cmd eq 'status') { + $self->_status; + } + elsif ($cmd eq 'add_job') { + $self->_add_job(@$args); + } +} + +sub _add_job { + my ($self,$worker,$file) = @_; + + croak "usage: $0 add_job " unless defined($worker) && -r $file; + + my $importer = Catmandu->importer('YAML', file => $file); + my $exporter = Catmandu->exporter('YAML'); + my $queue = LibreCat::App::Helper::Helpers->new->queue; + + $importer->each(sub { + my $job = $_[0]; + + my $response = $queue->add_job("audit",$job); + + print "Adding job\n"; + + $job->{'_response'} = $response; + + $exporter->add($job); + }); + + $exporter->commit; +} + +sub _status { my $gm = Net::Telnet::Gearman->new(Host => '127.0.0.1', Port => 4730,); my $version = $gm->version; $version =~ s/^OK //; @@ -68,4 +116,12 @@ __END__ LibreCat::Cmd::queue - show job queue status +=head1 SYNOPSIS + + # Show the status of all worker + librecat queue status + + # Submit a YAML file job to the WORKER + librecat queue add_job WORKER FILE + =cut diff --git a/lib/LibreCat/Hook/audit_message.pm b/lib/LibreCat/Hook/audit_message.pm index 194180c45..b67023e04 100644 --- a/lib/LibreCat/Hook/audit_message.pm +++ b/lib/LibreCat/Hook/audit_message.pm @@ -43,14 +43,17 @@ sub fix { $action = 'batch'; } + my $job = { + id => $id , + bag => 'publication' , + process => "hook($name)" , + action => "$action" , + message => "activated by $login ($user_id)" , + }; + + h->log->debug("adding job: " . to_yaml($job)); try { - h->queue->add_job('audit',{ - id => $id , - bag => 'publication' , - process => "hook($name)" , - action => "$action" , - message => "activated by $login ($user_id)" , - }); + h->queue->add_job('audit', $job); } catch { h->log->trace("caught a : $_"); }; diff --git a/views/backend/audit.tt b/views/backend/audit.tt index d13866089..94807f017 100644 --- a/views/backend/audit.tt +++ b/views/backend/audit.tt @@ -5,7 +5,7 @@

[% h.loc("audit.title") %]

- +
@@ -16,7 +16,7 @@ [% FOREACH au in audit %] - +
[% h.loc("audit.id") %] [% h.loc("audit.bag") %]
[% au.id %][% au.id %] [% au.bag %] [% au.process %] [% au.action %]