[open-ils-commits] r16525 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu May 27 16:16:38 EDT 2010
Author: miker
Date: 2010-05-27 16:16:33 -0400 (Thu, 27 May 2010)
New Revision: 16525
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0282.schema.user-visiable-holds
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
Log:
adding function to return holds visible to the user, based on their horizon settings; fixing logic reversal in circ version of same
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-27 18:47:48 UTC (rev 16524)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-05-27 20:16:33 UTC (rev 16525)
@@ -65,7 +65,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0281'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0282'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2010-05-27 18:47:48 UTC (rev 16524)
+++ trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2010-05-27 20:16:33 UTC (rev 16525)
@@ -606,7 +606,7 @@
FROM action.circulation
WHERE usr = usr_id
AND parent_circ IS NULL
- AND xact_start < NOW() - view_age
+ AND xact_start > NOW() - view_age
ORDER BY xact_start
LOOP
RETURN NEXT c;
@@ -616,6 +616,68 @@
END;
$func$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$
+DECLARE
+ h action.hold_request%ROWTYPE;
+ view_age INTERVAL;
+ view_count INT;
+ usr_view_count actor.usr_setting%ROWTYPE;
+ usr_view_age actor.usr_setting%ROWTYPE;
+BEGIN
+ SELECT * INTO usr_view_count FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_count';
+ SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_age';
+
+ IF usr_view_count.value IS NULL AND usr_view_age.value IS NULL THEN
+ -- Only show "open" holds
+ FOR h IN
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND fulfillment_time IS NULL
+ AND cancel_time IS NULL
+ ORDER BY xact_start
+ LOOP
+ RETURN NEXT h;
+ END LOOP;
+
+ RETURN;
+ END IF;
+
+ IF usr_view_age.value IS NOT NULL THEN
+ view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
+ ELSE
+ view_age := '2000 years'::INTERVAL;
+ END IF;
+
+ IF usr_view_count.value IS NOT NULL THEN
+ view_count := oils_json_to_string(usr_view_count.value)::INT;
+ ELSE
+ view_count := 1000;
+ END IF;
+
+ -- Else, show those /and/ some fulfilled/canceled holds
+ FOR h IN
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND fulfillment_time IS NULL
+ AND cancel_time IS NULL
+ UNION ALL
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND ( fulfillment_time IS NOT NULL OR cancel_time IS NOT NULL )
+ AND request_time > NOW() - view_age
+ ORDER BY request_time
+ LIMIT view_count
+ LOOP
+ RETURN NEXT h;
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
CREATE OR REPLACE FUNCTION action.purge_circulations () RETURNS INT AS $func$
DECLARE
usr_keep_age actor.usr_setting%ROWTYPE;
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-05-27 18:47:48 UTC (rev 16524)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-05-27 20:16:33 UTC (rev 16525)
@@ -4994,4 +4994,18 @@
'date'
);
+INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
+ VALUES (
+ 'history.hold.retention_age',
+ TRUE,
+ oils_i18n_gettext('history.hold.retention_age','Historical Hold Retention Age','cust','label'),
+ oils_i18n_gettext('history.hold.retention_age','Historical Hold Retention Age','cust','description'),
+ 'interval'
+ ),(
+ 'history.hold.retention_count',
+ TRUE,
+ oils_i18n_gettext('history.hold.retention_count','Historical Hold Retention Count','cust','label'),
+ oils_i18n_gettext('history.hold.retention_count','Historical Hold Retention Count','cust','description'),
+ 'integer'
+ );
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0282.schema.user-visiable-holds
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0282.schema.user-visiable-holds (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0282.schema.user-visiable-holds 2010-05-27 20:16:33 UTC (rev 16525)
@@ -0,0 +1,115 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0282');
+
+INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
+ VALUES ('history.hold.retention_age', TRUE, 'Historical Hold Retention Age', 'Historical Hold Retention Age', 'interval');
+INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
+ VALUES ('history.hold.retention_count', TRUE, 'Historical Hold Retention Count', 'Historical Hold Retention Count', 'integer');
+
+
+-- Logic reversal, fixing
+CREATE OR REPLACE FUNCTION action.usr_visible_circs (usr_id INT) RETURNS SETOF action.circulation AS $func$
+DECLARE
+ c action.circulation%ROWTYPE;
+ view_age INTERVAL;
+ usr_view_age actor.usr_setting%ROWTYPE;
+ usr_view_start actor.usr_setting%ROWTYPE;
+BEGIN
+ SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_age';
+ SELECT * INTO usr_view_start FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.circ.retention_start_date';
+
+ IF usr_view_age.value IS NOT NULL AND usr_view_start.value IS NOT NULL THEN
+ -- User opted in and supplied a retention age
+ IF oils_json_to_string(usr_view_age.value)::INTERVAL > AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ) THEN
+ view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
+ ELSE
+ view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
+ END IF;
+ ELSIF usr_view_start.value IS NOT NULL THEN
+ -- User opted in
+ view_age := AGE(NOW(), oils_json_to_string(usr_view_start.value)::TIMESTAMPTZ);
+ ELSE
+ -- User did not opt in
+ RETURN;
+ END IF;
+
+ FOR c IN
+ SELECT *
+ FROM action.circulation
+ WHERE usr = usr_id
+ AND parent_circ IS NULL
+ AND xact_start > NOW() - view_age
+ ORDER BY xact_start
+ LOOP
+ RETURN NEXT c;
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION action.usr_visible_holds (usr_id INT) RETURNS SETOF action.hold_request AS $func$
+DECLARE
+ h action.hold_request%ROWTYPE;
+ view_age INTERVAL;
+ view_count INT;
+ usr_view_count actor.usr_setting%ROWTYPE;
+ usr_view_age actor.usr_setting%ROWTYPE;
+BEGIN
+ SELECT * INTO usr_view_count FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_count';
+ SELECT * INTO usr_view_age FROM actor.usr_setting WHERE usr = usr_id AND name = 'history.hold.retention_age';
+
+ IF usr_view_count.value IS NULL AND usr_view_age.value IS NULL THEN
+ -- Only show "open" holds
+ FOR h IN
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND fulfillment_time IS NULL
+ AND cancel_time IS NULL
+ ORDER BY xact_start
+ LOOP
+ RETURN NEXT h;
+ END LOOP;
+
+ RETURN;
+ END IF;
+
+ IF usr_view_age.value IS NOT NULL THEN
+ view_age := oils_json_to_string(usr_view_age.value)::INTERVAL;
+ ELSE
+ view_age := '2000 years'::INTERVAL;
+ END IF;
+
+ IF usr_view_count.value IS NOT NULL THEN
+ view_count := oils_json_to_string(usr_view_count.value)::INT;
+ ELSE
+ view_count := 1000;
+ END IF;
+
+ -- Else, show those /and/ some fulfilled/canceled holds
+ FOR h IN
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND fulfillment_time IS NULL
+ AND cancel_time IS NULL
+ UNION ALL
+ SELECT *
+ FROM action.hold_request
+ WHERE usr = usr_id
+ AND ( fulfillment_time IS NOT NULL OR cancel_time IS NOT NULL )
+ AND request_time > NOW() - view_age
+ ORDER BY request_time
+ LIMIT view_count
+ LOOP
+ RETURN NEXT h;
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list