3 INSERT INTO config.upgrade_log (version) VALUES ('0251'); --miker
5 CREATE OR REPLACE FUNCTION vandelay.overlay_bib_record ( import_id BIGINT, eg_id BIGINT, merge_profile_id INT ) RETURNS BOOL AS $$
7 merge_profile vandelay.merge_profile%ROWTYPE;
8 dyn_profile vandelay.compile_profile%ROWTYPE;
19 SELECT b.marc INTO eg_marc
20 FROM biblio.record_entry b
21 JOIN vandelay.bib_match m ON (m.eg_record = b.id AND m.queued_record = import_id)
24 SELECT q.marc INTO v_marc
25 FROM vandelay.queued_record q
26 JOIN vandelay.bib_match m ON (m.queued_record = q.id AND q.id = import_id)
29 IF eg_marc IS NULL OR v_marc IS NULL THEN
30 -- RAISE NOTICE 'no marc for vandelay or bib record';
34 dyn_profile := vandelay.compile_profile( v_marc );
36 IF merge_profile_id IS NOT NULL THEN
37 SELECT * INTO merge_profile FROM vandelay.merge_profile WHERE id = merge_profile_id;
39 dyn_profile.add_rule := BTRIM( dyn_profile.add_rule || ',' || COALESCE(merge_profile.add_spec,''), ',');
40 dyn_profile.strip_rule := BTRIM( dyn_profile.strip_rule || ',' || COALESCE(merge_profile.strip_spec,''), ',');
41 dyn_profile.replace_rule := BTRIM( dyn_profile.replace_rule || ',' || COALESCE(merge_profile.replace_spec,''), ',');
42 dyn_profile.preserve_rule := BTRIM( dyn_profile.preserve_rule || ',' || COALESCE(merge_profile.preserve_spec,''), ',');
46 IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
47 -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
51 IF dyn_profile.replace_rule <> '' THEN
53 target_marc = eg_marc;
54 replace_rule = dyn_profile.replace_rule;
56 source_marc = eg_marc;
58 replace_rule = dyn_profile.preserve_rule;
61 UPDATE biblio.record_entry
62 SET marc = vandelay.merge_record_xml( target_marc, source_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule )
66 UPDATE vandelay.queued_bib_record
67 SET imported_as = eg_id,
71 editor_string := (oils_xpath('//*[@tag="905"]/*[@code="u"]/text()',v_marc))[1];
73 IF editor_string IS NOT NULL AND editor_string <> '' THEN
74 SELECT usr INTO editor_id FROM actor.card WHERE barcode = editor_string;
76 IF editor_id IS NULL THEN
77 SELECT id INTO editor_id FROM actor.usr WHERE usrname = editor_string;
80 IF editor_id IS NOT NULL THEN
81 UPDATE biblio.record_entry SET editor = editor_id WHERE id = eg_id;
88 -- RAISE NOTICE 'update of biblio.record_entry failed';