[open-ils-commits] r1250 - in conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application: . Trigger (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Feb 28 23:38:14 EST 2011
Author: dbs
Date: 2011-02-28 23:38:12 -0500 (Mon, 28 Feb 2011)
New Revision: 1250
Added:
conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application/Trigger/
conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
Log:
Add the baseline rel_1_6_1 Reactor.pm before our customizations
Added: conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
===================================================================
--- conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application/Trigger/Reactor.pm (rev 0)
+++ conifer/branches/rel_1_6_1/src/perlmods/OpenILS/Application/Trigger/Reactor.pm 2011-03-01 04:38:12 UTC (rev 1250)
@@ -0,0 +1,128 @@
+package OpenILS::Application::Trigger::Reactor;
+use strict; use warnings;
+use Template;
+use DateTime;
+use DateTime::Format::ISO8601;
+use OpenSRF::Utils qw/:datetime/;
+use OpenSRF::Utils::Logger qw(:logger);
+use OpenILS::Application::AppUtils;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
+my $U = 'OpenILS::Application::AppUtils';
+
+sub fourty_two { return 42 }
+sub NOOP_True { return 1 }
+sub NOOP_False { return 0 }
+
+
+
+
+# helper functions inserted into the TT environment
+my $_TT_helpers = {
+
+ # turns a date into something TT can understand
+ format_date => sub {
+ my $date = shift;
+ $date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($date));
+ return sprintf(
+ "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d",
+ $date->hour,
+ $date->minute,
+ $date->second,
+ $date->day,
+ $date->month,
+ $date->year
+ );
+ },
+
+ # escapes a string for inclusion in an XML document. escapes &, <, and > characters
+ escape_xml => sub {
+ my $str = shift;
+ $str =~ s/&/&/sog;
+ $str =~ s/</</sog;
+ $str =~ s/>/>/sog;
+ return $str;
+ },
+
+ # returns the calculated user locale
+ get_user_locale => sub {
+ my $user_id = shift;
+ return $U->get_user_locale($user_id);
+ },
+
+ # returns the calculated copy price
+ get_copy_price => sub {
+ my $copy_id = shift;
+ return $U->get_copy_price(new_editor(), $copy_id);
+ },
+
+ # given a copy, returns the title and author in a hash
+ get_copy_bib_basics => sub {
+ my $copy_id = shift;
+ my $copy = new_editor()->retrieve_asset_copy([
+ $copy_id,
+ {
+ flesh => 2,
+ flesh_fields => {
+ acp => ['call_number'],
+ acn => ['record']
+ }
+ }
+ ]);
+ if($copy->call_number->id == -1) {
+ return {
+ title => $copy->dummy_title,
+ author => $copy->dummy_author,
+ };
+ } else {
+ my $mvr = $U->record_to_mvr($copy->call_number->record);
+ return {
+ title => $mvr->title,
+ author => $mvr->author
+ };
+ }
+ },
+
+ # returns the org unit setting value
+ get_org_setting => sub {
+ my($org_id, $setting) = @_;
+ return $U->ou_ancestor_setting_value($org_id, $setting);
+ },
+};
+
+
+# processes templates. Returns template output on success, undef on error
+sub run_TT {
+ my $self = shift;
+ my $env = shift;
+ my $nostore = shift;
+ return undef unless $env->{template};
+
+ my $error;
+ my $output = '';
+ my $tt = Template->new;
+ $env->{helpers} = $_TT_helpers;
+
+ unless( $tt->process(\$env->{template}, $env, \$output) ) {
+ $output = undef;
+ ($error = $tt->error) =~ s/\n/ /og;
+ $logger->error("Error processing Trigger template: $error");
+ }
+
+ if ( $error or (!$nostore && $output) ) {
+ my $t_o = Fieldmapper::action_trigger::event_output->new;
+ $t_o->data( ($error) ? $error : $output );
+ $t_o->is_error( ($error) ? 't' : 'f' );
+
+ $env->{EventProcessor}->editor->xact_begin;
+ $t_o = $env->{EventProcessor}->editor->create_action_trigger_event_output( $t_o );
+
+ my $state = (ref $$env{event} eq 'ARRAY') ? $$env{event}->[0]->state : $env->{event}->state;
+ my $key = ($error) ? 'error_output' : 'template_output';
+ $env->{EventProcessor}->update_state( $state, { $key => $t_o->id } );
+ }
+
+ return $output;
+}
+
+
+1;
More information about the open-ils-commits
mailing list