3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
34 class CRM_Upgrade_Incremental_php_FourOne
{
35 // This was changed in 4.3 so we define it locally for compatability with older dbs
36 const NAVIGATION_NAME
= "Navigation Menu";
43 public function verifyPreDBstate(&$errors) {
44 $config = CRM_Core_Config
::singleton();
45 if (in_array('CiviCase', $config->enableComponents
)) {
46 if (!CRM_Core_DAO
::checkTriggerViewPermission(TRUE, FALSE)) {
47 $errors[] = ts('CiviCase now requires CREATE VIEW and DROP VIEW permissions for the database user.');
56 * Compute any messages which should be displayed after upgrade.
58 * @param string $postUpgradeMessage
61 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
65 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
66 if ($rev == '4.1.alpha1') {
67 $postUpgradeMessage .= '<br />' .
68 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'));
69 $postUpgradeMessage .= '<br />' .
70 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.');
72 $postUpgradeMessage .= '<br />' .
73 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.');
75 $postUpgradeMessage .= '<br />' .
76 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.');
83 public function upgrade_4_1_alpha1($rev) {
84 $config = CRM_Core_Config
::singleton();
85 if (in_array('CiviCase', $config->enableComponents
)) {
86 if (!CRM_Case_BAO_Case
::createCaseViews()) {
87 $template = CRM_Core_Smarty
::singleton();
88 $afterUpgradeMessage = '';
89 if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
90 $afterUpgradeMessage .= "<br/><br/>";
92 $afterUpgradeMessage .=
93 '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' .
94 ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:");
95 $afterUpgradeMessage .=
96 '<div class="crm-upgrade-case-views-query"><div>' .
97 CRM_Case_BAO_Case
::createCaseViewsQuery('upcoming') . '</div><div>' .
98 CRM_Case_BAO_Case
::createCaseViewsQuery('recent') . '</div>' .
100 $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
104 $upgrade = new CRM_Upgrade_Form();
105 $upgrade->processSQL($rev);
107 $this->transferPreferencesToSettings();
108 $this->createNewSettings();
110 // now modify the config so that the directories are now stored in the settings table
113 CRM_Core_BAO_ConfigSetting
::add($params);
115 // also reset navigation
116 CRM_Core_BAO_Navigation
::resetNavigation();
119 public function transferPreferencesToSettings() {
120 // first transfer system preferences
121 $domainColumnNames = array(
122 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
123 'contact_view_options',
124 'contact_edit_options',
125 'advanced_search_options',
126 'user_dashboard_options',
130 'display_name_format',
133 'contact_autocomplete_options',
135 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=> array(
136 'address_standardization_provider',
137 'address_standardization_userid',
138 'address_standardization_url',
140 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
145 $userColumnNames = array(
146 self
::NAVIGATION_NAME
=> array(
153 FROM civicrm_preferences
156 $params = array(1 => array(CRM_Core_Config
::domainID(), 'Integer'));
157 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
159 $domainID = CRM_Core_Config
::domainID();
160 $createdDate = date('YmdHis');
162 while ($dao->fetch()) {
163 if ($dao->is_domain
) {
165 foreach ($domainColumnNames as $groupName => $settingNames) {
166 foreach ($settingNames as $settingName) {
167 if (empty($dao->$settingName)) {
171 if ($settingName == 'mailing_backend') {
172 $value = $dao->$settingName;
175 $value = serialize($dao->$settingName);
180 $value = addslashes($value);
182 $value = $value ?
"'{$value}'" : 'null';
183 $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )";
188 // this is a user setting
189 foreach ($userColumnNames as $groupName => $settingNames) {
190 foreach ($settingNames as $settingName) {
191 $value = empty($dao->$settingName) ?
NULL : serialize($dao->$settingName);
194 $value = addslashes($value);
196 $value = $value ?
"'{$value}'" : 'null';
197 $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )";
204 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
208 $sql .= implode(",\n", $values);
209 CRM_Core_DAO
::executeQuery($sql);
211 // now drop the civicrm_preferences table
212 $sql = "DROP TABLE civicrm_preferences";
213 CRM_Core_DAO
::executeQuery($sql);
216 public function createNewSettings() {
217 $domainColumns = array(
218 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
219 array('contact_ajax_check_similar', 1),
220 array('activity_assignee_notification', 1),
222 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=> array(
223 array('tag_unconfirmed', 'Unconfirmed'),
224 array('petition_contacts', 'Petition Contacts'),
226 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=> array(
227 array('enable_cart', 0),
229 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
230 array('profile_double_optin', 1),
231 array('profile_add_to_group_double_optin', 0),
232 array('track_civimail_replies', 0),
233 array('civimail_workflow', 0),
234 array('civimail_server_wide_lock', 0),
236 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=> array(
237 array('default_renewal_contribution_page', NULL),
239 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=> array(
240 array('is_enabled', 0),
241 array('uniq_email_per_site', 0),
242 array('domain_group_id', 0),
243 array('event_price_set_domain_id', 0),
245 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=> array(
246 array('uploadDir', NULL),
247 array('imageUploadDir', NULL),
248 array('customFileUploadDir', NULL),
249 array('customTemplateDir', NULL),
250 array('customPHPPathDir', NULL),
251 array('extensionsDir', NULL),
253 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=> array(
254 array('userFrameworkResourceURL', NULL),
255 array('imageUploadURL', NULL),
256 array('customCSSURL', NULL),
260 $domainID = CRM_Core_Config
::domainID();
261 $createdDate = date('YmdHis');
263 $dbSettings = array();
264 self
::retrieveDirectoryAndURLPaths($dbSettings);
266 foreach ($domainColumns as $groupName => $settings) {
267 foreach ($settings as $setting) {
269 if (isset($dbSettings[$groupName][$setting[0]]) &&
270 !empty($dbSettings[$groupName][$setting[0]])
272 $setting[1] = $dbSettings[$groupName][$setting[0]];
275 $value = $setting[1] === NULL ?
NULL : serialize($setting[1]);
278 $value = addslashes($value);
281 $value = $value ?
"'{$value}'" : 'null';
282 $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )";
286 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
289 $sql .= implode(",\n", $values);
290 CRM_Core_DAO
::executeQuery($sql);
294 * @param array $params
296 public static function retrieveDirectoryAndURLPaths(&$params) {
299 SELECT v.name as valueName, v.value, g.name as optionName
300 FROM civicrm_option_value v,
301 civicrm_option_group g
302 WHERE ( g.name = 'directory_preferences'
303 OR g.name = 'url_preferences' )
304 AND v.option_group_id = g.id
307 $dao = CRM_Core_DAO
::executeQuery($sql);
308 while ($dao->fetch()) {
313 $groupName = CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
;
314 if ($dao->optionName
== 'url_preferences') {
315 $groupName = CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
;
317 $params[$groupName][$dao->valueName
] = $dao->value
;
324 public function upgrade_4_1_alpha2($rev) {
325 $dao = new CRM_Core_DAO_Setting();
326 $dao->group_name
= 'Directory Preferences';
327 $dao->name
= 'customTemplateDir';
328 if (!($dao->find(TRUE))) {
329 $dao->domain_id
= CRM_Core_Config
::domainID();
330 $dao->created_date
= date('YmdHis');
336 // Do the regular upgrade
337 $upgrade = new CRM_Upgrade_Form();
338 $upgrade->processSQL($rev);
344 public function upgrade_4_1_beta1($rev) {
346 $groupNames = array('directory_preferences', 'url_preferences');
347 foreach ($groupNames as $groupName) {
348 CRM_Core_OptionGroup
::deleteAssoc($groupName);
352 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
353 'contact_ajax_check_similar',
354 'activity_assignee_notification',
356 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=> array(
360 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=> array(
363 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
364 'profile_double_optin',
365 'profile_add_to_group_double_optin',
366 'track_civimail_replies',
368 'civimail_server_wide_lock',
370 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=> array(
371 'default_renewal_contribution_page',
373 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=> array(
375 'uniq_email_per_site',
377 'event_price_set_domain_id',
379 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=> array(
382 'customFileUploadDir',
387 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=> array(
388 'userFrameworkResourceURL',
394 $arrGroupNames = array_keys($domainCols);
395 $groupNames = implode("','", $arrGroupNames);
397 foreach ($domainCols as $groupName => $names) {
398 $arrNames[] = implode("','", $names);
400 $name = implode("','", $arrNames);
403 update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')";
405 CRM_Core_DAO
::executeQuery($sql);
407 $upgrade = new CRM_Upgrade_Form();
408 $upgrade->assign('addWightForActivity', !(CRM_Core_DAO
::checkFieldExists('civicrm_activity', 'weight')));
409 $upgrade->processSQL($rev);
415 public function upgrade_4_1_1($rev) {
416 $upgrade = new CRM_Upgrade_Form();
417 $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO
::checkFieldExists('civicrm_mailing', 'dedupe_email')));
419 $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
420 $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO
::singleValueQuery($sql));
422 $upgrade->processSQL($rev);
428 public function getTemplateMessage() {