| 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 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This class contains generic upgrade logic which runs regardless of version. |
| 20 | */ |
| 21 | class CRM_Upgrade_Incremental_General { |
| 22 | |
| 23 | /** |
| 24 | * The recommended PHP version. |
| 25 | * |
| 26 | * The point release will be dropped in recommendations unless it's .1 or |
| 27 | * higher. |
| 28 | */ |
| 29 | const RECOMMENDED_PHP_VER = '7.3.0'; |
| 30 | |
| 31 | /** |
| 32 | * The minimum recommended PHP version. |
| 33 | * |
| 34 | * A site running an earlier version will be told to upgrade. |
| 35 | */ |
| 36 | const MIN_RECOMMENDED_PHP_VER = '7.2.0'; |
| 37 | |
| 38 | /** |
| 39 | * The minimum PHP version required to install Civi. |
| 40 | * |
| 41 | * @see install/index.php |
| 42 | */ |
| 43 | const MIN_INSTALL_PHP_VER = '7.1.0'; |
| 44 | |
| 45 | /** |
| 46 | * The minimum recommended MySQL/MariaDB version. |
| 47 | * |
| 48 | * A site running an earlier version will be told to upgrade. |
| 49 | */ |
| 50 | const MIN_RECOMMENDED_MYSQL_VER = '5.7'; |
| 51 | |
| 52 | /** |
| 53 | * The minimum MySQL/MariaDB version required to install Civi. |
| 54 | * |
| 55 | * @see install/index.php |
| 56 | */ |
| 57 | const MIN_INSTALL_MYSQL_VER = '5.6.5'; |
| 58 | |
| 59 | /** |
| 60 | * Compute any messages which should be displayed before upgrade. |
| 61 | * |
| 62 | * @param string $preUpgradeMessage |
| 63 | * alterable. |
| 64 | * @param $currentVer |
| 65 | * @param $latestVer |
| 66 | */ |
| 67 | public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) { |
| 68 | $dateFormat = Civi::Settings()->get('dateformatshortdate'); |
| 69 | $phpversion = phpversion(); |
| 70 | if (version_compare($phpversion, self::MIN_RECOMMENDED_PHP_VER) < 0) { |
| 71 | $preUpgradeMessage .= '<p>'; |
| 72 | $preUpgradeMessage .= ts('This system uses PHP v%4. You may proceed with the upgrade, and CiviCRM v%1 will continue working normally. However, future releases will require PHP v%2. We recommend PHP v%3.', [ |
| 73 | 1 => $latestVer, |
| 74 | 2 => self::MIN_RECOMMENDED_PHP_VER . '+', |
| 75 | 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER) . '+', |
| 76 | 4 => $phpversion, |
| 77 | ]); |
| 78 | $preUpgradeMessage .= '</p>'; |
| 79 | } |
| 80 | if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::MIN_RECOMMENDED_MYSQL_VER) < 0) { |
| 81 | $preUpgradeMessage .= '<p>'; |
| 82 | $preUpgradeMessage .= ts('This system uses MySQL/MariaDB v%5. You may proceed with the upgrade, and CiviCRM v%1 will continue working normally. However, CiviCRM v%4 will require MySQL v%2 or MariaDB v%3.', [ |
| 83 | 1 => $latestVer, |
| 84 | 2 => self::MIN_RECOMMENDED_MYSQL_VER . '+', |
| 85 | 3 => '10.1' . '+', |
| 86 | 4 => '5.34' . '+', |
| 87 | 5 => CRM_Utils_SQL::getDatabaseVersion(), |
| 88 | ]); |
| 89 | $preUpgradeMessage .= '</p>'; |
| 90 | } |
| 91 | |
| 92 | // http://issues.civicrm.org/jira/browse/CRM-13572 |
| 93 | // Depending on how the code was upgraded, some sites may still have copies of old |
| 94 | // source files left behind. This is often a forgivable offense, but it's quite |
| 95 | // dangerous for CIVI-SA-2013-001. |
| 96 | global $civicrm_root; |
| 97 | $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php"; |
| 98 | if (file_exists($ofcFile)) { |
| 99 | if (@unlink($ofcFile)) { |
| 100 | $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [ |
| 101 | 1 => $ofcFile, |
| 102 | ]); |
| 103 | } |
| 104 | else { |
| 105 | $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [ |
| 106 | 1 => $ofcFile, |
| 107 | ]); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (Civi::settings()->get('enable_innodb_fts')) { |
| 112 | // The FTS indexing feature dynamically manipulates the schema which could |
| 113 | // cause conflicts with other layers that manipulate the schema. The |
| 114 | // simplest thing is to turn it off and back on. |
| 115 | |
| 116 | // It may not always be necessary to do this -- but I doubt we're going to test |
| 117 | // systematically in future releases. When it is necessary, one could probably |
| 118 | // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences |
| 119 | // after the upgrade. But that's speculative. For now, we'll leave this |
| 120 | // advanced feature in the hands of the sysadmin. |
| 121 | $preUpgradeMessage .= '<br />' . ts('This database uses InnoDB Full Text Search for optimized searching. The upgrade procedure has not been tested with this feature. You should disable (and later re-enable) the feature by navigating to "Administer => Customize Data and Screens => Search Preferences".'); |
| 122 | } |
| 123 | |
| 124 | $ftAclSetting = Civi::settings()->get('acl_financial_type'); |
| 125 | $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']); |
| 126 | if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) { |
| 127 | $preUpgradeMessage .= '<br />' . ts('CiviCRM will in the future require the extension %1 for CiviCRM Reports to work correctly with the Financial Type ACLs. The extension can be downloaded <a href="%2">here</a>', [ |
| 128 | 1 => 'biz.jmaconsulting.financialaclreport', |
| 129 | 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport', |
| 130 | ]); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Perform any message template updates. 5.0+. |
| 136 | * @param $message |
| 137 | * @param $version |
| 138 | */ |
| 139 | public static function updateMessageTemplate(&$message, $version) { |
| 140 | if (version_compare($version, 5.0, '<')) { |
| 141 | return; |
| 142 | } |
| 143 | $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version); |
| 144 | $messages = $messageObj->getUpgradeMessages(); |
| 145 | if (empty($messages)) { |
| 146 | return; |
| 147 | } |
| 148 | $messagesHtml = array_map(function($k, $v) { |
| 149 | return sprintf("<li><em>%s</em> - %s</li>", htmlentities($k), htmlentities($v)); |
| 150 | }, array_keys($messages), $messages); |
| 151 | |
| 152 | $message .= '<br />' . ts("The default copies of the message templates listed below will be updated to handle new features or correct a problem. Your installation has customized versions of these message templates, and you will need to apply the updates manually after running this upgrade. <a href='%1' style='color:white; text-decoration:underline; font-weight:bold;' target='_blank'>Click here</a> for detailed instructions. %2", [ |
| 153 | 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates', |
| 154 | 2 => '<ul>' . implode('', $messagesHtml) . '</ul>', |
| 155 | ]); |
| 156 | |
| 157 | $messageObj->updateTemplates(); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @param $message |
| 162 | * @param $latestVer |
| 163 | * @param $currentVer |
| 164 | */ |
| 165 | public static function checkMessageTemplate(&$message, $latestVer, $currentVer) { |
| 166 | if (version_compare($currentVer, 5.0, '>')) { |
| 167 | return; |
| 168 | } |
| 169 | $sql = "SELECT orig.workflow_id as workflow_id, |
| 170 | orig.msg_title as title |
| 171 | FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON ( |
| 172 | diverted.workflow_id = orig.workflow_id AND |
| 173 | orig.is_reserved = 1 AND ( |
| 174 | diverted.msg_subject != orig.msg_subject OR |
| 175 | diverted.msg_text != orig.msg_text OR |
| 176 | diverted.msg_html != orig.msg_html |
| 177 | ) |
| 178 | )"; |
| 179 | |
| 180 | $dao = CRM_Core_DAO::executeQuery($sql); |
| 181 | while ($dao->fetch()) { |
| 182 | $workflows[$dao->workflow_id] = $dao->title; |
| 183 | } |
| 184 | |
| 185 | if (empty($workflows)) { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | $html = NULL; |
| 190 | $pathName = dirname(dirname(__FILE__)); |
| 191 | $flag = FALSE; |
| 192 | foreach ($workflows as $workflow => $title) { |
| 193 | $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', |
| 194 | $workflow, |
| 195 | 'name', |
| 196 | 'id' |
| 197 | ); |
| 198 | |
| 199 | // check if file exists locally |
| 200 | $textFileName = implode(DIRECTORY_SEPARATOR, |
| 201 | [ |
| 202 | $pathName, |
| 203 | "{$latestVer}.msg_template", |
| 204 | 'message_templates', |
| 205 | "{$name}_text.tpl", |
| 206 | ] |
| 207 | ); |
| 208 | |
| 209 | $htmlFileName = implode(DIRECTORY_SEPARATOR, |
| 210 | [ |
| 211 | $pathName, |
| 212 | "{$latestVer}.msg_template", |
| 213 | 'message_templates', |
| 214 | "{$name}_html.tpl", |
| 215 | ] |
| 216 | ); |
| 217 | |
| 218 | if (file_exists($textFileName) || |
| 219 | file_exists($htmlFileName) |
| 220 | ) { |
| 221 | $flag = TRUE; |
| 222 | $html .= "<li>{$title}</li>"; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if ($flag == TRUE) { |
| 227 | $html = "<ul>" . $html . "<ul>"; |
| 228 | |
| 229 | $message .= '<br />' . ts("The default copies of the message templates listed below will be updated to handle new features or correct a problem. Your installation has customized versions of these message templates, and you will need to apply the updates manually after running this upgrade. <a href='%1' style='color:white; text-decoration:underline; font-weight:bold;' target='_blank'>Click here</a> for detailed instructions. %2", [ |
| 230 | 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates', |
| 231 | 2 => $html, |
| 232 | ]); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | } |