remove never-used option value
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FiveTwentyNine.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 FiveTwentyNine */
14 class CRM_Upgrade_Incremental_php_FiveTwentyNine 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 if ($rev == '5.29.beta1') {
29 if (CIVICRM_UF === 'Drupal8') {
30 $preUpgradeMessage .= '<p>' . ts('<em>Pre-announcement for upcoming version 5.30</em>: If your composer configuration or composer.json does not enable patching, you MUST do that BEFORE running composer to update your files to version 5.30. Either by using `composer config \'extra.enable-patching\' true`, or updating the top level composer.json\'s extra section with `"enable-patching": true`. See %1 for details.', [1 => '<a href="' . CRM_Utils_System::docURL2('installation/drupal8', TRUE) . '">Drupal 8 installation guide</a>']) . '</p>';
31 }
32 }
33 }
34
35 /**
36 * Compute any messages which should be displayed after upgrade.
37 *
38 * @param string $postUpgradeMessage
39 * alterable.
40 * @param string $rev
41 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
42 */
43 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
44 // Example: Generate a post-upgrade message.
45 // if ($rev == '5.12.34') {
46 // $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
47 // }
48 }
49
50 /*
51 * Important! All upgrade functions MUST add a 'runSql' task.
52 * Uncomment and use the following template for a new upgrade version
53 * (change the x in the function name):
54 */
55
56 /**
57 * Upgrade function.
58 *
59 * @param string $rev
60 */
61 public function upgrade_5_29_alpha1($rev) {
62 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
63 $this->addTask('Install eventcart extension', 'installEventCart');
64
65 list($minId, $maxId) = CRM_Core_DAO::executeQuery("SELECT coalesce(min(id),0), coalesce(max(id),0)
66 FROM civicrm_relationship ")->getDatabaseResult()->fetchRow();
67 for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
68 $endId = $startId + self::BATCH_SIZE - 1;
69 $title = ts("Upgrade DB to %1: Fill civicrm_relationship_cache (%2 => %3)", [
70 1 => $rev,
71 2 => $startId,
72 3 => $endId,
73 ]);
74 $this->addTask($title, 'populateRelationshipCache', $startId, $endId);
75 }
76 }
77
78 /**
79 * Upgrade function.
80 *
81 * @param string $rev
82 */
83 public function upgrade_5_29_beta1($rev) {
84 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
85 $this->addTask('Make label field non required on price field value', 'priceFieldValueLabelNonRequired');
86 }
87
88 /**
89 * Make the price field value label column non required
90 * @return bool
91 */
92 public static function priceFieldValueLabelNonRequired() {
93 $locales = CRM_Core_I18n::getMultilingual();
94 if ($locales) {
95 foreach ($locales as $locale) {
96 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label_{$locale}` `label_{$locale}` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
97 CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label_{$locale} = NULL WHERE label_{$locale} = 'null'", [], TRUE, NULL, FALSE, FALSE);
98 }
99 }
100 else {
101 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label` `label` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
102 CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label = NULL WHERE label = 'null'", [], TRUE, NULL, FALSE, FALSE);
103 }
104 return TRUE;
105 }
106
107 /**
108 * Install sequentialCreditNotes extension.
109 *
110 * This feature is restructured as a core extension - which is primarily a code cleanup step.
111 *
112 * @param \CRM_Queue_TaskContext $ctx
113 *
114 * @return bool
115 *
116 * @throws \CiviCRM_API3_Exception
117 * @throws \CRM_Core_Exception
118 */
119 public static function installEventCart(CRM_Queue_TaskContext $ctx) {
120 // Install via direct SQL manipulation. Note that:
121 // (1) This extension has no activation logic.
122 // (2) On new installs, the extension is activated purely via default SQL INSERT.
123 // (3) Caches are flushed at the end of the upgrade.
124 // ($) Over long term, upgrade steps are more reliable in SQL. API/BAO sometimes don't work mid-upgrade.
125 $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([
126 'type' => 'module',
127 'full_name' => 'eventcart',
128 'name' => 'eventcart',
129 'label' => 'Event Cart',
130 'file' => 'eventcart',
131 'schema_version' => NULL,
132 'is_active' => 1,
133 ]);
134 CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL());
135
136 return TRUE;
137 }
138
139 /**
140 * @param \CRM_Queue_TaskContext $ctx
141 * @param int $startId
142 * The lowest relationship ID that should be updated.
143 * @param int $endId
144 * The highest relationship ID that should be updated.
145 * @return bool
146 * TRUE on success
147 */
148 public static function populateRelationshipCache(CRM_Queue_TaskContext $ctx, $startId, $endId) {
149 // NOTE: We duplicate CRM_Contact_BAO_RelationshipCache::$mappings in case
150 // the schema evolves over multiple releases.
151 $mappings = [
152 'a_b' => [
153 'relationship_id' => 'rel.id',
154 'relationship_type_id' => 'rel.relationship_type_id',
155 'orientation' => '"a_b"',
156 'near_contact_id' => 'rel.contact_id_a',
157 'near_relation' => 'reltype.name_a_b',
158 'far_contact_id' => 'rel.contact_id_b',
159 'far_relation' => 'reltype.name_b_a',
160 'start_date' => 'rel.start_date',
161 'end_date' => 'rel.end_date',
162 'is_active' => 'rel.is_active',
163 ],
164 'b_a' => [
165 'relationship_id' => 'rel.id',
166 'relationship_type_id' => 'rel.relationship_type_id',
167 'orientation' => '"b_a"',
168 'near_contact_id' => 'rel.contact_id_b',
169 'near_relation' => 'reltype.name_b_a',
170 'far_contact_id' => 'rel.contact_id_a',
171 'far_relation' => 'reltype.name_a_b',
172 'start_date' => 'rel.start_date',
173 'end_date' => 'rel.end_date',
174 'is_active' => 'rel.is_active',
175 ],
176 ];
177 $keyFields = ['relationship_id', 'orientation'];
178
179 foreach ($mappings as $mapping) {
180 $query = CRM_Utils_SQL_Select::from('civicrm_relationship rel')
181 ->join('reltype', 'INNER JOIN civicrm_relationship_type reltype ON rel.relationship_type_id = reltype.id')
182 ->syncInto('civicrm_relationship_cache', $keyFields, $mapping)
183 ->where('rel.id >= #START AND rel.id <= #END', [
184 '#START' => $startId,
185 '#END' => $endId,
186 ]);
187 $query->execute();
188 }
189
190 return TRUE;
191 }
192
193 }