X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FExtension%2FMapper.php;h=dd989c8413ad4bf9b5c8ca6f19a4d2b13d577a8c;hb=c6da7104e771b5039d040499629d4da1a5780bdb;hp=59caf165e00925f38ee63606941722198ef46f64;hpb=515c2cde0bdfe5b7e805ecd26b0d471e899096a6;p=civicrm-core.git diff --git a/CRM/Extension/Mapper.php b/CRM/Extension/Mapper.php index 59caf165e0..dd989c8413 100644 --- a/CRM/Extension/Mapper.php +++ b/CRM/Extension/Mapper.php @@ -66,6 +66,12 @@ class CRM_Extension_Mapper { protected $civicrmUrl; + /** + * @var array + * Array(string $extKey => CRM_Extension_Upgrader_Interface $upgrader) + */ + protected $upgraders = []; + /** * @param CRM_Extension_Container_Interface $container * @param CRM_Utils_Cache_Interface $cache @@ -474,8 +480,7 @@ class CRM_Extension_Mapper { /** * Get a list of all installed modules, including enabled and disabled ones * - * @return array - * CRM_Core_Module + * @return CRM_Core_Module[] */ public function getModules() { $result = []; @@ -555,4 +560,36 @@ class CRM_Extension_Mapper { } } + /** + * @param string $key + * Long name of the extension. + * Ex: 'org.example.myext' + * + * @return \CRM_Extension_Upgrader_Interface + */ + public function getUpgrader(string $key) { + if (!array_key_exists($key, $this->upgraders)) { + $this->upgraders[$key] = NULL; + + try { + $info = $this->keyToInfo($key); + } + catch (CRM_Extension_Exception_ParseException $e) { + CRM_Core_Session::setStatus(ts('Parse error in extension: %1', [ + 1 => $e->getMessage(), + ]), '', 'error'); + CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage()); + return NULL; + } + + if (!empty($info->upgrader)) { + $class = $info->upgrader; + $u = new $class(); + $u->init(['key' => $key]); + $this->upgraders[$key] = $u; + } + } + return $this->upgraders[$key]; + } + }