[open-ils-commits] r14694 - in trunk/Open-ILS/src: perlmods/OpenILS/Application/Trigger sql/Pg sql/Pg/upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Oct 29 22:52:52 EDT 2009
Author: miker
Date: 2009-10-29 22:52:49 -0400 (Thu, 29 Oct 2009)
New Revision: 14694
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0063.data.min-target-age-validator.sql
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Log:
add a validator (for stacking) to optionally check the age of an event target
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-10-30 01:55:59 UTC (rev 14693)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Validator.pm 2009-10-30 02:52:49 UTC (rev 14694)
@@ -16,6 +16,11 @@
return 0 if (defined($env->{target}->checkin_time));
return 0 if ($env->{params}->{max_delay_age} && !$self->MaxPassiveDelayAge($env));
+ if ($env->{params}->{min_target_age}) {
+ $env->{params}->{target_age_field} = 'xact_start';
+ return 0 if (!$self->MinPassiveTargetAge($env));
+ }
+
return 1;
}
@@ -38,6 +43,21 @@
return 0;
}
+sub MinPassiveTargetAge {
+ my $self = shift;
+ my $env = shift;
+ my $target = $env->{target};
+ my $delay_field = $env->{params}->{target_age_field} || $env->{event}->event_def->delay_field;
+
+ my $delay_field_ts = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($target->$delay_field()));
+
+ # to get the minimum time that the target must have aged to, add the min age to the delay field
+ $delay_field_ts->add( seconds => interval_to_seconds( $env->{params}->{min_target_age} ) );
+
+ return 1 if $delay_field_ts <= DateTime->now;
+ return 0;
+}
+
sub CircIsOverdue {
my $self = shift;
my $env = shift;
@@ -47,6 +67,11 @@
return 0 if $circ->stop_fines and not $circ->stop_fines =~ /MAXFINES|LONGOVERDUE/;
return 0 if ($env->{params}->{max_delay_age} && !$self->MaxPassiveDelayAge($env));
+ if ($env->{params}->{min_target_age}) {
+ $env->{params}->{target_age_field} = 'xact_start';
+ return 0 if (!$self->MinPassiveTargetAge($env));
+ }
+
my $due_date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($circ->due_date));
return 0 if $due_date > DateTime->now;
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-30 01:55:59 UTC (rev 14693)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-30 02:52:49 UTC (rev 14694)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0061'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0063'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql 2009-10-30 01:55:59 UTC (rev 14693)
+++ trunk/Open-ILS/src/sql/Pg/400.schema.action_trigger.sql 2009-10-30 02:52:49 UTC (rev 14694)
@@ -77,6 +77,7 @@
INSERT INTO action_trigger.validator (module,description) VALUES ('HoldIsAvailable','Check that an item is on the hold shelf');
INSERT INTO action_trigger.validator (module,description) VALUES ('CircIsOverdue','Check that the circulation is overdue');
INSERT INTO action_trigger.validator (module,description) VALUES ('MaxPassiveDelayAge','Check that the event is not too far past the delay_field time -- requires a max_delay_age interval parameter');
+INSERT INTO action_trigger.validator (module,description) VALUES ('MinPassiveTargetAge','Check that the target is old enough to be used by this event -- requires a min_target_age interval parameter, and accepts an optional target_age_field to specify what time to use for offsetting');
-- After an event passes validation (action_trigger.validator), the reactor processes it.
CREATE TABLE action_trigger.reactor (
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0063.data.min-target-age-validator.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0063.data.min-target-age-validator.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0063.data.min-target-age-validator.sql 2009-10-30 02:52:49 UTC (rev 14694)
@@ -0,0 +1,8 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0063');
+
+INSERT INTO action_trigger.validator (module,description) VALUES ('MinPassiveTargetAge','Check that the target is old enough to be used by this event -- requires a min_target_age interval parameter, and accepts an optional target_age_field to specify what time to use for offsetting');
+
+COMMIT;
+
More information about the open-ils-commits
mailing list