Commit 40be4275 authored by Jamie McClelland's avatar Jamie McClelland

modifying db schema (and upgrade path) for new dynamic petition

functionality.
parent 55496ca4
......@@ -11,7 +11,7 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base {
*
*/
public function install() {
$this->executeSqlFile('sql/Petitionemail_install.sql');
// Nothing to do. All *_install.sql files installed automatically.
}
/**
......@@ -19,7 +19,31 @@ class CRM_Petitionemail_Upgrader extends CRM_Petitionemail_Upgrader_Base {
*
*/
public function uninstall() {
$this->executeSqlFile('sql/Petitionemail_uninstall.sql');
// Nothing to do. All *_uninstall.sql files installed automatically.
}
/**
* Add new fields and table allowing for dynamic targets to be selected.
*
*/
function upgrade_1001() {
// First create the two new tables
if(!$this->executeSqlFile('sql/Petitionemail_target_install.sql')) return FALSE;
if(!$this->executeSqlFile('sql/Petitionemail_matching_field_install.sql')) return FALSE;
// Now transfer the data to the new tables
$sql = "SELECT petition_id, recipient_email, recipient_name FROM civicrm_petition_email";
$dao = CRM_Core_DAO::executeQuery($sql);
while($dao->fetch()) {
$target = '"' . $dao->recipient_name . '" <' . $dao->recipient_email . '>';
$sql = "INSERT INTO civicrm_petition_email_target SET petition_id = %0, target = %1";
$params = array(
0 => array($dao->petition_id, 'Integer'),
1 => array($target, 'String')
);
CRM_Core_DAO::executeQuery($sql, $params);
}
if(!$this->executeSqlFile('sql/Petitionemail_1001_upgrade.sql')) return FALSE;
return TRUE;
}
}
--
-- SQL statements to handle the 1001 upgrade
ALTER TABLE civicrm_petition_email DROP COLUMN `recipient_email`;
ALTER TABLE civicrm_petition_email DROP COLUMN `recipient_name`;
ALTER TABLE civicrm_petition_email ADD COLUMN `group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the CiviCRM Group representing the petition targets.' AFTER petition_id;
ALTER TABLE civicrm_petition_email ADD COLUMN `location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.' AFTER group_id;
......@@ -4,11 +4,11 @@
CREATE TABLE IF NOT EXISTS `civicrm_petition_email` (
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`recipient_email` varchar(128) DEFAULT NULL COMMENT 'The email of the petition target.',
`recipient_name` varchar(128) DEFAULT NULL COMMENT 'The display name of the petition target.',
`group_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the CiviCRM Group representing the petition targets.',
`location_type_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The location type that should be used when selecting the target email address.',
`default_message` text COMMENT 'The default message for the petition',
`message_field` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The ID of the custom field used for petition messages.',
`subject` varchar(128) DEFAULT NULL COMMENT 'The subject line for outgoing emails.',
PRIMARY KEY (`petition_id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores recipient and message information for petitions...';
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores recipient and message information for petitions.';
--
-- Table structure for table `civicrm_petition_email_matching_field`
--
CREATE TABLE IF NOT EXISTS `civicrm_petition_email_matching_field` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The unique ID of the email field.',
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`matching_field` text COMMENT 'The name of the field that should match between petition signer and target.',
PRIMARY KEY (`id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores the fields used to match petition signers and targets.';
--
-- Table structure for table `civicrm_petition_email_target`
--
CREATE TABLE IF NOT EXISTS `civicrm_petition_email_target` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The unique ID of the target.',
`petition_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The SID of the petition.',
`target` varchar(255) COMMENT 'The name and email address of additional targets that should receive a copy of all petitions signed.',
PRIMARY KEY (`id`),
KEY `petition_id` (`petition_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores the additional targets that should receive a copy of all petitions signed.';
DROP TABLE IF EXISTS `civicrm_petition_email`;
DROP TABLE IF EXISTS `civicrm_petition_email_matching_field`;
DROP TABLE IF EXISTS `civicrm_petition_email_target`;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment