4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License along with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Upgrade_Incremental_php_FourOne
{
36 // This was changed in 4.3 so we define it locally for compatability with older dbs
37 const NAVIGATION_NAME
= "Navigation Menu";
44 public function verifyPreDBstate(&$errors) {
45 $config = CRM_Core_Config
::singleton();
46 if (in_array('CiviCase', $config->enableComponents
)) {
47 if (!CRM_Core_DAO
::checkTriggerViewPermission(TRUE, FALSE)) {
48 $errors[] = ts('CiviCase now requires CREATE VIEW and DROP VIEW permissions for the database user.');
57 * Compute any messages which should be displayed after upgrade
59 * @param $postUpgradeMessage
62 * String, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
66 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
67 if ($rev == '4.1.alpha1') {
68 $postUpgradeMessage .= '<br />' .
69 ts('WARNING! CiviCRM 4.1 introduces an improved way of handling cron jobs. However the new method is NOT backwards compatible. <strong>Please notify your system administrator that all CiviCRM related cron jobs will cease to work, and will need to be re-configured (this includes sending CiviMail mailings, updating membership statuses, etc.).</strong> Refer to the <a href="%1">online documentation</a> for detailed instructions.', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC41/Managing+Scheduled+Jobs'));
70 $postUpgradeMessage .= '<br />' .
71 ts('The CiviCRM Administration menu structure has been re-organized during this upgrade to make it easier to find things and reduce the number of keystrokes. If you have customized this portion of the navigation menu - you should take a few minutes to review the changes. You may need to reimplement or move your customizations.');
73 $postUpgradeMessage .= '<br />' .
74 ts('Yahoo recently discontinued their geocoding and mapping API service. If you previously used Yahoo, you will need to select and configure an alternate service in order to continue using geocoding/mapping tools.');
76 $postUpgradeMessage .= '<br />' .
77 ts('We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.');
84 public function upgrade_4_1_alpha1($rev) {
85 $config = CRM_Core_Config
::singleton();
86 if (in_array('CiviCase', $config->enableComponents
)) {
87 if (!CRM_Case_BAO_Case
::createCaseViews()) {
88 $template = CRM_Core_Smarty
::singleton();
89 $afterUpgradeMessage = '';
90 if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
91 $afterUpgradeMessage .= "<br/><br/>";
93 $afterUpgradeMessage .=
94 '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' .
95 ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:");
96 $afterUpgradeMessage .=
97 '<div class="crm-upgrade-case-views-query"><div>' .
98 CRM_Case_BAO_Case
::createCaseViewsQuery('upcoming') . '</div><div>' .
99 CRM_Case_BAO_Case
::createCaseViewsQuery('recent') . '</div>' .
101 $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
105 $upgrade = new CRM_Upgrade_Form();
106 $upgrade->processSQL($rev);
108 $this->transferPreferencesToSettings();
109 $this->createNewSettings();
111 // now modify the config so that the directories are now stored in the settings table
114 CRM_Core_BAO_ConfigSetting
::add($params);
116 // also reset navigation
117 CRM_Core_BAO_Navigation
::resetNavigation();
120 public function transferPreferencesToSettings() {
121 // first transfer system preferences
122 $domainColumnNames = array(
123 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
124 'contact_view_options',
125 'contact_edit_options',
126 'advanced_search_options',
127 'user_dashboard_options',
131 'display_name_format',
134 'contact_autocomplete_options',
136 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=> array(
137 'address_standardization_provider',
138 'address_standardization_userid',
139 'address_standardization_url',
141 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
146 $userColumnNames = array(
147 self
::NAVIGATION_NAME
=> array(
154 FROM civicrm_preferences
157 $params = array(1 => array(CRM_Core_Config
::domainID(), 'Integer'));
158 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
160 $domainID = CRM_Core_Config
::domainID();
161 $createdDate = date('YmdHis');
163 while ($dao->fetch()) {
164 if ($dao->is_domain
) {
166 foreach ($domainColumnNames as $groupName => $settingNames) {
167 foreach ($settingNames as $settingName) {
168 if (empty($dao->$settingName)) {
172 if ($settingName == 'mailing_backend') {
173 $value = $dao->$settingName;
176 $value = serialize($dao->$settingName);
181 $value = addslashes($value);
183 $value = $value ?
"'{$value}'" : 'null';
184 $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )";
189 // this is a user setting
190 foreach ($userColumnNames as $groupName => $settingNames) {
191 foreach ($settingNames as $settingName) {
192 $value = empty($dao->$settingName) ?
NULL : serialize($dao->$settingName);
195 $value = addslashes($value);
197 $value = $value ?
"'{$value}'" : 'null';
198 $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )";
205 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
209 $sql .= implode(",\n", $values);
210 CRM_Core_DAO
::executeQuery($sql);
212 // now drop the civicrm_preferences table
213 $sql = "DROP TABLE civicrm_preferences";
214 CRM_Core_DAO
::executeQuery($sql);
217 public function createNewSettings() {
218 $domainColumns = array(
219 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
220 array('contact_ajax_check_similar', 1),
221 array('activity_assignee_notification', 1),
223 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=> array(
224 array('tag_unconfirmed', 'Unconfirmed'),
225 array('petition_contacts', 'Petition Contacts'),
227 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=> array(
228 array('enable_cart', 0),
230 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
231 array('profile_double_optin', 1),
232 array('profile_add_to_group_double_optin', 0),
233 array('track_civimail_replies', 0),
234 array('civimail_workflow', 0),
235 array('civimail_server_wide_lock', 0),
237 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=> array(
238 array('default_renewal_contribution_page', NULL),
240 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=> array(
241 array('is_enabled', 0),
242 array('uniq_email_per_site', 0),
243 array('domain_group_id', 0),
244 array('event_price_set_domain_id', 0),
246 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=> array(
247 array('uploadDir', NULL),
248 array('imageUploadDir', NULL),
249 array('customFileUploadDir', NULL),
250 array('customTemplateDir', NULL),
251 array('customPHPPathDir', NULL),
252 array('extensionsDir', NULL),
254 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=> array(
255 array('userFrameworkResourceURL', NULL),
256 array('imageUploadURL', NULL),
257 array('customCSSURL', NULL),
261 $domainID = CRM_Core_Config
::domainID();
262 $createdDate = date('YmdHis');
264 $dbSettings = array();
265 self
::retrieveDirectoryAndURLPaths($dbSettings);
267 foreach ($domainColumns as $groupName => $settings) {
268 foreach ($settings as $setting) {
270 if (isset($dbSettings[$groupName][$setting[0]]) &&
271 !empty($dbSettings[$groupName][$setting[0]])
273 $setting[1] = $dbSettings[$groupName][$setting[0]];
276 $value = $setting[1] === NULL ?
NULL : serialize($setting[1]);
279 $value = addslashes($value);
282 $value = $value ?
"'{$value}'" : 'null';
283 $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )";
287 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
290 $sql .= implode(",\n", $values);
291 CRM_Core_DAO
::executeQuery($sql);
295 * @param array $params
297 public static function retrieveDirectoryAndURLPaths(&$params) {
300 SELECT v.name as valueName, v.value, g.name as optionName
301 FROM civicrm_option_value v,
302 civicrm_option_group g
303 WHERE ( g.name = 'directory_preferences'
304 OR g.name = 'url_preferences' )
305 AND v.option_group_id = g.id
308 $dao = CRM_Core_DAO
::executeQuery($sql);
309 while ($dao->fetch()) {
314 $groupName = CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
;
315 if ($dao->optionName
== 'url_preferences') {
316 $groupName = CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
;
318 $params[$groupName][$dao->valueName
] = $dao->value
;
325 public function upgrade_4_1_alpha2($rev) {
326 $dao = new CRM_Core_DAO_Setting();
327 $dao->group_name
= 'Directory Preferences';
328 $dao->name
= 'customTemplateDir';
329 if (!($dao->find(TRUE))) {
330 $dao->domain_id
= CRM_Core_Config
::domainID();
331 $dao->created_date
= date('YmdHis');
337 // Do the regular upgrade
338 $upgrade = new CRM_Upgrade_Form
;
339 $upgrade->processSQL($rev);
345 public function upgrade_4_1_beta1($rev) {
347 $groupNames = array('directory_preferences', 'url_preferences');
348 foreach ($groupNames as $groupName) {
349 CRM_Core_OptionGroup
::deleteAssoc($groupName);
353 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
354 'contact_ajax_check_similar',
355 'activity_assignee_notification',
357 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=> array(
361 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=> array(
364 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
365 'profile_double_optin',
366 'profile_add_to_group_double_optin',
367 'track_civimail_replies',
369 'civimail_server_wide_lock',
371 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=> array(
372 'default_renewal_contribution_page',
374 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=> array(
376 'uniq_email_per_site',
378 'event_price_set_domain_id',
380 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=> array(
383 'customFileUploadDir',
388 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=> array(
389 'userFrameworkResourceURL',
395 $arrGroupNames = array_keys($domainCols);
396 $groupNames = implode("','", $arrGroupNames);
398 foreach ($domainCols as $groupName => $names) {
399 $arrNames[] = implode("','", $names);
401 $name = implode("','", $arrNames);
404 update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')";
406 CRM_Core_DAO
::executeQuery($sql);
408 $upgrade = new CRM_Upgrade_Form();
409 $upgrade->assign('addWightForActivity', !(CRM_Core_DAO
::checkFieldExists('civicrm_activity', 'weight')));
410 $upgrade->processSQL($rev);
416 public function upgrade_4_1_1($rev) {
417 $upgrade = new CRM_Upgrade_Form();
418 $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO
::checkFieldExists('civicrm_mailing', 'dedupe_email')));
420 $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
421 $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO
::singleValueQuery($sql));
423 $upgrade->processSQL($rev);
429 public function getTemplateMessage() {