git formatting & comment fixes
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourFive.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25 */
26
27 /**
28 *
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2014
31 * $Id$
32 *
33 */
34 class CRM_Upgrade_Incremental_php_FourFive {
35 const BATCH_SIZE = 5000;
36
37 function verifyPreDBstate(&$errors) {
38 return TRUE;
39 }
40
41 /**
42 * Compute any messages which should be displayed beforeupgrade
43 *
44 * Note: This function is called iteratively for each upcoming
45 * revision to the database.
46 *
47 * @param $preUpgradeMessage
48 * @param $rev string, a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'
49 * @param null $currentVer
50 *
51 * @internal param string $postUpgradeMessage , alterable
52 * @return void
53 */
54 function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
55 }
56
57 /**
58 * Compute any messages which should be displayed after upgrade
59 *
60 * @param $postUpgradeMessage string, alterable
61 * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
62 * @return void
63 */
64 function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
65 if ($rev == '4.5.alpha1') {
66 $postUpgradeMessage .= '<br /><br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Contributions - Receipt (off-line)</li><li>Contributions - Receipt (on-line)</li><li>Memberships - Receipt (on-line)</li><li>Pledges - Acknowledgement</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).');
67 $postUpgradeMessage .= '<br /><br />' . ts('This release allows you to view and edit multiple-record custom field sets in a table format which will be more usable in some cases. You can try out the format by navigating to Administer > Custom Data & Screens > Custom Fields. Click Settings for a custom field set and change Display Style to "Tab with Tables".');
68 }
69 }
70
71 function upgrade_4_5_alpha1($rev) {
72 // task to process sql
73 $this->addTask(ts('Upgrade DB to 4.5.alpha1: SQL'), 'task_4_5_x_runSql', $rev);
74
75 $this->addTask(ts('Set default for Individual name fields configuration'), 'addNameFieldOptions');
76
77 return TRUE;
78 }
79
80 /**
81 * Add defaults for the newly introduced name fields configuration in 'contact_edit_options' setting
82 *
83 * @param CRM_Queue_TaskContext $ctx
84 *
85 * @return bool TRUE for success
86 */
87 static function addNameFieldOptions(CRM_Queue_TaskContext $ctx) {
88 $query = "SELECT `value` FROM `civicrm_setting` WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'";
89 $dao = CRM_Core_DAO::executeQuery($query);
90 $dao->fetch();
91 $oldValue = unserialize($dao->value);
92
93 $newValue = $oldValue . '12\ 114\ 115\ 116\ 117\ 1';
94
95 $query = "UPDATE `civicrm_setting` SET `value` = %1 WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'";
96 $params = array(1 => array(serialize($newValue), 'String'));
97 CRM_Core_DAO::executeQuery($query, $params);
98
99 return TRUE;
100 }
101
102 /**
103 * (Queue Task Callback)
104 */
105 static function task_4_5_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
106 $upgrade = new CRM_Upgrade_Form();
107 $upgrade->processSQL($rev);
108
109 return TRUE;
110 }
111
112 /**
113 * Syntactic sugar for adding a task which (a) is in this class and (b) has
114 * a high priority.
115 *
116 * After passing the $funcName, you can also pass parameters that will go to
117 * the function. Note that all params must be serializable.
118 */
119 protected function addTask($title, $funcName) {
120 $queue = CRM_Queue_Service::singleton()->load(array(
121 'type' => 'Sql',
122 'name' => CRM_Upgrade_Form::QUEUE_NAME,
123 ));
124
125 $args = func_get_args();
126 $title = array_shift($args);
127 $funcName = array_shift($args);
128 $task = new CRM_Queue_Task(
129 array(get_class($this), $funcName),
130 $args,
131 $title
132 );
133 $queue->createItem($task, array('weight' => -1));
134 }
135 }