]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/1022.schema.more_overlay_funcs.sql
LP#1759238: stamping upgrade script
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 1022.schema.more_overlay_funcs.sql
1 BEGIN;
2
3 SELECT evergreen.upgrade_deps_block_check('1022', :eg_version);
4
5 CREATE OR REPLACE FUNCTION vandelay.merge_record_xml_using_profile ( incoming_marc TEXT, existing_marc TEXT, merge_profile_id BIGINT ) RETURNS TEXT AS $$
6 DECLARE
7     merge_profile   vandelay.merge_profile%ROWTYPE;
8     dyn_profile     vandelay.compile_profile%ROWTYPE;
9     target_marc     TEXT;
10     source_marc     TEXT;
11     replace_rule    TEXT;
12     match_count     INT;
13 BEGIN
14
15     IF existing_marc IS NULL OR incoming_marc IS NULL THEN
16         -- RAISE NOTICE 'no marc for source or target records';
17         RETURN NULL;
18     END IF;
19
20     IF merge_profile_id IS NOT NULL THEN
21         SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
22         IF FOUND THEN
23             dyn_profile.add_rule := COALESCE(merge_profile.add_spec,'');
24             dyn_profile.strip_rule := COALESCE(merge_profile.strip_spec,'');
25             dyn_profile.replace_rule := COALESCE(merge_profile.replace_spec,'');
26             dyn_profile.preserve_rule := COALESCE(merge_profile.preserve_spec,'');
27         ELSE
28             -- RAISE NOTICE 'merge profile not found';
29             RETURN NULL;
30         END IF;
31     ELSE
32         -- RAISE NOTICE 'no merge profile specified';
33         RETURN NULL;
34     END IF;
35
36     IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
37         -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
38         RETURN NULL;
39     END IF;
40
41     IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' AND dyn_profile.strip_rule = '' THEN
42         -- Since we have nothing to do, just return a target record as is
43         RETURN existing_marc;
44     ELSIF dyn_profile.preserve_rule <> '' THEN
45         source_marc = existing_marc;
46         target_marc = incoming_marc;
47         replace_rule = dyn_profile.preserve_rule;
48     ELSE
49         source_marc = incoming_marc;
50         target_marc = existing_marc;
51         replace_rule = dyn_profile.replace_rule;
52     END IF;
53
54     RETURN vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule );
55
56 END;
57 $$ LANGUAGE PLPGSQL;
58
59 COMMIT;