}
}
};
- if ($org != $pref_ou) {
- $query->{from}->{acp}->{aou}->{filter}->{id}->{in}->{select}->{aou} = [{
- column => 'id',
- transform => 'actor.org_unit_descendants_pref_lib',
- result_field => 'id',
- params => [$depth, $pref_ou]
- }];
- }
};
# Filter hidden items if this is the public catalog
) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth USING (id);
$$ LANGUAGE SQL ROWS 1;
-CREATE OR REPLACE FUNCTION actor.org_unit_descendants_pref_lib (
- ou INT,
- depth INT,
- pref_ou INT
-) RETURNS SETOF actor.org_unit AS $$
- SELECT ou.* FROM actor.org_unit_descendants($1, $2) AS ou
- UNION
- SELECT ou.* FROM actor.org_unit ou WHERE id = $3;
-$$ LANGUAGE SQL STABLE ROWS 1;
-
-COMMENT ON FUNCTION actor.org_unit_descendants_pref_lib( INT, INT, INT) IS $$
-Returns the descendants by depth of the specified library, but adds the
-preferred library if it is not contained in the set of descendants.
-$$;
-
CREATE OR REPLACE FUNCTION actor.org_unit_descendants_distance( INT ) RETURNS TABLE (id INT, distance INT) AS $$
WITH RECURSIVE org_unit_descendants_distance(id, distance) AS (
SELECT $1, 0
SELECT id, distance FROM actor.org_unit_descendants_distance($2)
)
SELECT COALESCE(
- (SELECT -10000 FROM actor.org_unit WHERE $1 = $3 AND id = $3),
+ (SELECT -10000 FROM actor.org_unit
+ WHERE $1 = $3 AND id = $3 AND $2 IN (
+ SELECT id FROM actor.org_unit WHERE parent_ou IS NULL
+ )
+ ),
(SELECT distance FROM search_libs WHERE id = $1),
10000
);
-- check whether patch can be applied
SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
-CREATE OR REPLACE FUNCTION actor.org_unit_descendants_pref_lib (
- ou INT,
- depth INT,
- pref_ou INT
-) RETURNS SETOF actor.org_unit AS $$
- SELECT ou.* FROM actor.org_unit_descendants($1, $2) AS ou
- UNION
- SELECT ou.* FROM actor.org_unit ou WHERE id = $3;
-$$ LANGUAGE SQL STABLE ROWS 1;
-
-COMMENT ON FUNCTION actor.org_unit_descendants_pref_lib( INT, INT, INT) IS $$
-Returns the descendants by depth of the specified library, but adds the
-preferred library if it is not contained in the set of descendants.
-$$;
-
-- The simplest way to apply all of these changes is just to replace the unapi
-- schema entirely -- the following is a copy of 990.schema.unapi.sql with
-- the initial COMMIT in place in case the upgrade_deps_block_check fails;
SELECT id, distance FROM actor.org_unit_descendants_distance($2)
)
SELECT COALESCE(
- (SELECT -10000 FROM actor.org_unit WHERE $1 = $3 AND id = $3),
+ (SELECT -10000 FROM actor.org_unit
+ WHERE $1 = $3 AND id = $3 AND $2 IN (
+ SELECT id FROM actor.org_unit WHERE parent_ou IS NULL
+ )
+ ),
(SELECT distance FROM search_libs WHERE id = $1),
10000
);