Commit | Line | Data |
---|---|---|
a0f5cb5a C |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | /** | |
13 | * Upgrade logic for FiveTwentyEight */ | |
14 | class CRM_Upgrade_Incremental_php_FiveTwentyEight extends CRM_Upgrade_Incremental_Base { | |
15 | ||
16 | /** | |
17 | * Compute any messages which should be displayed beforeupgrade. | |
18 | * | |
19 | * Note: This function is called iteratively for each upcoming | |
20 | * revision to the database. | |
21 | * | |
22 | * @param string $preUpgradeMessage | |
23 | * @param string $rev | |
24 | * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. | |
25 | * @param null $currentVer | |
26 | */ | |
27 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
28 | // Example: Generate a pre-upgrade message. | |
b449827d KC |
29 | if ($rev == '5.28.alpha1') { |
30 | $preUpgradeMessage .= CRM_Upgrade_Incremental_php_FiveTwentyEight::createWpFilesMessage(); | |
31 | } | |
a0f5cb5a C |
32 | } |
33 | ||
34 | /** | |
35 | * Compute any messages which should be displayed after upgrade. | |
36 | * | |
37 | * @param string $postUpgradeMessage | |
38 | * alterable. | |
39 | * @param string $rev | |
40 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
41 | */ | |
42 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
b449827d KC |
43 | // Example: Generate a pre-upgrade message. |
44 | if ($rev == '5.28.alpha1') { | |
45 | $postUpgradeMessage .= CRM_Upgrade_Incremental_php_FiveTwentyEight::createWpFilesMessage(); | |
46 | } | |
47 | } | |
48 | ||
49 | public static function createWpFilesMessage() { | |
50 | if (!function_exists('civi_wp')) { | |
51 | return ''; | |
52 | } | |
53 | ||
54 | if (isset($GLOBALS['civicrm_paths']['civicrm.files']['path'])) { | |
55 | // They've explicitly chosen to use a non-default path. | |
56 | return ''; | |
57 | } | |
58 | ||
4db100ce TO |
59 | $table = '<table><tbody>' |
60 | . sprintf('<tr><th colspan="2">%s</th></tr>', ts('<b>[civicrm.files]</b> Path')) | |
1c0b0693 ML |
61 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('5.29 Default value:'), wp_upload_dir()['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR) |
62 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('5.28 Default value:'), CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage()['path']) | |
4db100ce TO |
63 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('Active Value:'), Civi::paths()->getVariable('civicrm.files', 'path')) |
64 | . sprintf('<tr><th colspan="2">%s</th></tr>', ts('<b>[civicrm.files]</b> URL')) | |
1c0b0693 ML |
65 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('5.29 Default value:'), wp_upload_dir()['baseurl'] . '/civicrm/') |
66 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('5.28 Default value:'), CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage()['url']) | |
4db100ce TO |
67 | . sprintf('<tr><td>%s</td><td><code>%s</code></td></tr>', ts('Active Value:'), Civi::paths()->getVariable('civicrm.files', 'url')) |
68 | . '</tbody></table>'; | |
69 | ||
1c0b0693 ML |
70 | return '<p>' . ts('Starting with version 5.29.0, CiviCRM on WordPress may make a subtle change in the calculation of <code>[civicrm.files]</code>. To ensure a smooth upgrade, please review the following table. All paths and URLs should appear the same. If there is <strong><em>any</em></strong> discrepancy, then consult <a %1>the upgrade documentation</a>.', [ |
71 | 1 => 'href="https://docs.civicrm.org/sysadmin/en/latest/upgrade/version-specific/#civicrm-5.29" target="_blank"', | |
72 | 2 => '...wp-content/uploads/civicrm', | |
73 | ]) . '</p>' . $table; | |
a0f5cb5a C |
74 | } |
75 | ||
76 | /* | |
77 | * Important! All upgrade functions MUST add a 'runSql' task. | |
78 | * Uncomment and use the following template for a new upgrade version | |
79 | * (change the x in the function name): | |
80 | */ | |
81 | ||
2af06525 CW |
82 | /** |
83 | * Upgrade function. | |
84 | * | |
85 | * @param string $rev | |
86 | */ | |
87 | public function upgrade_5_28_alpha1($rev) { | |
ee1bbc4b | 88 | $this->addTask('Populate missing Contact Type name fields', 'populateMissingContactTypeName'); |
a362acbd | 89 | $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); |
2af06525 CW |
90 | $this->addTask('Add icon column to civicrm_custom_group', 'addColumn', |
91 | 'civicrm_custom_group', 'icon', "varchar(255) COMMENT 'crm-i icon class' DEFAULT NULL"); | |
9bfe43ee | 92 | $this->addTask('Remove index on medium_id from civicrm_activity', 'dropIndex', 'civicrm_activity', 'index_medium_id'); |
2af06525 | 93 | } |
a0f5cb5a | 94 | |
faf0012b | 95 | public static function populateMissingContactTypeName() { |
fe806431 | 96 | $contactTypes = \Civi\Api4\ContactType::get(FALSE) |
faf0012b SL |
97 | ->execute(); |
98 | foreach ($contactTypes as $contactType) { | |
99 | if (empty($contactType['name'])) { | |
100 | \Civi\Api4\ContactType::update() | |
101 | ->addWhere('id', '=', $contactType['id']) | |
102 | ->addValue('name', ucfirst(CRM_Utils_String::munge($contactType['label']))) | |
103 | ->setCheckPermissions(FALSE) | |
104 | ->execute(); | |
105 | } | |
106 | } | |
107 | return TRUE; | |
108 | } | |
109 | ||
a0f5cb5a | 110 | } |