r70357 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70356‎ | r70357 | r70358 >
Date:20:35, 2 August 2010
Author:kaldari
Status:deferred
Tags:
Comment:
updating triggers sync script for new donor comments system
Modified paths:
  • /civicrm/trunk/sites/all/bin/public_reporting/synchronize.sql (modified) (history)
  • /civicrm/trunk/sites/all/bin/public_reporting/triggers.sql (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/bin/public_reporting/triggers.sql
@@ -5,11 +5,13 @@
66 DROP TRIGGER IF EXISTS public_reporting_insert;
77 DROP TRIGGER IF EXISTS public_reporting_update;
88 DROP TRIGGER IF EXISTS public_reporting_contact_update;
 9+DROP TRIGGER IF EXISTS public_reporting_note_insert;
 10+DROP TRIGGER IF EXISTS public_reporting_note_update;
911 DELIMITER //
1012 CREATE TRIGGER public_reporting_insert AFTER INSERT ON civicrm_contribution FOR EACH ROW
1113 BEGIN
1214 DECLARE public_name VARCHAR(128) charset utf8;
13 - IF SUBSTRING(NEW.source, 1, 3) != 'RFD' THEN
 15+ IF SUBSTRING(NEW.source, 1, 3) != 'RFD' THEN -- don't trigger for refunds
1416 SET public_name := (SELECT IF(do_not_trade = 1 or NEW.payment_instrument_id = 4, NULL, SUBSTRING_INDEX(display_name, "@", 1))
1517 FROM civicrm_contact WHERE id = NEW.contact_id);
1618 INSERT INTO public_reporting (contribution_id, contact_id, name, converted_amount, original_currency,
@@ -23,7 +25,7 @@
2426 BEGIN
2527 DECLARE anonymous INTEGER;
2628 DECLARE public_name VARCHAR(128) charset utf8;
27 - IF SUBSTRING(NEW.source, 1, 3) = 'RFD' THEN
 29+ IF SUBSTRING(NEW.source, 1, 3) = 'RFD' THEN -- trigger for refunds
2830 DELETE from public_reporting
2931 WHERE public_reporting.contribution_id = NEW.id;
3032 ELSE
@@ -45,4 +47,14 @@
4648 UPDATE public_reporting pr SET pr.name = public_name WHERE pr.contact_id = NEW.id;
4749 END
4850 //
 51+CREATE TRIGGER public_reporting_note_insert AFTER INSERT ON civicrm_value_1_note_11 FOR EACH ROW
 52+BEGIN
 53+ UPDATE public_reporting pr SET pr.note = NEW.donor_comment WHERE pr.contribution_id = NEW.entity_id;
 54+END
 55+//
 56+CREATE TRIGGER public_reporting_note_update AFTER UPDATE ON civicrm_value_1_note_11 FOR EACH ROW
 57+BEGIN
 58+ UPDATE public_reporting pr SET pr.note = NEW.donor_comment WHERE pr.contribution_id = NEW.entity_id;
 59+END
 60+//
4961 DELIMITER ;
Index: civicrm/trunk/sites/all/bin/public_reporting/synchronize.sql
@@ -3,8 +3,30 @@
44 INSERT INTO public_reporting (contribution_id, contact_id, name, converted_amount, original_currency,
55 original_amount, note, received)
66 SELECT cn.id, ct.id, IF(ct.do_not_trade, NULL, SUBSTRING_INDEX(ct.display_name, "@", 1)), cn.total_amount,
7 - SUBSTRING(cn.source, 1, 3), CONVERT(SUBSTRING(cn.source, 5), DECIMAL(20,2)), cn.note, UNIX_TIMESTAMP(cn.receive_date)
 7+ SUBSTRING(cn.source, 1, 3), CONVERT(SUBSTRING(cn.source, 5), DECIMAL(20,2)), nt.note, UNIX_TIMESTAMP(cn.receive_date)
88 FROM civicrm_contribution cn
99 INNER JOIN civicrm_contact ct ON cn.contact_id = ct.id
 10+ LEFT JOIN civicrm_value_1_note_11 nt ON cn.id = nt.entity_id
1011 WHERE cn.total_amount >= 1;
1112 COMMIT;
 13+
 14+/* Use if donor comments are stored in notes table instead of custom field
 15+BEGIN;
 16+DELETE FROM public_reporting;
 17+CREATE TEMPORARY TABLE temp_notes (
 18+ contribution_id int(10) unsigned NOT NULL,
 19+ note text collate utf8_unicode_ci,
 20+ PRIMARY KEY (`contribution_id`)
 21+ );
 22+INSERT INTO temp_notes (contribution_id, note)
 23+SELECT entity_id, note FROM civicrm_note WHERE entity_table = 'civicrm_contribution';
 24+INSERT INTO public_reporting (contribution_id, contact_id, name, converted_amount, original_currency,
 25+ original_amount, note, received)
 26+SELECT cn.id, ct.id, IF(ct.do_not_trade, NULL, SUBSTRING_INDEX(ct.display_name, "@", 1)), cn.total_amount,
 27+ SUBSTRING(cn.source, 1, 3), CONVERT(SUBSTRING(cn.source, 5), DECIMAL(20,2)), tn.note, UNIX_TIMESTAMP(cn.receive_date)
 28+ FROM civicrm_contribution cn
 29+ INNER JOIN civicrm_contact ct ON cn.contact_id = ct.id
 30+ LEFT JOIN temp_notes tn ON cn.id = tn.contribution_id
 31+ WHERE cn.total_amount >= 1;
 32+COMMIT;
 33+*/
\ No newline at end of file

Status & tagging log