From: erickson Date: Mon, 8 Dec 2008 22:08:11 +0000 (+0000) Subject: make the org-ancestor-setting proc return SETOF so that returning 0 rows is an option... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eafc9400ce74513bc304d8574c7c43a492f0215b;p=Evergreen.git make the org-ancestor-setting proc return SETOF so that returning 0 rows is an option. update the cstore query that calls this proc to use the new-style call and re-use some code git-svn-id: svn://svn.open-ils.org/ILS/trunk@11455 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index a8b9fa73e7..57c4a07afa 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1245,49 +1245,18 @@ sub make_mbts { sub ou_ancestor_setting_value { my($self, $org_id, $name, $e) = @_; $e = $e || OpenILS::Utils::CStoreEditor->new; - my $query = { - select => { - aous => [ { - transform => 'actor.org_unit_ancestor_setting', - params => [$org_id], - column => 'name', - result_field => 'value', - alias => 'value' - } ] - }, - from => 'aous', - where => {name => $name}, - limit => 1 # since name is not required to be unique, this approach could return duplicate rows - }; - - my $obj = $e->json_query($query); - return OpenSRF::Utils::JSON->JSON2perl($obj->[0]->{value}) if @$obj; + my $set = $self->ou_ancestor_setting($org_id, $name, $e); + return $set->{value} if $set; return undef; } sub ou_ancestor_setting { my( $self, $orgid, $name, $e ) = @_; $e = $e || OpenILS::Utils::CStoreEditor->new; - - my $query = { - select => { - aous => [ { - transform => 'actor.org_unit_ancestor_setting', - params => [$orgid], - column => 'name', - result_field => 'id', - alias => 'id' - } ] - }, - from => 'aous', - where => {name => $name}, - limit => 1 # since name is not required to be unique, this approach could return duplicate rows - }; - - my $obj = $e->json_query($query); - return undef unless @$obj; - my $setting = $e->retrieve_actor_org_unit_setting($obj->[0]->{id}); - return { org => $setting->org_unit, value => OpenSRF::Utils::JSON->JSON2perl($setting->value) }; + my $query = {from => ['actor.org_unit_ancestor_setting', $name, $orgid]}; + my $setting = $e->json_query($query)->[0]; + return undef unless $setting; + return {org => $setting->{org_unit}, value => OpenSRF::Utils::JSON->JSON2perl($setting->{value})}; } diff --git a/Open-ILS/src/sql/Pg/020.schema.functions.sql b/Open-ILS/src/sql/Pg/020.schema.functions.sql index b7f6a11afe..d0fc868863 100644 --- a/Open-ILS/src/sql/Pg/020.schema.functions.sql +++ b/Open-ILS/src/sql/Pg/020.schema.functions.sql @@ -206,7 +206,7 @@ CREATE OR REPLACE FUNCTION actor.org_unit_proximity ( INT, INT ) RETURNS INT AS ) z; $$ LANGUAGE SQL STABLE; -CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting( setting_name TEXT, org_id INT ) RETURNS actor.org_unit_setting AS $$ +CREATE OR REPLACE FUNCTION actor.org_unit_ancestor_setting( setting_name TEXT, org_id INT ) RETURNS SETOF actor.org_unit_setting AS $$ DECLARE setting RECORD; cur_org INT; @@ -215,13 +215,12 @@ BEGIN LOOP SELECT INTO setting * FROM actor.org_unit_setting WHERE org_unit = cur_org AND name = setting_name; IF FOUND THEN - RETURN setting; + RETURN NEXT setting; END IF; SELECT INTO cur_org parent_ou FROM actor.org_unit WHERE id = cur_org; - IF cur_org IS NULL THEN - RETURN NULL; - END IF; + EXIT WHEN cur_org IS NULL; END LOOP; + RETURN; END; $$ LANGUAGE plpgsql;