[open-ils-commits] r14702 - in trunk/Open-ILS/src: perlmods/OpenILS/Application/Trigger/Reactor sql/Pg sql/Pg/upgrade (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Oct 30 13:55:56 EDT 2009
Author: erickson
Date: 2009-10-30 13:55:52 -0400 (Fri, 30 Oct 2009)
New Revision: 14702
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm
trunk/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
created a new ApplyPatronPenalty A/T reactor
Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/ApplyPatronPenalty.pm 2009-10-30 17:55:52 UTC (rev 14702)
@@ -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 <<ABOUT;
+
+ Applies a standing penalty to a patron. If there is a template, the template is
+ used as the value for the note
+
+ Required named (with labels) environment variables:
+ "user" -- User object fleshed into the environment
+ "context_org" -- Org unit object fleshed into the environment
+
+ Note: Using named env variables with a grouped event definition where the
+ env vars may be different depending on the target produces undefined behavior.
+ Don't use this reactor if more than one User or Org Unit object may be
+ referenced accross the set of target objects.
+
+ABOUT
+}
+
+sub handler {
+ my $self = shift;
+ my $env = shift;
+
+ my $pname = $$env{params}{standing_penalty};
+ my $user = $$env{environment}{user};
+ my $context_org = $$env{environment}{context_org};
+
+ unless($pname and ref $user and ref $context_org) {
+ $logger->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;
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-30 14:34:43 UTC (rev 14701)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-30 17:55:52 UTC (rev 14702)
@@ -51,7 +51,7 @@
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,
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-10-30 14:34:43 UTC (rev 14701)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2009-10-30 17:55:52 UTC (rev 14702)
@@ -2364,3 +2364,8 @@
(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.');
+
+
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0064.apply-patron-penalty-reactor.sql 2009-10-30 17:55:52 UTC (rev 14702)
@@ -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;
+
More information about the open-ils-commits
mailing list