Cleanup CRM_Utils_Check version safeguard with APIv4
authorColeman Watts <coleman@civicrm.org>
Wed, 12 Aug 2020 18:50:37 +0000 (14:50 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 13 Aug 2020 00:50:58 +0000 (20:50 -0400)
CRM/Utils/Check/Component.php
CRM/Utils/Check/Message.php

index 37a7171cab4373bd647129b919c41741f43a02da..2f57004adeac08cab6f600a86befab37e61c55f3 100644 (file)
@@ -28,15 +28,9 @@ abstract class CRM_Utils_Check_Component {
    */
   public function getChecksConfig() {
     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');
-      }
+      Civi::$statics[__FUNCTION__] = (array) StatusPreference::get(FALSE)
+        ->addWhere('domain_id', '=', 'current_domain')
+        ->execute()->indexBy('name');
     }
     return Civi::$statics[__FUNCTION__];
   }
index 94f51db49d9da3899c647c2fd12a9e9edcfe2372..e0a7d51d7b308c53d5b2ad7638ef50c376737b18 100644 (file)
@@ -246,32 +246,25 @@ 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) {
       return FALSE;
     }
-    $statusPreferenceParams = [
-      'name' => $this->getName(),
-      'domain_id' => CRM_Core_Config::domainID(),
-      'sequential' => 1,
+    $where = [
+      ['name', '=', $this->getName()],
+      ['domain_id', '=', CRM_Core_Config::domainID()],
     ];
     // Check if there's a StatusPreference matching this name/domain.
-    $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams);
-    $prefs = CRM_Utils_Array::value('values', $statusPreference, []);
-    if ($prefs) {
+    $pref = civicrm_api4('StatusPreference', 'get', ['checkPermissions' => FALSE, 'where' => $where])->first();
+    if ($pref) {
       // If so, compare severity to StatusPreference->severity.
-      if ($this->level <= $prefs[0]['ignore_severity']) {
-        if (isset($prefs[0]['hush_until'])) {
+      if ($this->level <= $pref['ignore_severity']) {
+        if (isset($pref['hush_until'])) {
           // Time-based hush.
-          $this->hiddenUntil = $prefs[0]['hush_until'];
+          $this->hiddenUntil = $pref['hush_until'];
           $today = new DateTime();
-          $snoozeDate = new DateTime($prefs[0]['hush_until']);
+          $snoozeDate = new DateTime($pref['hush_until']);
           return !($today > $snoozeDate);
         }
         else {