4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
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 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 string, alterable
60 * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
63 function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
64 if ($rev == '4.1.alpha1') {
65 $postUpgradeMessage .= '<br />' . 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'));
66 $postUpgradeMessage .= '<br />' . 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.');
68 $postUpgradeMessage .= '<br />' . 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.');
70 $postUpgradeMessage .= '<br />' . 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.');
77 function upgrade_4_1_alpha1($rev) {
78 $config = CRM_Core_Config
::singleton();
79 if (in_array('CiviCase', $config->enableComponents
)) {
80 if (!CRM_Case_BAO_Case
::createCaseViews()) {
81 $template = CRM_Core_Smarty
::singleton();
82 $afterUpgradeMessage = '';
83 if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
84 $afterUpgradeMessage .= "<br/><br/>";
86 $afterUpgradeMessage .= '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' . ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:");
87 $afterUpgradeMessage .= '<div class="crm-upgrade-case-views-query"><div>' . CRM_Case_BAO_Case
::createCaseViewsQuery('upcoming') . '</div><div>' . CRM_Case_BAO_Case
::createCaseViewsQuery('recent') . '</div>' . '</div></div>';
88 $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
92 $upgrade = new CRM_Upgrade_Form();
93 $upgrade->processSQL($rev);
96 $this->transferPreferencesToSettings();
97 $this->createNewSettings();
99 // now modify the config so that the directories are now stored in the settings table
102 CRM_Core_BAO_ConfigSetting
::add($params);
104 // also reset navigation
105 CRM_Core_BAO_Navigation
::resetNavigation();
108 function transferPreferencesToSettings() {
109 // first transfer system preferences
110 $domainColumnNames = array(
111 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
112 'contact_view_options',
113 'contact_edit_options',
114 'advanced_search_options',
115 'user_dashboard_options',
119 'display_name_format',
122 'contact_autocomplete_options',
124 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=> array(
125 'address_standardization_provider',
126 'address_standardization_userid',
127 'address_standardization_url',
129 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
136 $userColumnNames = array(
137 self
::NAVIGATION_NAME
=> array(
144 FROM civicrm_preferences
147 $params = array(1 => array(CRM_Core_Config
::domainID(), 'Integer'));
148 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
150 $domainID = CRM_Core_Config
::domainID();
151 $createdDate = date('YmdHis');
153 while ($dao->fetch()) {
154 if ($dao->is_domain
) {
156 foreach ($domainColumnNames as $groupName => $settingNames) {
157 foreach ($settingNames as $settingName) {
158 if (empty($dao->$settingName)) {
162 if ($settingName == 'mailing_backend') {
163 $value = $dao->$settingName;
166 $value = serialize($dao->$settingName);
171 $value = addslashes($value);
173 $value = $value ?
"'{$value}'" : 'null';
174 $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )";
179 // this is a user setting
180 foreach ($userColumnNames as $groupName => $settingNames) {
181 foreach ($settingNames as $settingName) {
182 $value = empty($dao->$settingName) ?
NULL : serialize($dao->$settingName);
185 $value = addslashes($value);
187 $value = $value ?
"'{$value}'" : 'null';
188 $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )";
195 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
199 $sql .= implode(",\n", $values);
200 CRM_Core_DAO
::executeQuery($sql);
202 // now drop the civicrm_preferences table
203 $sql = "DROP TABLE civicrm_preferences";
204 CRM_Core_DAO
::executeQuery($sql);
207 function createNewSettings() {
208 $domainColumns = array(
209 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=>
210 array(array('contact_ajax_check_similar', 1),
211 array('activity_assignee_notification', 1),
213 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=>
214 array(array('tag_unconfirmed', 'Unconfirmed'),
215 array('petition_contacts', 'Petition Contacts'),
217 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=>
218 array(array('enable_cart', 0),
220 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=>
221 array(array('profile_double_optin', 1),
222 array('profile_add_to_group_double_optin', 0),
223 array('track_civimail_replies', 0),
224 array('civimail_workflow', 0),
225 array('civimail_server_wide_lock', 0),
227 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=>
228 array(array('default_renewal_contribution_page', NULL),
230 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=>
231 array(array('is_enabled', 0),
232 array('uniq_email_per_site', 0),
233 array('domain_group_id', 0),
234 array('event_price_set_domain_id', 0),
236 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=>
237 array(array('uploadDir', NULL),
238 array('imageUploadDir', NULL),
239 array('customFileUploadDir', NULL),
240 array('customTemplateDir', NULL),
241 array('customPHPPathDir', NULL),
242 array('extensionsDir', NULL),
244 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=>
245 array(array('userFrameworkResourceURL', NULL),
246 array('imageUploadURL', NULL),
247 array('customCSSURL', NULL),
251 $domainID = CRM_Core_Config
::domainID();
252 $createdDate = date('YmdHis');
254 $dbSettings = array();
255 self
::retrieveDirectoryAndURLPaths($dbSettings);
257 foreach ($domainColumns as $groupName => $settings) {
258 foreach ($settings as $setting) {
260 if (isset($dbSettings[$groupName][$setting[0]]) && !empty($dbSettings[$groupName][$setting[0]])) {
261 $setting[1] = $dbSettings[$groupName][$setting[0]];
264 $value = $setting[1] === NULL ?
NULL : serialize($setting[1]);
267 $value = addslashes($value);
270 $value = $value ?
"'{$value}'" : 'null';
271 $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )";
275 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
278 $sql .= implode(",\n", $values);
279 CRM_Core_DAO
::executeQuery($sql);
283 * @param array $params
285 static function retrieveDirectoryAndURLPaths(&$params) {
288 SELECT v.name as valueName, v.value, g.name as optionName
289 FROM civicrm_option_value v,
290 civicrm_option_group g
291 WHERE ( g.name = 'directory_preferences'
292 OR g.name = 'url_preferences' )
293 AND v.option_group_id = g.id
296 $dao = CRM_Core_DAO
::executeQuery($sql);
297 while ($dao->fetch()) {
302 $groupName = CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
;
303 if ($dao->optionName
== 'url_preferences') {
304 $groupName = CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
;
306 $params[$groupName][$dao->valueName
] = $dao->value
;
313 function upgrade_4_1_alpha2($rev) {
314 $dao = new CRM_Core_DAO_Setting();
315 $dao->group_name
= 'Directory Preferences';
316 $dao->name
= 'customTemplateDir';
317 if (!($dao->find(TRUE))) {
318 $dao->domain_id
= CRM_Core_Config
::domainID();
319 $dao->created_date
= date('YmdHis');
325 // Do the regular upgrade
326 $upgrade = new CRM_Upgrade_Form
;
327 $upgrade->processSQL($rev);
333 function upgrade_4_1_beta1($rev) {
335 $groupNames = array('directory_preferences', 'url_preferences');
336 foreach ($groupNames as $groupName) {
337 CRM_Core_OptionGroup
::deleteAssoc($groupName);
341 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=>
343 'contact_ajax_check_similar',
344 'activity_assignee_notification',
346 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=>
351 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=>
355 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=>
357 'profile_double_optin',
358 'profile_add_to_group_double_optin',
359 'track_civimail_replies',
361 'civimail_server_wide_lock',
363 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=>
365 'default_renewal_contribution_page',
367 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=>
370 'uniq_email_per_site',
372 'event_price_set_domain_id',
374 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=>
378 'customFileUploadDir',
383 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=>
385 'userFrameworkResourceURL',
391 $arrGroupNames = array_keys($domainCols);
392 $groupNames = implode("','", $arrGroupNames);
394 foreach ($domainCols as $groupName => $names) {
395 $arrNames[] = implode("','", $names);
397 $name = implode("','", $arrNames);
400 update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')";
402 CRM_Core_DAO
::executeQuery($sql);
404 $upgrade = new CRM_Upgrade_Form();
405 $upgrade->assign('addWightForActivity', !(CRM_Core_DAO
::checkFieldExists('civicrm_activity', 'weight')));
406 $upgrade->processSQL($rev);
412 function upgrade_4_1_1($rev) {
413 $upgrade = new CRM_Upgrade_Form();
414 $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO
::checkFieldExists('civicrm_mailing', 'dedupe_email')));
416 $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
417 $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO
::singleValueQuery($sql));
419 $upgrade->processSQL($rev);
425 function getTemplateMessage() {