Skip to content
Snippets Groups Projects
Commit 6a48b56e authored by Ted Bowman's avatar Ted Bowman Committed by Lucas Hedding
Browse files

Issue #3157857 by tedbow, heddn: Do not accessed Extensionlist class variables...

Issue #3157857 by tedbow, heddn: Do not accessed Extensionlist class variables in AutomaticUpdatesPsa dynamically
parent 25808277
No related branches found
No related tags found
No related merge requests found
...@@ -2,11 +2,20 @@ ...@@ -2,11 +2,20 @@
namespace Drupal\automatic_updates; namespace Drupal\automatic_updates;
use Drupal\Core\Extension\ExtensionList;
/** /**
* Provide a helper to get project info. * Provide a helper to get project info.
*/ */
trait ProjectInfoTrait { trait ProjectInfoTrait {
/**
* The extension lists.
*
* @var \Drupal\Core\Extension\ExtensionList[]
*/
protected $extensionLists;
/** /**
* Get extension list. * Get extension list.
* *
...@@ -17,15 +26,46 @@ trait ProjectInfoTrait { ...@@ -17,15 +26,46 @@ trait ProjectInfoTrait {
* The extension list service. * The extension list service.
*/ */
protected function getExtensionList($extension_type) { protected function getExtensionList($extension_type) {
if (isset($this->{$extension_type})) { if (isset($this->extensionLists[$extension_type])) {
$list = $this->{$extension_type}; $list = $this->extensionLists[$extension_type];
} }
else { else {
if (!in_array($extension_type, $this->getExtensionsTypes())) {
throw new \UnexpectedValueException("Invalid extension type: $extension_type");
}
$list = \Drupal::service("extension.list.$extension_type"); $list = \Drupal::service("extension.list.$extension_type");
} }
return $list; return $list;
} }
/**
* Sets the extension lists.
*
* @param \Drupal\Core\Extension\ExtensionList $module_list
* The module extension list.
* @param \Drupal\Core\Extension\ExtensionList $theme_list
* The theme extension list.
* @param \Drupal\Core\Extension\ExtensionList $profile_list
* The profile extension list.
*/
protected function setExtensionLists(ExtensionList $module_list, ExtensionList $theme_list, ExtensionList $profile_list) {
$this->extensionLists = [
'module' => $module_list,
'theme' => $theme_list,
'profile' => $profile_list,
];
}
/**
* Get the extension types.
*
* @return string[]
* The extension types.
*/
protected function getExtensionsTypes() {
return ['module', 'profile', 'theme'];
}
/** /**
* Returns an array of info files information of available extensions. * Returns an array of info files information of available extensions.
* *
......
...@@ -15,27 +15,6 @@ class MissingProjectInfo implements ReadinessCheckerInterface { ...@@ -15,27 +15,6 @@ class MissingProjectInfo implements ReadinessCheckerInterface {
use ProjectInfoTrait; use ProjectInfoTrait;
use StringTranslationTrait; use StringTranslationTrait;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $modules;
/**
* The profile extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $profiles;
/**
* The theme extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $themes;
/** /**
* MissingProjectInfo constructor. * MissingProjectInfo constructor.
* *
...@@ -47,9 +26,7 @@ class MissingProjectInfo implements ReadinessCheckerInterface { ...@@ -47,9 +26,7 @@ class MissingProjectInfo implements ReadinessCheckerInterface {
* The theme extension list. * The theme extension list.
*/ */
public function __construct(ExtensionList $modules, ExtensionList $profiles, ExtensionList $themes) { public function __construct(ExtensionList $modules, ExtensionList $profiles, ExtensionList $themes) {
$this->modules = $modules; $this->setExtensionLists($modules, $themes, $profiles);
$this->profiles = $profiles;
$this->themes = $themes;
} }
/** /**
...@@ -80,14 +57,4 @@ class MissingProjectInfo implements ReadinessCheckerInterface { ...@@ -80,14 +57,4 @@ class MissingProjectInfo implements ReadinessCheckerInterface {
return $messages; return $messages;
} }
/**
* Get the extension types.
*
* @return array
* The extension types.
*/
protected function getExtensionsTypes() {
return ['modules', 'profiles', 'themes'];
}
} }
...@@ -22,27 +22,6 @@ class ModifiedFiles implements ReadinessCheckerInterface { ...@@ -22,27 +22,6 @@ class ModifiedFiles implements ReadinessCheckerInterface {
*/ */
protected $modifiedFiles; protected $modifiedFiles;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $module;
/**
* The profile extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $profile;
/**
* The theme extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $theme;
/** /**
* An array of array of strings of extension paths. * An array of array of strings of extension paths.
* *
...@@ -65,9 +44,7 @@ class ModifiedFiles implements ReadinessCheckerInterface { ...@@ -65,9 +44,7 @@ class ModifiedFiles implements ReadinessCheckerInterface {
*/ */
public function __construct(ModifiedFilesInterface $modified_files, ExtensionList $modules, ExtensionList $profiles, ExtensionList $themes) { public function __construct(ModifiedFilesInterface $modified_files, ExtensionList $modules, ExtensionList $profiles, ExtensionList $themes) {
$this->modifiedFiles = $modified_files; $this->modifiedFiles = $modified_files;
$this->module = $modules; $this->setExtensionLists($modules, $themes, $profiles);
$this->profile = $profiles;
$this->theme = $themes;
} }
/** /**
...@@ -97,14 +74,4 @@ class ModifiedFiles implements ReadinessCheckerInterface { ...@@ -97,14 +74,4 @@ class ModifiedFiles implements ReadinessCheckerInterface {
return $messages; return $messages;
} }
/**
* Get the extension types.
*
* @return array
* The extension types.
*/
protected function getExtensionsTypes() {
return ['module', 'profile', 'theme'];
}
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\automatic_updates\Services; namespace Drupal\automatic_updates\Services;
use Composer\Semver\VersionParser; use Composer\Semver\VersionParser;
use Drupal\automatic_updates\ProjectInfoTrait;
use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
...@@ -20,6 +21,7 @@ use Psr\Log\LoggerInterface; ...@@ -20,6 +21,7 @@ use Psr\Log\LoggerInterface;
class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface { class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
use StringTranslationTrait; use StringTranslationTrait;
use DependencySerializationTrait; use DependencySerializationTrait;
use ProjectInfoTrait;
/** /**
* This module's configuration. * This module's configuration.
...@@ -49,27 +51,6 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface { ...@@ -49,27 +51,6 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
*/ */
protected $time; protected $time;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $module;
/**
* The profile extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $profile;
/**
* The theme extension list.
*
* @var \Drupal\Core\Extension\ExtensionList
*/
protected $theme;
/** /**
* The logger. * The logger.
* *
...@@ -88,24 +69,22 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface { ...@@ -88,24 +69,22 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
* The time service. * The time service.
* @param \GuzzleHttp\Client $client * @param \GuzzleHttp\Client $client
* The HTTP client. * The HTTP client.
* @param \Drupal\Core\Extension\ExtensionList $module * @param \Drupal\Core\Extension\ExtensionList $moduleList
* The module extension list. * The module extension list.
* @param \Drupal\Core\Extension\ExtensionList $profile * @param \Drupal\Core\Extension\ExtensionList $profileList
* The profile extension list. * The profile extension list.
* @param \Drupal\Core\Extension\ExtensionList $theme * @param \Drupal\Core\Extension\ExtensionList $themeList
* The theme extension list. * The theme extension list.
* @param \Psr\Log\LoggerInterface $logger * @param \Psr\Log\LoggerInterface $logger
* The logger. * The logger.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, CacheBackendInterface $cache, TimeInterface $time, Client $client, ExtensionList $module, ExtensionList $profile, ExtensionList $theme, LoggerInterface $logger) { public function __construct(ConfigFactoryInterface $config_factory, CacheBackendInterface $cache, TimeInterface $time, Client $client, ExtensionList $moduleList, ExtensionList $profileList, ExtensionList $themeList, LoggerInterface $logger) {
$this->config = $config_factory->get('automatic_updates.settings'); $this->config = $config_factory->get('automatic_updates.settings');
$this->cache = $cache; $this->cache = $cache;
$this->time = $time; $this->time = $time;
$this->httpClient = $client; $this->httpClient = $client;
$this->module = $module;
$this->profile = $profile;
$this->theme = $theme;
$this->logger = $logger; $this->logger = $logger;
$this->setExtensionLists($moduleList, $themeList, $profileList);
} }
/** /**
...@@ -175,11 +154,14 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface { ...@@ -175,11 +154,14 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
* TRUE if extension exists, else FALSE. * TRUE if extension exists, else FALSE.
*/ */
protected function isValidExtension($extension_type, $project_name) { protected function isValidExtension($extension_type, $project_name) {
if (!property_exists($this, $extension_type)) { try {
$this->logger->error('Extension list of type "%extension" does not exist.', ['%extension' => $extension_type]); $extension_list = $this->getExtensionList($extension_type);
return $extension_list->exists($project_name) && !empty($extension_list->getAllAvailableInfo()[$project_name]['version']);
}
catch (\UnexpectedValueException $exception) {
$this->logger->error($exception->getMessage());
return FALSE; return FALSE;
} }
return $this->{$extension_type}->exists($project_name) && !empty($this->{$extension_type}->getAllAvailableInfo()[$project_name]['version']);
} }
/** /**
...@@ -191,7 +173,7 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface { ...@@ -191,7 +173,7 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
* The JSON object. * The JSON object.
*/ */
protected function contribParser(array &$messages, $json) { protected function contribParser(array &$messages, $json) {
$extension_version = $this->{$json->type}->getAllAvailableInfo()[$json->project]['version']; $extension_version = $this->getExtensionList($json->type)->getAllAvailableInfo()[$json->project]['version'];
$json->insecure = array_filter(array_map(static function ($version) { $json->insecure = array_filter(array_map(static function ($version) {
$version_array = explode('-', $version, 2); $version_array = explode('-', $version, 2);
if ($version_array && $version_array[0] === \Drupal::CORE_COMPATIBILITY) { if ($version_array && $version_array[0] === \Drupal::CORE_COMPATIBILITY) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment