From ce516a095f9023daa6d171fb9aeeae11325bbcad Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 8 Sep 2022 19:04:11 -0700 Subject: [PATCH] Extensions - Use ext_max_depth to limit scans for info.xml --- CRM/Extension/Container/Basic.php | 13 +++++++++++-- CRM/Extension/System.php | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CRM/Extension/Container/Basic.php b/CRM/Extension/Container/Basic.php index 0588c5eeb1..6d6157c041 100644 --- a/CRM/Extension/Container/Basic.php +++ b/CRM/Extension/Container/Basic.php @@ -77,6 +77,12 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface */ protected $filters = []; + /** + * @var int|null + * Maximum number of subdirectories to search. + */ + protected $maxDepth; + /** * @param string $baseDir * Local path to the container. @@ -86,12 +92,15 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface * Cache in which to store extension metadata. * @param string $cacheKey * Unique name for this container. + * @param int|null $maxDepth + * Maximum number of subdirectories to search. */ - public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { + public function __construct($baseDir, $baseUrl, CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL, ?int $maxDepth = NULL) { $this->cache = $cache; $this->cacheKey = $cacheKey; $this->baseDir = rtrim($baseDir, '/'); $this->baseUrl = rtrim($baseUrl, '/'); + $this->maxDepth = $maxDepth; } /** @@ -198,7 +207,7 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface } if (!is_array($this->relPaths)) { $this->relPaths = []; - $infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml'); + $infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml', FALSE, $this->maxDepth); foreach ($infoPaths as $infoPath) { $relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir); try { diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index 32d6cb6437..98815e8758 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -85,6 +85,7 @@ class CRM_Extension_System { */ public function __construct($parameters = []) { $config = CRM_Core_Config::singleton(); + $parameters['maxDepth'] = CRM_Utils_Array::value('maxDepth', $parameters, \Civi::settings()->get('ext_max_depth')); $parameters['extensionsDir'] = CRM_Utils_Array::value('extensionsDir', $parameters, $config->extensionsDir); $parameters['extensionsURL'] = CRM_Utils_Array::value('extensionsURL', $parameters, $config->extensionsURL); $parameters['resourceBase'] = CRM_Utils_Array::value('resourceBase', $parameters, $config->resourceBase); @@ -122,7 +123,8 @@ class CRM_Extension_System { $this->parameters['civicrm_root'], $this->parameters['resourceBase'], $this->getCache(), - 'civiroot' + 'civiroot', + $this->parameters['maxDepth'] ); // TODO: CRM_Extension_Container_Basic( /sites/all/modules ) @@ -138,7 +140,8 @@ class CRM_Extension_System { $vendorPath, CRM_Utils_File::addTrailingSlash($this->parameters['userFrameworkBaseURL'], '/') . 'vendor', $this->getCache(), - 'cmsvendor' + 'cmsvendor', + $this->parameters['maxDepth'] ); } } -- 2.25.1