Commit | Line | Data |
---|---|---|
296342b1 OB |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
296342b1 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
296342b1 OB |
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 | |
06b69b18 | 30 | * @copyright CiviCRM LLC (c) 2004-2014 |
296342b1 OB |
31 | * $Id$ |
32 | * | |
33 | */ | |
34 | class CRM_Upgrade_Incremental_php_FourFive { | |
35 | const BATCH_SIZE = 5000; | |
36 | ||
624e56fa EM |
37 | /** |
38 | * @param $errors | |
39 | * | |
40 | * @return bool | |
41 | */ | |
296342b1 OB |
42 | function verifyPreDBstate(&$errors) { |
43 | return TRUE; | |
44 | } | |
45 | ||
46 | /** | |
47 | * Compute any messages which should be displayed beforeupgrade | |
48 | * | |
49 | * Note: This function is called iteratively for each upcoming | |
50 | * revision to the database. | |
51 | * | |
d0f74b53 | 52 | * @param $preUpgradeMessage |
296342b1 | 53 | * @param $rev string, a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0' |
d0f74b53 EM |
54 | * @param null $currentVer |
55 | * | |
56 | * @internal param string $postUpgradeMessage , alterable | |
296342b1 OB |
57 | * @return void |
58 | */ | |
59 | function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
60 | } | |
61 | ||
62 | /** | |
63 | * Compute any messages which should be displayed after upgrade | |
64 | * | |
65 | * @param $postUpgradeMessage string, alterable | |
66 | * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs | |
67 | * @return void | |
68 | */ | |
69 | function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
1421174e | 70 | if ($rev == '4.5.alpha1') { |
9a1a1aad | 71 | $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). (<a href="%1">learn more...</a>)', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Updating+System+Workflow+Message+Templates+after+Upgrades+-+method+1+-+kdiff')); |
b05a0fb6 | 72 | $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".'); |
03390e26 | 73 | $postUpgradeMessage .= '<br /><br />' . ts('This release changes the way that anonymous event registrations match participants with existing contacts. By default, all event participants will be matched with existing individuals using the Unsupervised rule, even if multiple registrations with the same email address are allowed. However, you can now select a different matching rule to use for each event. Please review your events to make sure you choose the appropriate matching rule and collect sufficient information for it to match contacts.'); |
1421174e | 74 | } |
296342b1 OB |
75 | } |
76 | ||
624e56fa EM |
77 | /** |
78 | * @param $rev | |
79 | * | |
80 | * @return bool | |
81 | */ | |
296342b1 OB |
82 | function upgrade_4_5_alpha1($rev) { |
83 | // task to process sql | |
3182e644 | 84 | $this->addTask(ts('Migrate honoree information to module_data'), 'migrateHonoreeInfo'); |
296342b1 | 85 | $this->addTask(ts('Upgrade DB to 4.5.alpha1: SQL'), 'task_4_5_x_runSql', $rev); |
8b49cb50 OB |
86 | $this->addTask(ts('Set default for Individual name fields configuration'), 'addNameFieldOptions'); |
87 | ||
64542f7e PJ |
88 | // CRM-14522 - The below schema checking is done as foreign key name |
89 | // for pdf_format_id column varies for different databases | |
90 | // if DB is been into upgrade for 3.4.2 version, it would have pdf_format_id name for FK | |
91 | // else FK_civicrm_msg_template_pdf_format_id | |
92 | $config = CRM_Core_Config::singleton(); | |
93 | $dbUf = DB::parseDSN($config->dsn); | |
94 | $query = " | |
95 | SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS | |
96 | WHERE TABLE_NAME = 'civicrm_msg_template' | |
97 | AND CONSTRAINT_TYPE = 'FOREIGN KEY' | |
98 | AND TABLE_SCHEMA = %1 | |
99 | "; | |
100 | $params = array(1 => array($dbUf['database'], 'String')); | |
101 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, NULL, FALSE, FALSE); | |
102 | if ($dao->fetch()) { | |
103 | if ($dao->CONSTRAINT_NAME == 'FK_civicrm_msg_template_pdf_format_id' || | |
104 | $dao->CONSTRAINT_NAME == 'pdf_format_id') { | |
105 | $sqlDropFK = "ALTER TABLE `civicrm_msg_template` | |
106 | DROP FOREIGN KEY `{$dao->CONSTRAINT_NAME}`, | |
107 | DROP KEY `{$dao->CONSTRAINT_NAME}`"; | |
108 | CRM_Core_DAO::executeQuery($sqlDropFK, CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE); | |
109 | } | |
110 | } | |
111 | ||
8b49cb50 OB |
112 | return TRUE; |
113 | } | |
114 | ||
115 | /** | |
116 | * Add defaults for the newly introduced name fields configuration in 'contact_edit_options' setting | |
117 | * | |
d0f74b53 EM |
118 | * @param CRM_Queue_TaskContext $ctx |
119 | * | |
8b49cb50 OB |
120 | * @return bool TRUE for success |
121 | */ | |
122 | static function addNameFieldOptions(CRM_Queue_TaskContext $ctx) { | |
123 | $query = "SELECT `value` FROM `civicrm_setting` WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'"; | |
124 | $dao = CRM_Core_DAO::executeQuery($query); | |
125 | $dao->fetch(); | |
126 | $oldValue = unserialize($dao->value); | |
127 | ||
128 | $newValue = $oldValue . '12\ 114\ 115\ 116\ 117\ 1'; | |
129 | ||
130 | $query = "UPDATE `civicrm_setting` SET `value` = %1 WHERE `group_name` = 'CiviCRM Preferences' AND `name` = 'contact_edit_options'"; | |
131 | $params = array(1 => array(serialize($newValue), 'String')); | |
132 | CRM_Core_DAO::executeQuery($query, $params); | |
133 | ||
296342b1 OB |
134 | return TRUE; |
135 | } | |
136 | ||
3182e644 | 137 | /** |
138 | * Migrate honoree information to uf_join.module_data as honoree columns (text and title) will be dropped | |
139 | * on DB upgrade | |
140 | * | |
141 | * @param CRM_Queue_TaskContext $ctx | |
142 | * | |
143 | * @return bool TRUE for success | |
144 | */ | |
145 | static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx) { | |
146 | $query = "ALTER TABLE `civicrm_uf_join` | |
147 | ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'"; | |
148 | CRM_Core_DAO::executeQuery($query); | |
149 | ||
150 | $honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type')); | |
151 | $ufGroupDAO = new CRM_Core_DAO_UFGroup(); | |
152 | $ufGroupDAO->name = 'new_individual'; | |
153 | $ufGroupDAO->find(TRUE); | |
154 | ||
155 | $query = "SELECT * FROM civicrm_contribution_page"; | |
156 | $dao = CRM_Core_DAO::executeQuery($query); | |
157 | ||
158 | if ($dao->N) { | |
159 | $domain = new CRM_Core_DAO_Domain; | |
160 | $domain->find(TRUE); | |
161 | while ($dao->fetch()) { | |
162 | $honorParams = array('soft_credit' => array('soft_credit_types' => $honorTypes)); | |
163 | if ($domain->locales) { | |
164 | $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); | |
165 | foreach ($locales as $locale) { | |
166 | $honor_block_title = "honor_block_title_{$locale}"; | |
167 | $honor_block_text = "honor_block_text_{$locale}"; | |
168 | $honorParams['soft_credit'] += array( | |
169 | $locale => array( | |
170 | 'honor_block_title' => $dao->$honor_block_title, | |
171 | 'honor_block_text' => $dao->$honor_block_text, | |
172 | ), | |
173 | ); | |
174 | } | |
175 | } | |
176 | else { | |
177 | $honorParams['soft_credit'] += array( | |
178 | 'default' => array( | |
179 | 'honor_block_title' => $dao->honor_block_title, | |
180 | 'honor_block_text' => $dao->honor_block_text, | |
181 | ), | |
182 | ); | |
183 | } | |
184 | $ufJoinParam = array( | |
185 | 'module' => 'soft_credit', | |
186 | 'entity_table' => 'civicrm_contribution_page', | |
187 | 'is_active' => $dao->honor_block_is_active, | |
188 | 'entity_id' => $dao->id, | |
189 | 'uf_group_id' => $ufGroupDAO->id, | |
190 | 'module_data' => json_encode($honorParams), | |
191 | ); | |
192 | CRM_Core_BAO_UFJoin::create($ufJoinParam); | |
193 | } | |
194 | } | |
195 | ||
196 | return TRUE; | |
197 | } | |
198 | ||
296342b1 OB |
199 | /** |
200 | * (Queue Task Callback) | |
201 | */ | |
202 | static function task_4_5_x_runSql(CRM_Queue_TaskContext $ctx, $rev) { | |
203 | $upgrade = new CRM_Upgrade_Form(); | |
204 | $upgrade->processSQL($rev); | |
205 | ||
206 | return TRUE; | |
207 | } | |
208 | ||
209 | /** | |
d0f74b53 | 210 | * Syntactic sugar for adding a task which (a) is in this class and (b) has |
296342b1 OB |
211 | * a high priority. |
212 | * | |
213 | * After passing the $funcName, you can also pass parameters that will go to | |
214 | * the function. Note that all params must be serializable. | |
215 | */ | |
216 | protected function addTask($title, $funcName) { | |
217 | $queue = CRM_Queue_Service::singleton()->load(array( | |
218 | 'type' => 'Sql', | |
219 | 'name' => CRM_Upgrade_Form::QUEUE_NAME, | |
220 | )); | |
221 | ||
222 | $args = func_get_args(); | |
223 | $title = array_shift($args); | |
224 | $funcName = array_shift($args); | |
225 | $task = new CRM_Queue_Task( | |
226 | array(get_class($this), $funcName), | |
227 | $args, | |
228 | $title | |
229 | ); | |
230 | $queue->createItem($task, array('weight' => -1)); | |
231 | } | |
232 | } |