From 56519dc115e8a259fd8fc2849330b9932782f481 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 4 Jun 2021 07:23:34 +0000 Subject: [PATCH] [php8-compat] fix Upgrade call back issues by making functions static and also fixing an issue with an array key not existing when checking obsolete extensions --- CRM/Extension/Manager.php | 62 ++++++++++--------- CRM/Upgrade/Incremental/Base.php | 2 +- CRM/Upgrade/Incremental/php/FiveSeventeen.php | 2 +- .../Incremental/php/FiveTwentySeven.php | 4 +- CRM/Upgrade/Incremental/php/FiveTwentySix.php | 2 +- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CRM/Extension/Manager.php b/CRM/Extension/Manager.php index 5b32af8dd0b6..dbdbeca74be3 100644 --- a/CRM/Extension/Manager.php +++ b/CRM/Extension/Manager.php @@ -382,36 +382,38 @@ public function disable($keys) { $this->addProcess($keys, 'disable'); foreach ($keys as $key) { - switch ($origStatuses[$key]) { - case self::STATUS_INSTALLED: - $this->addProcess([$key], 'disabling'); - // throws Exception - list ($info, $typeManager) = $this->_getInfoTypeHandler($key); - $typeManager->onPreDisable($info); - $this->_setExtensionActive($info, 0); - $typeManager->onPostDisable($info); - $this->popProcess([$key]); - break; - - case self::STATUS_INSTALLED_MISSING: - // throws Exception - list ($info, $typeManager) = $this->_getMissingInfoTypeHandler($key); - $typeManager->onPreDisable($info); - $this->_setExtensionActive($info, 0); - $typeManager->onPostDisable($info); - break; - - case self::STATUS_DISABLED: - case self::STATUS_DISABLED_MISSING: - case self::STATUS_UNINSTALLED: - // ok, nothing to do - // Remove the 'disable' process as we're not doing that. - $this->popProcess([$key]); - break; - - case self::STATUS_UNKNOWN: - default: - throw new CRM_Extension_Exception("Cannot disable unknown extension: $key"); + if (isset($origStatuses[$key])) { + switch ($origStatuses[$key]) { + case self::STATUS_INSTALLED: + $this->addProcess([$key], 'disabling'); + // throws Exception + list ($info, $typeManager) = $this->_getInfoTypeHandler($key); + $typeManager->onPreDisable($info); + $this->_setExtensionActive($info, 0); + $typeManager->onPostDisable($info); + $this->popProcess([$key]); + break; + + case self::STATUS_INSTALLED_MISSING: + // throws Exception + list ($info, $typeManager) = $this->_getMissingInfoTypeHandler($key); + $typeManager->onPreDisable($info); + $this->_setExtensionActive($info, 0); + $typeManager->onPostDisable($info); + break; + + case self::STATUS_DISABLED: + case self::STATUS_DISABLED_MISSING: + case self::STATUS_UNINSTALLED: + // ok, nothing to do + // Remove the 'disable' process as we're not doing that. + $this->popProcess([$key]); + break; + + case self::STATUS_UNKNOWN: + default: + throw new CRM_Extension_Exception("Cannot disable unknown extension: $key"); + } } } diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 60d4ca3a67e7..b51992a9a4d4 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -268,7 +268,7 @@ public static function updateContributeSettings($ctx) { * * @return bool */ - public function updateSmartGroups($ctx, $actions) { + public static function updateSmartGroups($ctx, $actions) { $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups(); $groupUpdateObject->updateGroups($actions); return TRUE; diff --git a/CRM/Upgrade/Incremental/php/FiveSeventeen.php b/CRM/Upgrade/Incremental/php/FiveSeventeen.php index 5f86560b0c49..4560afa58f7e 100644 --- a/CRM/Upgrade/Incremental/php/FiveSeventeen.php +++ b/CRM/Upgrade/Incremental/php/FiveSeventeen.php @@ -104,7 +104,7 @@ public function upgrade_5_17_1($rev) { /** * Update safe file types. */ - public function updateFileTypes() { + public static function updateFileTypes() { CRM_Core_BAO_OptionValue::ensureOptionValueExists([ 'option_group_id' => 'safe_file_extension', 'label' => 'pptx', diff --git a/CRM/Upgrade/Incremental/php/FiveTwentySeven.php b/CRM/Upgrade/Incremental/php/FiveTwentySeven.php index e84a025d24de..f7f307c6c0f2 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwentySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveTwentySeven.php @@ -71,7 +71,7 @@ public function upgrade_5_27_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); } - public function priceFieldValueLabelRequired($ctx) { + public static function priceFieldValueLabelRequired($ctx) { $locales = CRM_Core_I18n::getMultilingual(); if ($locales) { foreach ($locales as $locale) { @@ -86,7 +86,7 @@ public function priceFieldValueLabelRequired($ctx) { return TRUE; } - public function nameMembershipTypeRequired($ctx) { + public static function nameMembershipTypeRequired($ctx) { $locales = CRM_Core_I18n::getMultilingual(); if ($locales) { foreach ($locales as $locale) { diff --git a/CRM/Upgrade/Incremental/php/FiveTwentySix.php b/CRM/Upgrade/Incremental/php/FiveTwentySix.php index b23c29d6e6d9..cc04839d9515 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwentySix.php +++ b/CRM/Upgrade/Incremental/php/FiveTwentySix.php @@ -81,7 +81,7 @@ public function upgrade_5_26_alpha1($rev) { /** * Update workflow_name based on workflow_id values. */ - public function populateWorkflowName() { + public static function populateWorkflowName() { CRM_Core_DAO::executeQuery('UPDATE civicrm_msg_template LEFT JOIN civicrm_option_value ov ON ov.id = workflow_id SET workflow_name = ov.name'