[open-ils-commits] r7742 - in trunk/Open-ILS/src:
perlmods/OpenILS/Application/Storage/Publisher sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Aug 29 16:35:37 EDT 2007
Author: miker
Date: 2007-08-29 16:29:43 -0400 (Wed, 29 Aug 2007)
New Revision: 7742
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm
trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql
trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
Log:
adding storage method open-ils.storage.asset.merge_record_assets to call stored proc version of the record merging logic
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm 2007-08-29 20:16:35 UTC (rev 7741)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm 2007-08-29 20:29:43 UTC (rev 7742)
@@ -794,5 +794,31 @@
api_level => 1,
);
+sub merge_record_assets {
+ my $self = shift;
+ my $client = shift;
+ my $target = shift;
+ my @sources = @_;
+ my $count = 0;
+ for my $source ( @sources ) {
+ $count += asset::call_number
+ ->db_Main
+ ->selectcol_arrayref(
+ "SELECT asset.merge_record_assets(?,?);",
+ {},
+ $target,
+ $source
+ )->[0];
+ }
+
+ return $count;
+}
+__PACKAGE__->register_method(
+ api_name => 'open-ils.storage.asset.merge_record_assets',
+ method => 'merge_record_assets',
+ argc => 2,
+ api_level => 1,
+)
+
1;
Modified: trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql 2007-08-29 20:16:35 UTC (rev 7741)
+++ trunk/Open-ILS/src/sql/Pg/020.schema.functions.sql 2007-08-29 20:29:43 UTC (rev 7742)
@@ -171,3 +171,4 @@
stype = anyarray,
initcond = '{}'
);
+
Modified: trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2007-08-29 20:16:35 UTC (rev 7741)
+++ trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2007-08-29 20:29:43 UTC (rev 7742)
@@ -174,5 +174,36 @@
FROM asset.call_number cn
JOIN metabib.rec_descriptor rd ON (rd.record = cn.record);
+CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
+DECLARE
+ moved_cns INT := 0;
+ source_cn asset.call_number%ROWTYPE;
+ target_cn asset.call_number%ROWTYPE;
+BEGIN
+ FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
+ SELECT INTO target_cn *
+ FROM asset.call_number
+ WHERE label = source_cn.label
+ AND owning_lib = source_cn.owning_lib
+ AND record = source_cn.record;
+
+ IF FOUND THEN
+ UPDATE asset.copy
+ SET call_number = target_cn.id
+ WHERE call_number = source_cn.id;
+ ELSE
+ UPDATE asset.call_number
+ SET record = target_record
+ WHERE id = source_cn.id;
+ END IF;
+
+ moved_cns := moved_cns + 1;
+ END LOOP;
+
+ RETURN moved_cns;
+END;
+$func$ LANGUAGE plpgsql;
+
COMMIT;
+
More information about the open-ils-commits
mailing list