remove never-used option value
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FiveEighteen.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 FiveEighteen */
14 class CRM_Upgrade_Incremental_php_FiveEighteen 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 ($rev == '5.12.34') {
30 // $preUpgradeMessage .= '<p>' . ts('A new permission, "%1", has been added. This permission is now used to control access to the Manage Tags screen.', array(1 => ts('manage tags'))) . '</p>';
31 // }
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) {
43 // Example: Generate a post-upgrade message.
44 // if ($rev == '5.12.34') {
45 // $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'.");
46 // }
47 }
48
49 /*
50 * Important! All upgrade functions MUST add a 'runSql' task.
51 * Uncomment and use the following template for a new upgrade version
52 * (change the x in the function name):
53 */
54
55 /**
56 * Upgrade function.
57 *
58 * @param string $rev
59 */
60 public function upgrade_5_18_alpha1($rev) {
61 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
62 $this->addTask('Update smart groups to reflect change of unique name for is_override', 'updateSmartGroups', [
63 'renameField' => [
64 ['old' => 'is_override', 'new' => 'member_is_override'],
65 ],
66 ]);
67 $this->addTask('Remove Foreign Key from civicrm_dashboard on domain_id if exists', 'removeDomainIDFK');
68 $this->addTask('Remove Index on domain_id that might have been randomly added in the same format as FK', 'dropIndex', 'civicrm_dashboard', 'FK_civicrm_dashboard_domain_id');
69 $this->addTask('Re-Create Foreign key between civicrm_dashboard and civicrm_domain correctly', 'recreateDashboardFK');
70 $this->addTask('Update smart groups to rename filters on pledge_payment_date to pledge_payment_scheduled_date', 'updateSmartGroups', [
71 'renameField' => [
72 ['old' => 'pledge_payment_date_relative', 'new' => 'pledge_payment_scheduled_date_relative'],
73 ['old' => 'pledge_payment_date_high', 'new' => 'pledge_payment_scheduled_date_high'],
74 ['old' => 'pledge_payment_date_low', 'new' => 'pledge_payment_scheduled_date_low'],
75 ['old' => 'member_join_date_relative', 'new' => 'membership_join_date_relative'],
76 ['old' => 'member_join_date_high', 'new' => 'membership_join_date_high'],
77 ['old' => 'member_join_date_low', 'new' => 'membership_join_date_low'],
78 ['old' => 'member_start_date_relative', 'new' => 'membership_start_date_relative'],
79 ['old' => 'member_start_date_high', 'new' => 'membership_start_date_high'],
80 ['old' => 'member_start_date_low', 'new' => 'membership_start_date_low'],
81 ['old' => 'member_end_date_relative', 'new' => 'membership_end_date_relative'],
82 ['old' => 'member_end_date_high', 'new' => 'membership_end_date_high'],
83 ['old' => 'member_end_date_low', 'new' => 'membership_end_date_low'],
84 ],
85 ]);
86 $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
87 'datepickerConversion' => [
88 'pledge_payment_scheduled_date',
89 'pledge_create_date',
90 'pledge_end_date',
91 'pledge_start_date',
92 'membership_join_date',
93 'membership_end_date',
94 'membership_start_date',
95 ],
96 ]);
97 $this->addTask('Update civicrm_mapping_field and civicrm_uf_field for change in join_date name', 'updateJoinDateMappingUF');
98 $this->addTask('Update civicrm_report_instances for change in filter from join_date to membership_join_date', 'joinDateReportUpdate');
99 }
100
101 public static function removeDomainIDFK() {
102 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_dashboard', 'FK_civicrm_dashboard_domain_id');
103 return TRUE;
104 }
105
106 public static function recreateDashboardFK() {
107 $sql = CRM_Core_BAO_SchemaHandler::buildForeignKeySQL([
108 'fk_table_name' => 'civicrm_domain',
109 'fk_field_name' => 'id',
110 'name' => 'domain_id',
111 'fk_attributes' => ' ON DELETE CASCADE',
112 ], "\n", " ADD ", 'civicrm_dashboard');
113 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_dashboard " . $sql, [], TRUE, NULL, FALSE, FALSE);
114 return TRUE;
115 }
116
117 public static function updateJoinDateMappingUF() {
118 CRM_Core_DAO::executeQuery("UPDATE civicrm_mapping_field SET name = 'membership_join_date' WHERE name = 'join_date' AND contact_type = 'Membership'");
119 CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET field_name = 'membership_join_date' WHERE field_name = 'join_date' AND field_type = 'Membership'");
120 return TRUE;
121 }
122
123 public static function joinDateReportUpdate() {
124 $report_templates = ['member/contributionDetail', 'member/Detail', 'member/Summary'];
125 $substitutions = [
126 'join_date_relative' => 'membership_join_date_relative',
127 'join_date_from' => 'membership_join_date_from',
128 'join_date_to' => 'membership_join_date_to',
129 ];
130 foreach ($report_templates as $report_template) {
131 $reports = civicrm_api3('ReportInstance', 'get', [
132 'report_id' => $report_template,
133 'options' => ['limit' => 0],
134 ])['values'];
135 foreach ($reports as $report) {
136 if (!is_array($report['form_values'])) {
137 $form_values = unserialize($report['form_values']);
138 }
139 else {
140 $form_values = $report['form_values'];
141 }
142 foreach ($form_values as $key => $value) {
143 if (array_key_exists($key, $substitutions)) {
144 $form_values[$substitutions[$key]] = $value;
145 unset($form_values[$key]);
146 }
147 }
148 $form_values = serialize($form_values);
149 CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET form_values = %1 WHERE id = %2", [
150 1 => [$form_values, 'String'],
151 2 => [$report['id'], 'Positive'],
152 ]);
153 }
154 }
155 return TRUE;
156 }
157
158 // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
159 // return TRUE;
160 // }
161
162 }