From 9ed02654b14dc3a124fcd5b0dd3f20033d115c96 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 30 Oct 2009 17:55:52 +0000 Subject: [PATCH] created a new ApplyPatronPenalty A/T reactor git-svn-id: svn://svn.open-ils.org/ILS/trunk@14702 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Trigger/Reactor/ApplyPatronPenalty.pm | 74 ++++++++++++++++++++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 5 ++ .../upgrade/0064.apply-patron-penalty-reactor.sql | 8 +++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm create mode 100644 Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm new file mode 100644 index 0000000000..33e624e595 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm @@ -0,0 +1,74 @@ +package OpenILS::Application::Trigger::Reactor::ApplyPatronPenalty; +use base 'OpenILS::Application::Trigger::Reactor'; +use strict; use warnings; +use Error qw/:try/; +use OpenILS::Const qw/:const/; +use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::Logger qw/$logger/; +use OpenILS::Utils::CStoreEditor q/:funcs/; +use OpenILS::Application::AppUtils; +my $U = "OpenILS::Application::AppUtils"; + + +sub ABOUT { + return <error("ApplyPatronPenalty: missing parameters"); + return 0; + } + + my $e = new_editor(xact => 1); + + my $ptype = $e->search_config_standing_penalty({name => $pname})->[0]; + + unless($ptype) { + $logger->error("ApplyPatronPenalty: invalid penalty name '$pname'"); + $e->rollback; + return 0; + } + + $context_org = (defined $ptype->org_depth) ? + $U->org_unit_ancestor_at_depth($context_org->id, $ptype->org_depth) : + $context_org->id; + + # apply the penalty + my $penalty = Fieldmapper::actor::usr_standing_penalty->new; + $penalty->usr($user->id); + $penalty->org_unit($context_org); + $penalty->standing_penalty($ptype->id); + $penalty->note($self->run_TT($env)); + + unless($e->create_actor_user_standing_penalty($penalty)) { + $e->rollback; + return 0; + } + + $e->commit; + return 1; +} + +1; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 5fa4cd88c0..fefabc7763 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0063'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0064'); -- berick CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index ed648f8e32..20874d49d2 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -2364,3 +2364,8 @@ INSERT INTO action_trigger.event_params (event_def, param, value) VALUES (6, 'max_delay_age', '"1 day"'); +-- ApplyPatronPenalty A/T Reactor + +INSERT INTO action_trigger.reactor (module,description) VALUES ('ApplyPatronPenalty','Applies the conifigured penalty to a patron. Required named environment variables are "user", which refers to the user object, and "context_org", which refers to the org_unit object that acts as the focus for the penalty.'); + + diff --git a/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql b/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql new file mode 100644 index 0000000000..d6129482fc --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql @@ -0,0 +1,8 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0064'); + +INSERT INTO action_trigger.reactor (module,description) VALUES ('ApplyPatronPenalty','Applies the conifigured penalty to a patron. Required named environment variables are "user", which refers to the user object, and "context_org", which refers to the org_unit object that acts as the focus for the penalty.'); + +COMMIT; + -- 2.11.0