4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Upgrade_Incremental_php_FourOne
{
36 function verifyPreDBstate(&$errors) {
37 $config = CRM_Core_Config
::singleton();
38 if (in_array('CiviCase', $config->enableComponents
)) {
39 if (!CRM_Core_DAO
::checkTriggerViewPermission(TRUE, FALSE)) {
40 $errors[] = ts('CiviCase now requires CREATE VIEW and DROP VIEW permissions for the database user.');
49 * Compute any messages which should be displayed after upgrade
51 * @param $postUpgradeMessage string, alterable
52 * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
55 function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
56 if ($rev == '4.1.alpha1') {
57 $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'));
58 $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.');
60 $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.');
62 $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.');
66 function upgrade_4_1_alpha1($rev) {
67 $config = CRM_Core_Config
::singleton();
68 if (in_array('CiviCase', $config->enableComponents
)) {
69 if (!CRM_Case_BAO_Case
::createCaseViews()) {
70 $template = CRM_Core_Smarty
::singleton();
71 $afterUpgradeMessage = '';
72 if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
73 $afterUpgradeMessage .= "<br/><br/>";
75 $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:");
76 $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>';
77 $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
81 $upgrade = new CRM_Upgrade_Form();
82 $upgrade->processSQL($rev);
85 $this->transferPreferencesToSettings();
86 $this->createNewSettings();
88 // now modify the config so that the directories are now stored in the settings table
91 CRM_Core_BAO_ConfigSetting
::add($params);
93 // also reset navigation
94 CRM_Core_BAO_Navigation
::resetNavigation();
97 function transferPreferencesToSettings() {
98 // first transfer system preferences
99 $domainColumnNames = array(
100 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=> array(
101 'contact_view_options',
102 'contact_edit_options',
103 'advanced_search_options',
104 'user_dashboard_options',
108 'display_name_format',
111 'contact_autocomplete_options',
113 CRM_Core_BAO_Setting
::ADDRESS_STANDARDIZATION_PREFERENCES_NAME
=> array(
114 'address_standardization_provider',
115 'address_standardization_userid',
116 'address_standardization_url',
118 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=> array(
125 $userColumnNames = array(
126 CRM_Core_BAO_Setting
::NAVIGATION_NAME
=> array(
133 FROM civicrm_preferences
136 $params = array(1 => array(CRM_Core_Config
::domainID(), 'Integer'));
137 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
139 $domainID = CRM_Core_Config
::domainID();
140 $createdDate = date('YmdHis');
142 while ($dao->fetch()) {
143 if ($dao->is_domain
) {
145 foreach ($domainColumnNames as $groupName => $settingNames) {
146 foreach ($settingNames as $settingName) {
147 if (empty($dao->$settingName)) {
151 if ($settingName == 'mailing_backend') {
152 $value = $dao->$settingName;
155 $value = serialize($dao->$settingName);
160 $value = addslashes($value);
162 $value = $value ?
"'{$value}'" : 'null';
163 $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )";
168 // this is a user setting
169 foreach ($userColumnNames as $groupName => $settingNames) {
170 foreach ($settingNames as $settingName) {
171 $value = empty($dao->$settingName) ?
NULL : serialize($dao->$settingName);
174 $value = addslashes($value);
176 $value = $value ?
"'{$value}'" : 'null';
177 $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )";
184 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
188 $sql .= implode(",\n", $values);
189 CRM_Core_DAO
::executeQuery($sql);
191 // now drop the civicrm_preferences table
192 $sql = "DROP TABLE civicrm_preferences";
193 CRM_Core_DAO
::executeQuery($sql);
196 function createNewSettings() {
197 $domainColumns = array(
198 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=>
199 array(array('contact_ajax_check_similar', 1),
200 array('activity_assignee_notification', 1),
202 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=>
203 array(array('tag_unconfirmed', 'Unconfirmed'),
204 array('petition_contacts', 'Petition Contacts'),
206 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=>
207 array(array('enable_cart', 0),
209 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=>
210 array(array('profile_double_optin', 1),
211 array('profile_add_to_group_double_optin', 0),
212 array('track_civimail_replies', 0),
213 array('civimail_workflow', 0),
214 array('civimail_server_wide_lock', 0),
216 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=>
217 array(array('default_renewal_contribution_page', NULL),
219 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=>
220 array(array('is_enabled', 0),
221 array('uniq_email_per_site', 0),
222 array('domain_group_id', 0),
223 array('event_price_set_domain_id', 0),
225 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=>
226 array(array('uploadDir', NULL),
227 array('imageUploadDir', NULL),
228 array('customFileUploadDir', NULL),
229 array('customTemplateDir', NULL),
230 array('customPHPPathDir', NULL),
231 array('extensionsDir', NULL),
233 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=>
234 array(array('userFrameworkResourceURL', NULL),
235 array('imageUploadURL', NULL),
236 array('customCSSURL', NULL),
240 $domainID = CRM_Core_Config
::domainID();
241 $createdDate = date('YmdHis');
243 $dbSettings = array();
244 self
::retrieveDirectoryAndURLPaths($dbSettings);
246 foreach ($domainColumns as $groupName => $settings) {
247 foreach ($settings as $setting) {
249 if (isset($dbSettings[$groupName][$setting[0]]) && !empty($dbSettings[$groupName][$setting[0]])) {
250 $setting[1] = $dbSettings[$groupName][$setting[0]];
253 $value = $setting[1] === NULL ?
NULL : serialize($setting[1]);
256 $value = addslashes($value);
259 $value = $value ?
"'{$value}'" : 'null';
260 $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )";
264 INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id )
267 $sql .= implode(",\n", $values);
268 CRM_Core_DAO
::executeQuery($sql);
271 static function retrieveDirectoryAndURLPaths(&$params) {
274 SELECT v.name as valueName, v.value, g.name as optionName
275 FROM civicrm_option_value v,
276 civicrm_option_group g
277 WHERE ( g.name = 'directory_preferences'
278 OR g.name = 'url_preferences' )
279 AND v.option_group_id = g.id
282 $dao = CRM_Core_DAO
::executeQuery($sql);
283 while ($dao->fetch()) {
288 $groupName = CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
;
289 if ($dao->optionName
== 'url_preferences') {
290 $groupName = CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
;
292 $params[$groupName][$dao->valueName
] = $dao->value
;
296 function upgrade_4_1_alpha2($rev) {
297 $dao = new CRM_Core_DAO_Setting();
298 $dao->group_name
= 'Directory Preferences';
299 $dao->name
= 'customTemplateDir';
300 if (!($dao->find(TRUE))) {
301 $dao->domain_id
= CRM_Core_Config
::domainID();
302 $dao->created_date
= date('YmdHis');
308 // Do the regular upgrade
309 $upgrade = new CRM_Upgrade_Form
;
310 $upgrade->processSQL($rev);
313 function upgrade_4_1_beta1($rev) {
315 $groupNames = array('directory_preferences', 'url_preferences');
316 foreach ($groupNames as $groupName) {
317 CRM_Core_OptionGroup
::deleteAssoc($groupName);
321 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
=>
323 'contact_ajax_check_similar',
324 'activity_assignee_notification',
326 CRM_Core_BAO_Setting
::CAMPAIGN_PREFERENCES_NAME
=>
331 CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
=>
335 CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
=>
337 'profile_double_optin',
338 'profile_add_to_group_double_optin',
339 'track_civimail_replies',
341 'civimail_server_wide_lock',
343 CRM_Core_BAO_Setting
::MEMBER_PREFERENCES_NAME
=>
345 'default_renewal_contribution_page',
347 CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
=>
350 'uniq_email_per_site',
352 'event_price_set_domain_id',
354 CRM_Core_BAO_Setting
::DIRECTORY_PREFERENCES_NAME
=>
358 'customFileUploadDir',
363 CRM_Core_BAO_Setting
::URL_PREFERENCES_NAME
=>
365 'userFrameworkResourceURL',
371 $arrGroupNames = array_keys($domainCols);
372 $groupNames = implode("','", $arrGroupNames);
374 foreach ($domainCols as $groupName => $names) {
375 $arrNames[] = implode("','", $names);
377 $name = implode("','", $arrNames);
380 update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')";
382 CRM_Core_DAO
::executeQuery($sql);
384 $upgrade = new CRM_Upgrade_Form();
385 $upgrade->assign('addWightForActivity', !(CRM_Core_DAO
::checkFieldExists('civicrm_activity', 'weight')));
386 $upgrade->processSQL($rev);
389 function upgrade_4_1_1($rev) {
390 $upgrade = new CRM_Upgrade_Form();
391 $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO
::checkFieldExists('civicrm_mailing', 'dedupe_email')));
393 $sql = "SELECT id FROM civicrm_worldregion LIMIT 1";
394 $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO
::singleValueQuery($sql));
396 $upgrade->processSQL($rev);
399 function getTemplateMessage() {