3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Upgrade logic for FiveTwentyFive */
14 class CRM_Upgrade_Incremental_php_FiveTwentyFive
extends CRM_Upgrade_Incremental_Base
{
17 * Compute any messages which should be displayed beforeupgrade.
19 * Note: This function is called iteratively for each upcoming
20 * revision to the database.
22 * @param string $preUpgradeMessage
24 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
25 * @param null $currentVer
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>';
35 * Compute any messages which should be displayed after upgrade.
37 * @param string $postUpgradeMessage
40 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
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'.");
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):
56 // * Upgrade function.
58 // * @param string $rev
60 // public function upgrade_5_0_x($rev) {
61 // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
62 // $this->addTask('Do the foo change', 'taskFoo', ...);
63 // // Additional tasks here...
64 // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
65 // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
68 // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
77 public function upgrade_5_25_alpha1($rev) {
78 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
79 $this->addTask('Convert Report Form dates from jcalander to datepicker', 'convertReportsJcalendarToDatePicker');
82 public function upgrade_5_25_beta3($rev) {
83 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
84 $this->addTask('Convert CiviContribute settings', 'updateContributeSettings');
88 * Convert date fields stored in civicrm_report_instance to that format for datepicker
90 public static function convertReportsJcalendarToDatePicker() {
92 $reports = CRM_Core_DAO
::executeQuery("SELECT id FROM civicrm_report_instance WHERE form_values like '%relative%'");
93 while ($reports->fetch()) {
94 $report = civicrm_api3('ReportInstance', 'getsingle', ['id' => $reports->id
]);
95 $reportFormValues = unserialize($report['form_values']);
96 foreach ($reportFormValues as $index => $value) {
97 if (strpos($index, '_relative') !== FALSE) {
98 $date_fields[] = str_replace('_relative', '', $index);
101 foreach ($date_fields as $date_field) {
102 foreach ($reportFormValues as $index => $value) {
103 if ($index === $date_field . '_to' ||
$index === $date_field . '_from') {
104 $isEndOfDay = strpos($index, '_to') !== FALSE ?
TRUE : FALSE;
105 // If We have stored in the database hours minutes seconds use them
106 if (!empty($reportFormValues[$index . '_time'])) {
107 $time = $reportFormValues[$index . '_time'];
113 if (date('Y-m-d', strtotime($dateValue)) !== $dateValue
114 && date('Y-m-d H:i:s', strtotime($dateValue)) !== $dateValue
115 && !empty($dateValue)
117 $dateValue = date('Y-m-d H:i:s', strtotime(CRM_Utils_Date
::processDate($value, $time)));
119 $dateValue = str_replace('00:00:00', '23:59:59', $dateValue);
122 $reportFormValues[$index] = $dateValue;
123 // Now remove the time keys as no longer needed.
124 if (!empty($reportFormValues[$index . '_time'])) {
125 unset($reportFormValues[$index . '_time']);
129 if (serialize($reportFormValues) !== $report['form_values']) {
130 civicrm_api3('ReportInstance', 'create', ['id' => $report['id'], 'form_values' => serialize($reportFormValues)]);