3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6.alpha1 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2014
34 class CRM_Upgrade_Incremental_php_FourSix
{
35 const BATCH_SIZE
= 5000;
42 public function verifyPreDBstate(&$errors) {
47 * Compute any messages which should be displayed beforeupgrade
49 * Note: This function is called iteratively for each upcoming
50 * revision to the database.
52 * @param $preUpgradeMessage
54 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
55 * @param null $currentVer
59 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
63 * Compute any messages which should be displayed after upgrade
65 * @param string $postUpgradeMessage
68 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
71 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
72 if ($rev == '4.6.alpha1') {
73 $postUpgradeMessage .= '<br /><br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Events - Registration Confirmation and Receipt (on-line)</li><li>Events - Registration Confirmation and Receipt (off-line)</li><li>Contributions - Receipt (on-line)</li><li>Contributions - Receipt (off-line)</li><li>Memberships - Receipt (on-line)</li><li>Memberships - Signup and Renewal Receipts (off-line)</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).');
75 if ($rev == '4.6.alpha3') {
76 $postUpgradeMessage .= '<br /><br />' . ts('A new permission has been added for editing message templates. Previously, users needed the "administer CiviCRM" permission. Now, users need the new permission called "edit message templates." Please check your CMS permissions to ensure that users who should be able to edit message templates are assigned this new permission.');
82 * (Queue Task Callback)
84 public static function task_4_6_x_runSql(CRM_Queue_TaskContext
$ctx, $rev) {
85 $upgrade = new CRM_Upgrade_Form();
86 $upgrade->processSQL($rev);
92 * Syntactic sugar for adding a task which (a) is in this class and (b) has
95 * After passing the $funcName, you can also pass parameters that will go to
96 * the function. Note that all params must be serializable.
98 protected function addTask($title, $funcName) {
99 $queue = CRM_Queue_Service
::singleton()->load(array(
101 'name' => CRM_Upgrade_Form
::QUEUE_NAME
,
104 $args = func_get_args();
105 $title = array_shift($args);
106 $funcName = array_shift($args);
107 $task = new CRM_Queue_Task(
108 array(get_class($this), $funcName),
112 $queue->createItem($task, array('weight' => -1));
115 function upgrade_4_6_alpha3($rev) {
116 // task to process sql
117 $this->addTask(ts('Adding column reference date and updating with '), 'updateReferenceDate');
120 // CRM-15728, Add new column reference_date to civicrm_action_log in order to track
121 // actual action_start_date for membership entity for only those schedule reminders which are not repeatable
122 static function updateReferenceDate(CRM_Queue_TaskContext
$ctx) {
123 $query = "ALTER TABLE `civicrm_action_log`
124 ADD COLUMN `reference_date` date COMMENT 'Stores the date from the entity which triggered this reminder action (e.g. membership.end_date for most membership renewal reminders)'";
125 CRM_Core_DAO
::executeQuery($query);
127 $query = "SELECT schedule.* FROM civicrm_action_schedule schedule
128 LEFT JOIN civicrm_action_mapping mapper ON mapper.id = schedule.mapping_id AND
129 mapper.entity = 'civicrm_membership' AND is_repeat = 0";
130 $dao = CRM_Core_DAO
::executeQuery($query);
131 while($dao->fetch()) {
132 if (empty($dao->start_action_date
)) {
136 $referenceColumn = str_replace('membership_', "m.", $dao->start_action_date
);
138 'reminder.reference_date IS NOT NULL',
139 '( m.is_override IS NULL OR m.is_override = 0 )',
140 'reminder.action_date_time >= DATE_SUB(reminder.action_date_time, INTERVAL 9 MONTH)'
142 $value = implode(', ', explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($dao->entity_value
, CRM_Core_DAO
::VALUE_SEPARATOR
)));
143 if (!empty($value)) {
144 $where[] = "m.membership_type_id IN ({$value})";
147 $where[] = "m.membership_type_id IS NULL";
150 // Update reference_date with action_start_date chosen,
151 // only to those which falls under date limits configured on schedule reminder
152 $startDateClause = array();
153 $op = ($dao->start_action_condition
== 'before' ?
'<=' : '>=');
154 $operator = ($dao->start_action_condition
== 'before' ?
'DATE_SUB' : 'DATE_ADD');
155 $date = $operator . "({$referenceColumn}, INTERVAL {$dao->start_action_offset} {$dao->start_action_unit})";
156 $where[] = "NOW() >= {$date}";
157 $where[] = "DATE_SUB(NOW(), INTERVAL 1 DAY ) <= {$date}";
159 $sql = "UPDATE civicrm_action_log reminder
160 LEFT JOIN civicrm_membership m ON reminder.entity_id = m.id
161 SET reminder.reference_date = {$referenceColumn}
163 WHERE " . implode(" AND ", $where);
164 CRM_Core_DAO
::executeQuery($sql);