remove never-used option value
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FiveTwentySix.php
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 FiveTwentySix */
14 class CRM_Upgrade_Incremental_php_FiveTwentySix 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.
29 if (!function_exists('civi_wp')) {
30 //exit
31 }
32 elseif ($rev == '5.26.alpha1') {
33 $preUpgradeMessage .= '<br/>' . ts("WARNING: CiviCRM 5.26 and later changes how front-end CiviCRM URLs are formed in WordPress. Please <a href='%1' target='_blank'>read this blog post before upgrading</a> . You may need to update settings at your payment Processor for recurring payments. If you have an external service that sends callback messages to CiviCRM, you may need to update the settings at the external service to use the new URL format.", [
34 1 => 'https://civicrm.org/blog/kcristiano/civicrm-526-and-wordpress-important-notice',
35 ]);
36 }
37 }
38
39 /**
40 * Compute any messages which should be displayed after upgrade.
41 *
42 * @param string $postUpgradeMessage
43 * alterable.
44 * @param string $rev
45 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
46 */
47 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
48 if (!function_exists('civi_wp')) {
49 //exit
50 }
51 elseif ($rev == '5.26.alpha1') {
52 $postUpgradeMessage .= '<br/>' . ts("WARNING: CiviCRM 5.26 and later changes how front-end CiviCRM URLs are formed in WordPress. Please <a href='%1' target='_blank'>read this blog post before upgrading</a> . You may need to update settings at your payment Processor for recurring payments. If you have an external service that sends callback messages to CiviCRM, you may need to update the settings at the external service to use the new URL format.", [
53 1 => 'https://civicrm.org/blog/kcristiano/civicrm-526-and-wordpress-important-notice',
54 ]);
55 }
56 }
57
58 /*
59 * Important! All upgrade functions MUST add a 'runSql' task.
60 * Uncomment and use the following template for a new upgrade version
61 * (change the x in the function name):
62 */
63
64 /**
65 * Upgrade function.
66 *
67 * @param string $rev
68 */
69 public function upgrade_5_26_alpha1($rev) {
70 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
71 $this->addTask('Add option value for nl_BE', 'addNLBEOptionValue');
72 $this->addTask('Add workflow_name to civicrm_msg_template', 'addColumn', 'civicrm_msg_template', 'workflow_name',
73 "VARCHAR(255) DEFAULT NULL COMMENT 'Name of workflow'", FALSE, '5.26.0');
74 $this->addTask('Populate workflow_name in civicrm_msg_template', 'populateWorkflowName');
75
76 // Additional tasks here...
77 // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
78 // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
79 }
80
81 /**
82 * Update workflow_name based on workflow_id values.
83 */
84 public function populateWorkflowName() {
85 CRM_Core_DAO::executeQuery('UPDATE civicrm_msg_template
86 LEFT JOIN civicrm_option_value ov ON ov.id = workflow_id
87 SET workflow_name = ov.name'
88 );
89 return TRUE;
90 }
91
92 /**
93 * Add option value for nl_BE language.
94 *
95 * @param CRM_Queue_TaskContext $ctx
96 */
97 public static function addNLBEOptionValue(CRM_Queue_TaskContext $ctx) {
98 CRM_Core_BAO_OptionValue::ensureOptionValueExists([
99 'option_group_id' => 'languages',
100 'name' => 'nl_BE',
101 'label' => ts('Dutch (Belgium)'),
102 'value' => 'nl',
103 'is_active' => 1,
104 ]);
105 // Update the existing nl_NL entry.
106 $sql = CRM_Utils_SQL::interpolate('UPDATE civicrm_option_value SET label = @newLabel WHERE option_group_id = #group AND name = @name AND label IN (@oldLabels)', [
107 'name' => 'nl_NL',
108 'newLabel' => ts('Dutch (Netherlands)'),
109 // Adding check against old label in case they've customized it, in which
110 // case we don't want to overwrite that. The ts() part is tricky since
111 // it depends if they installed it in English first.
112 'oldLabels' => ['Dutch', ts('Dutch')],
113 'group' => CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_option_group WHERE name = "languages"'),
114 ]);
115 CRM_Core_DAO::executeQuery($sql);
116 return TRUE;
117 }
118
119 }