dev/core#1932 - Make status-checks more polite during upgrade
authorTim Otten <totten@civicrm.org>
Thu, 6 Aug 2020 09:04:36 +0000 (02:04 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 6 Aug 2020 09:07:25 +0000 (02:07 -0700)
Before
------

If you happen to run a status-check (eg `showPeriodicAlerts()`) in the interim between
downloading code and running DB upgrades, then you'll get weird failures.

After
-----

The status-checks are able to complete.

Technical Details
-----------------

(1) I figure that this conditional is lightweight because it relies on data
that's read-once and then cached in memory:

```
CRM_Utils_System::version() !== CRM_Core_BAO_Domain::version()
```

(2) The easiest way to reproduce is to get a DB from before 4.7 and coerce
`CRM_Utils_Check::CHECK_TIMER`.

CRM/Utils/Check/Component.php
CRM/Utils/Check/Component/Env.php
CRM/Utils/Check/Component/OptionGroups.php
CRM/Utils/Check/Message.php

index 5b5dcc746258972805f8271062c29767e88aa369..37a7171cab4373bd647129b919c41741f43a02da 100644 (file)
@@ -27,10 +27,16 @@ abstract class CRM_Utils_Check_Component {
    * @throws \Civi\API\Exception\UnauthorizedException
    */
   public function getChecksConfig() {
-    if (empty(Civi::$statics[__FUNCTION__])) {
-      Civi::$statics[__FUNCTION__] = (array) StatusPreference::get(FALSE)
-        ->addWhere('domain_id', '=', 'current_domain')
-        ->execute()->indexBy('name');
+    if (!isset(Civi::$statics[__FUNCTION__])) {
+      // TODO: Remove this check when MINIMUM_UPGRADABLE_VERSION goes to 4.7.
+      if (CRM_Utils_System::version() !== CRM_Core_BAO_Domain::version() && !CRM_Core_DAO::checkTableExists('civicrm_status_pref')) {
+        Civi::$statics[__FUNCTION__] = [];
+      }
+      else {
+        Civi::$statics[__FUNCTION__] = (array) StatusPreference::get(FALSE)
+          ->addWhere('domain_id', '=', 'current_domain')
+          ->execute()->indexBy('name');
+      }
     }
     return Civi::$statics[__FUNCTION__];
   }
index f3a494ab95131c23f3490d7017c1ab6461a9f2ce..26e77d8caedd52249cb00a0ebe8a1707a0d3b6d8 100644 (file)
@@ -281,6 +281,11 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
    * @throws CRM_Core_Exception
    */
   public function checkLastCron($force = FALSE) {
+    // TODO: Remove this check when MINIMUM_UPGRADABLE_VERSION goes to 4.7.
+    if (CRM_Utils_System::version() !== CRM_Core_BAO_Domain::version()) {
+      return [];
+    }
+
     $messages = [];
 
     // Cron doesn't work in non-production environments; skip.
index a47303ad0de0c4a501e6d2e04710222e84644816..62017ae83ed6d384ac07a610760cd7e1fb29910c 100644 (file)
@@ -20,6 +20,10 @@ class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component {
    * @return CRM_Utils_Check_Message[]
    */
   public function checkOptionGroupValues() {
+    if (CRM_Utils_System::version() !== CRM_Core_BAO_Domain::version()) {
+      return [];
+    }
+
     $messages = [];
     $problemValues = [];
     $optionGroups  = civicrm_api3('OptionGroup', 'get', [
index 139ab43ff3dda3c9e1a68d582b185f2ac288e30a..94f51db49d9da3899c647c2fd12a9e9edcfe2372 100644 (file)
@@ -246,6 +246,11 @@ class CRM_Utils_Check_Message {
    * @throws \CiviCRM_API3_Exception
    */
   private function checkStatusPreference() {
+    // TODO: Remove this check when MINIMUM_UPGRADABLE_VERSION goes to 4.7.
+    if (CRM_Utils_System::version() !== CRM_Core_BAO_Domain::version() && !CRM_Core_DAO::checkTableExists('civicrm_status_pref')) {
+      return FALSE;
+    }
+
     $this->hiddenUntil = FALSE;
     // Debug & info can't be hidden
     if ($this->level < 2) {