From e4c4f267b6029cd2c95e5c5dbc6094e7d0bf5e3d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 17 Dec 2018 12:01:50 -0500 Subject: [PATCH] Add extension compatibility list --- CRM/Admin/Page/Extensions.php | 7 ++++- CRM/Extension/Info.php | 23 +++++++++++++--- CRM/Extension/System.php | 12 +++++++++ CRM/Upgrade/Form.php | 34 ++++++++++++++++++++++++ distmaker/dists/common.sh | 2 +- extension-compatibility.json | 5 ++++ tests/phpunit/CRM/Extension/InfoTest.php | 8 ++++++ 7 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 extension-compatibility.json diff --git a/CRM/Admin/Page/Extensions.php b/CRM/Admin/Page/Extensions.php index 966c1a195d..97da3d1755 100644 --- a/CRM/Admin/Page/Extensions.php +++ b/CRM/Admin/Page/Extensions.php @@ -221,7 +221,7 @@ class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic { } /** - * Get the list of local extensions and format them as a table with + * Get the list of remote extensions and format them as a table with * status and action data. * * @param array $localExtensionRows @@ -238,7 +238,12 @@ class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic { // build list of available downloads $remoteExtensionRows = array(); + $compat = CRM_Extension_System::getCompatibilityInfo(); + foreach ($remoteExtensions as $info) { + if (!empty($compat[$info->key]['obsolete'])) { + continue; + } $row = (array) $info; $row['id'] = $info->key; $action = CRM_Core_Action::UPDATE; diff --git a/CRM/Extension/Info.php b/CRM/Extension/Info.php index 4302f77500..aa8e4ba7a9 100644 --- a/CRM/Extension/Info.php +++ b/CRM/Extension/Info.php @@ -169,10 +169,7 @@ class CRM_Extension_Info { } } elseif ($attr === 'requires') { - $this->requires = array(); - foreach ($val->ext as $ext) { - $this->requires[] = (string) $ext; - } + $this->requires = $this->filterRequirements($val); } else { $this->$attr = CRM_Utils_XML::xmlObjToArray($val); @@ -180,4 +177,22 @@ class CRM_Extension_Info { } } + /** + * Filter out invalid requirements, e.g. extensions that have been moved to core. + * + * @param SimpleXMLElement $requirements + * @return array + */ + public function filterRequirements($requirements) { + $filtered = []; + $compatInfo = CRM_Extension_System::getCompatibilityInfo(); + foreach ($requirements->ext as $ext) { + $ext = (string) $ext; + if (empty($compatInfo[$ext]['obsolete'])) { + $filtered[] = $ext; + } + } + return $filtered; + } + } diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index 20d171d131..e1b0b0852d 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -286,6 +286,18 @@ class CRM_Extension_System { return $this->_repoUrl; } + /** + * Returns a list keyed by extension key + * + * @return array + */ + public static function getCompatibilityInfo() { + if (!isset(Civi::$statics[__CLASS__]['compatibility'])) { + Civi::$statics[__CLASS__]['compatibility'] = json_decode(file_get_contents(Civi::paths()->getPath('[civicrm.root]/extension-compatibility.json')), TRUE); + } + return Civi::$statics[__CLASS__]['compatibility']; + } + /** * Take an extension's raw XML info and add information about the * extension's status on the local system. diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 16a2740d67..b13361347c 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -547,6 +547,13 @@ SET version = '$version' ); $queue->createItem($task); + $task = new CRM_Queue_Task( + array('CRM_Upgrade_Form', 'disableOldExtensions'), + array($postUpgradeMessageFile), + "Checking extensions" + ); + $queue->createItem($task); + $revisions = $upgrade->getRevisionSequence(); foreach ($revisions as $rev) { // proceed only if $currentVer < $rev @@ -624,6 +631,33 @@ SET version = '$version' return TRUE; } + /** + * Disable any extensions not compatible with this new version. + * + * @param \CRM_Queue_TaskContext $ctx + * @param string $postUpgradeMessageFile + * @return bool + */ + public static function disableOldExtensions(CRM_Queue_TaskContext $ctx, $postUpgradeMessageFile) { + $compatInfo = CRM_Extension_System::getCompatibilityInfo(); + $disabled = []; + $manager = CRM_Extension_System::singleton()->getManager(); + foreach ($compatInfo as $key => $ext) { + if (!empty($ext['obsolete']) && $manager->getStatus($key) == $manager::STATUS_INSTALLED) { + $disabled[$key] = sprintf("
  • %s
  • ", ts('The extension %1 is now obsolete and has been disabled.', [1 => $key])); + } + } + if ($disabled) { + $manager->disable(array_keys($disabled)); + file_put_contents($postUpgradeMessageFile, + '

    ', + FILE_APPEND + ); + } + + return TRUE; + } + /** * Perform an incremental version update. * diff --git a/distmaker/dists/common.sh b/distmaker/dists/common.sh index e760bf5930..1ad546ef5b 100644 --- a/distmaker/dists/common.sh +++ b/distmaker/dists/common.sh @@ -70,7 +70,7 @@ function dm_install_core() { done dm_install_files "$repo" "$to" {agpl-3.0,agpl-3.0.exception,gpl,CONTRIBUTORS}.txt - dm_install_files "$repo" "$to" composer.json composer.lock bower.json package.json Civi.php README.md release-notes.md + dm_install_files "$repo" "$to" composer.json composer.lock bower.json package.json Civi.php README.md release-notes.md extension-compatibility.json mkdir -p "$to/sql" pushd "$repo" >> /dev/null diff --git a/extension-compatibility.json b/extension-compatibility.json new file mode 100644 index 0000000000..2f8bd4b813 --- /dev/null +++ b/extension-compatibility.json @@ -0,0 +1,5 @@ +{ + "com.ixiam.modules.quicksearch": { + "obsolete": "5.8" + } +} diff --git a/tests/phpunit/CRM/Extension/InfoTest.php b/tests/phpunit/CRM/Extension/InfoTest.php index 0ae7fba1c0..879cb76288 100644 --- a/tests/phpunit/CRM/Extension/InfoTest.php +++ b/tests/phpunit/CRM/Extension/InfoTest.php @@ -81,4 +81,12 @@ class CRM_Extension_InfoTest extends CiviUnitTestCase { $this->assertTrue(is_object($exc)); } + public function test_requirements() { + // Quicksearch requirement should get filtered out per extension-compatibility.json + $data = "fooexample.testcom.ixiam.modules.quicksearch"; + + $info = CRM_Extension_Info::loadFromString($data); + $this->assertEquals(['example.test'], $info->requires); + } + } -- 2.25.1