From d292c940c07d164e32bbe9525e909311ca65e8cb Mon Sep 17 00:00:00 2001 From: Nikolay Lobachev Date: Mon, 29 Nov 2021 18:09:44 +0100 Subject: [PATCH] Remove deprecated code. (#4324) * Feat: replace system_rebuild_module_data() * Feat: replace REQUEST_TIME * Feat: replace format_date() * Feat: remove update_fix_compatibility() https://www.drupal.org/node/3026100 * Feat: replace user_load() * Feat: replace CONFIG_SYNC_DIRECTORY * Feat: replace drupal_get_profile() * Feat: replace config_get_config_directory() * Feat: replace prepareLegacyRequest() * Feat: replace ResourcePluginManager->getInstance() * Feat: replace Drupal\simpletest\TestDiscovery * Feat: replace db_insert() * Fix: module installed detection using module_handler service * Remove the interaction part, because in Drupal 9 we have only one config folder. * Use imports of the classes instead of full classified name of the class. * Use dependency injection instead of direct call of \Drupal::service. * Use dependency injection instead of direct call of \Drupal::service in Uninstall command class. * Move vars outside loops. * Use dependency injection instead of direct call of \Drupal::service in Manager class. * Set Drupal console version 1.9.8. Co-authored-by: Simon --- config/services/debug.yml | 2 +- config/services/module.yml | 2 +- src/Application.php | 2 +- src/Command/Config/DiffCommand.php | 28 ++---------------- src/Command/Config/ExportCommand.php | 5 ++-- src/Command/Config/ExportSingleCommand.php | 3 +- src/Command/Config/ImportCommand.php | 3 +- src/Command/Create/CommentsCommand.php | 2 +- src/Command/Cron/ExecuteCommand.php | 2 +- src/Command/Debug/ModuleCommand.php | 18 ++++++++++-- src/Command/Debug/RestCommand.php | 2 +- src/Command/Debug/TestCommand.php | 2 +- src/Command/Debug/UpdateCommand.php | 1 - src/Command/DotenvInitCommand.php | 3 +- src/Command/Module/UninstallCommand.php | 15 ++++++++-- src/Command/Rest/EnableCommand.php | 2 +- src/Command/ServerCommand.php | 2 +- src/Command/Shared/LocaleTrait.php | 10 ++++--- src/Command/Shared/ProjectDownloadTrait.php | 6 ++-- src/Command/Test/RunCommand.php | 4 +-- src/Command/Update/ExecuteCommand.php | 1 - src/Command/User/CreateCommand.php | 2 +- src/Command/User/LoginUrlCommand.php | 2 +- src/Command/User/RoleCommand.php | 3 +- src/Extension/Manager.php | 29 +++++++++++++++---- src/Utils/Create/CommentData.php | 2 +- src/Utils/Create/NodeData.php | 4 +-- src/Utils/Create/UserData.php | 2 +- src/Utils/DrupalApi.php | 15 ++++++---- .../entity-content-revision-delete.php.twig | 4 +-- ...ntent-revision-revert-translation.php.twig | 2 +- .../entity-content-revision-revert.php.twig | 2 +- .../src/Plugin/Condition/condition.php.twig | 6 ++-- uninstall.services.yml | 2 +- 34 files changed, 109 insertions(+), 81 deletions(-) diff --git a/config/services/debug.yml b/config/services/debug.yml index 8ccd8b409..483b53dc5 100644 --- a/config/services/debug.yml +++ b/config/services/debug.yml @@ -67,7 +67,7 @@ services: - { name: drupal.command } console.module_debug: class: Drupal\Console\Command\Debug\ModuleCommand - arguments: ['@console.configuration_manager', '@console.site'] + arguments: ['@console.configuration_manager', '@console.site', '@extension.list.module'] tags: - { name: drupal.command } console.image_styles_debug: diff --git a/config/services/module.yml b/config/services/module.yml index 6d081eb13..ff0e2c64c 100644 --- a/config/services/module.yml +++ b/config/services/module.yml @@ -21,7 +21,7 @@ services: - { name: drupal.command } console.module_uninstall: class: Drupal\Console\Command\Module\UninstallCommand - arguments: ['@console.site','@module_installer', '@console.chain_queue', '@config.factory', '@console.extension_manager'] + arguments: ['@console.site','@module_installer', '@console.chain_queue', '@config.factory', '@console.extension_manager', '@extension.list.module'] tags: - { name: drupal.command } console.module_update: diff --git a/src/Application.php b/src/Application.php index 12ed78343..7eeec6f31 100644 --- a/src/Application.php +++ b/src/Application.php @@ -25,7 +25,7 @@ class Application extends BaseApplication /** * @var string */ - const VERSION = '1.9.7'; + const VERSION = '1.9.8'; public function __construct(ContainerInterface $container) { diff --git a/src/Command/Config/DiffCommand.php b/src/Command/Config/DiffCommand.php index c32881a3b..314fa538b 100644 --- a/src/Command/Config/DiffCommand.php +++ b/src/Command/Config/DiffCommand.php @@ -8,6 +8,7 @@ use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\StorageComparer; +use Drupal\Core\Site\Settings; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -78,36 +79,13 @@ protected function configure() )->setAliases(['cdi']); } - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - global $config_directories; - - $directory = $input->getArgument('directory'); - if (!$directory) { - $directory = $this->getIo()->choice( - $this->trans('commands.config.diff.questions.directories'), - $config_directories, - CONFIG_SYNC_DIRECTORY - ); - - $input->setArgument('directory', $config_directories[$directory]); - } - } - /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { - global $config_directories; - $directory = $input->getArgument('directory') ?: CONFIG_SYNC_DIRECTORY; - if (array_key_exists($directory, $config_directories)) { - $directory = $config_directories[$directory]; - } - $source_storage = new FileStorage($directory); + $config_directory = Settings::get('config_sync_directory'); + $source_storage = new FileStorage($config_directory); if ($input->getOption('reverse')) { $config_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager); diff --git a/src/Command/Config/ExportCommand.php b/src/Command/Config/ExportCommand.php index 63d004e5d..74fb56cfc 100644 --- a/src/Command/Config/ExportCommand.php +++ b/src/Command/Config/ExportCommand.php @@ -11,6 +11,7 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\StorageInterface; +use Drupal\Core\Site\Settings; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -83,7 +84,7 @@ protected function interact(InputInterface $input, OutputInterface $output) if (!$input->getOption('directory')) { $directory = $this->getIo()->ask( $this->trans('commands.config.export.questions.directory'), - config_get_config_directory(CONFIG_SYNC_DIRECTORY) + Settings::get('config_sync_directory') ); $input->setOption('directory', $directory); } @@ -102,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $drupal_root = $this->drupalFinder->getComposerRoot(); if (!$directory) { - $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); + $directory = Settings::get('config_sync_directory') ; } $fileSystem = new Filesystem(); diff --git a/src/Command/Config/ExportSingleCommand.php b/src/Command/Config/ExportSingleCommand.php index 0fe2607b3..2f55810ed 100644 --- a/src/Command/Config/ExportSingleCommand.php +++ b/src/Command/Config/ExportSingleCommand.php @@ -8,6 +8,7 @@ namespace Drupal\Console\Command\Config; use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Site\Settings; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -304,7 +305,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - $directory = $directory_copy = config_get_config_directory(CONFIG_SYNC_DIRECTORY); + $directory = $directory_copy = Settings::get('config_sync_directory') ; if (!is_dir($directory)) { if ($value) { $directory = $directory_copy .'/' . str_replace('.', '/', $value); diff --git a/src/Command/Config/ImportCommand.php b/src/Command/Config/ImportCommand.php index 68d8f210d..554ed456d 100644 --- a/src/Command/Config/ImportCommand.php +++ b/src/Command/Config/ImportCommand.php @@ -6,6 +6,7 @@ namespace Drupal\Console\Command\Config; +use Drupal\Core\Site\Settings; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -87,7 +88,7 @@ protected function interact(InputInterface $input, OutputInterface $output) if (!$input->getOption('directory')) { $directory = $this->getIo()->ask( $this->trans('commands.config.import.questions.directory'), - config_get_config_directory(CONFIG_SYNC_DIRECTORY) + Settings::get('config_sync_directory') ); $input->setOption('directory', $directory); } diff --git a/src/Command/Create/CommentsCommand.php b/src/Command/Create/CommentsCommand.php index 656d3969f..481d806bf 100644 --- a/src/Command/Create/CommentsCommand.php +++ b/src/Command/Create/CommentsCommand.php @@ -130,7 +130,7 @@ protected function interact(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output) { $nodeId = $input->getArgument('node-id')?:1; - $node = \Drupal\node\Entity\Node::load($nodeId); + $node = Node::load($nodeId); if (empty($node)) { throw new \InvalidArgumentException( $this->trans( diff --git a/src/Command/Cron/ExecuteCommand.php b/src/Command/Cron/ExecuteCommand.php index dd00ac9e3..0ef8ac815 100644 --- a/src/Command/Cron/ExecuteCommand.php +++ b/src/Command/Cron/ExecuteCommand.php @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - $this->state->set('system.cron_last', REQUEST_TIME); + $this->state->set('system.cron_last', \Drupal::time()->getRequestTime()); $this->lock->release('cron'); $this->getIo()->success($this->trans('commands.cron.execute.messages.success')); diff --git a/src/Command/Debug/ModuleCommand.php b/src/Command/Debug/ModuleCommand.php index e9835606f..dd53c4b1c 100644 --- a/src/Command/Debug/ModuleCommand.php +++ b/src/Command/Debug/ModuleCommand.php @@ -14,6 +14,7 @@ use Drupal\Console\Core\Command\Command; use Drupal\Console\Utils\Site; use Drupal\Console\Core\Utils\ConfigurationManager; +use Drupal\Core\Extension\ModuleExtensionList; class ModuleCommand extends Command { @@ -27,18 +28,31 @@ class ModuleCommand extends Command */ protected $site; + /** + * @var Site + */ + protected $module; + + /** + * @var Drupal\Core\Extension\ModuleExtensionList + */ + protected $extensionList; + /** * ChainDebugCommand constructor. * * @param ConfigurationManager $configurationManager * @param Site $site + * @param ModuleExtensionList $extensionList */ public function __construct( ConfigurationManager $configurationManager, - Site $site + Site $site, + ModuleExtensionList $extensionList ) { $this->configurationManager = $configurationManager; $this->site = $site; + $this->extensionList = $extensionList; parent::__construct(); } @@ -117,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getModules($status, $type, $modules) { $result = []; - $modulesData = system_rebuild_module_data(); + $modulesData = $this->extensionList->reset()->getList(); if(!$modules) { $modules = array_keys($modulesData) ; diff --git a/src/Command/Debug/RestCommand.php b/src/Command/Debug/RestCommand.php index 527051f90..a8f3726d9 100644 --- a/src/Command/Debug/RestCommand.php +++ b/src/Command/Debug/RestCommand.php @@ -89,7 +89,7 @@ private function restDetail($resource_id) { $config = $this->getRestDrupalConfig(); - $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); + $plugin = $this->pluginManagerRest->createInstance($resource_id); if (empty($plugin)) { $this->getIo()->error( diff --git a/src/Command/Debug/TestCommand.php b/src/Command/Debug/TestCommand.php index 266276311..00275af3f 100644 --- a/src/Command/Debug/TestCommand.php +++ b/src/Command/Debug/TestCommand.php @@ -14,7 +14,7 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Console\Core\Command\Command; use Drupal\Console\Annotations\DrupalCommand; -use Drupal\simpletest\TestDiscovery; +use Drupal\Core\Test\TestDiscovery; /** * @DrupalCommand( diff --git a/src/Command/Debug/UpdateCommand.php b/src/Command/Debug/UpdateCommand.php index 6f24765d6..2d8670851 100644 --- a/src/Command/Debug/UpdateCommand.php +++ b/src/Command/Debug/UpdateCommand.php @@ -63,7 +63,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->site->loadLegacyFile('/core/includes/install.inc'); drupal_load_updates(); - update_fix_compatibility(); $requirements = update_check_requirements(); $severity = drupal_requirements_severity($requirements); diff --git a/src/Command/DotenvInitCommand.php b/src/Command/DotenvInitCommand.php index 84e5346b3..a9c1048f5 100644 --- a/src/Command/DotenvInitCommand.php +++ b/src/Command/DotenvInitCommand.php @@ -2,6 +2,7 @@ namespace Drupal\Console\Command; +use Drupal\Core\Site\Settings; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -125,7 +126,7 @@ protected function copySettingsFile(Filesystem $fs) include_once $this->drupalFinder->getDrupalRoot() . '/core/includes/install.inc'; $settings['config_directories'] = [ - CONFIG_SYNC_DIRECTORY => (object) [ + Settings::get('config_sync_directory') => (object) [ 'value' => Path::makeRelative( $this->drupalFinder->getComposerRoot() . '/config/sync', $this->drupalFinder->getDrupalRoot() diff --git a/src/Command/Module/UninstallCommand.php b/src/Command/Module/UninstallCommand.php index 51014ce6c..12b5e0cd7 100755 --- a/src/Command/Module/UninstallCommand.php +++ b/src/Command/Module/UninstallCommand.php @@ -18,6 +18,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Drupal\Core\Extension\ModuleExtensionList; class UninstallCommand extends ContainerAwareCommand { @@ -48,6 +49,11 @@ class UninstallCommand extends ContainerAwareCommand */ protected $extensionManager; + /** + * @var Drupal\Core\Extension\ModuleExtensionList + */ + protected $extensionList; + /** * InstallCommand constructor. * @@ -56,19 +62,22 @@ class UninstallCommand extends ContainerAwareCommand * @param ChainQueue $chainQueue * @param ConfigFactory $configFactory * @param Manager $extensionManager + * @param ModuleExtensionList $extensionList */ public function __construct( Site $site, ModuleInstallerInterface $moduleInstaller, ChainQueue $chainQueue, ConfigFactoryInterface $configFactory, - Manager $extensionManager + Manager $extensionManager, + ModuleExtensionList $extensionList ) { $this->site = $site; $this->moduleInstaller = $moduleInstaller; $this->chainQueue = $chainQueue; $this->configFactory = $configFactory; $this->extensionManager = $extensionManager; + $this->extensionList = $extensionList; parent::__construct(); } @@ -124,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $coreExtension = $this->configFactory->getEditable('core.extension'); // Get info about modules available - $moduleData = system_rebuild_module_data(); + $moduleData = $this->extensionList->reset()->getList(); $moduleList = array_combine($module, $module); if ($composer) { @@ -175,7 +184,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // to core yet so we need to check if it exists. $profiles = \Drupal::service('profile_handler')->getProfileInheritance(); } else { - $profiles[drupal_get_profile()] = []; + $profiles[\Drupal::installProfile()] = []; } $dependencies = []; diff --git a/src/Command/Rest/EnableCommand.php b/src/Command/Rest/EnableCommand.php index b4829759f..4f1320d30 100644 --- a/src/Command/Rest/EnableCommand.php +++ b/src/Command/Rest/EnableCommand.php @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $input->setArgument('resource-id', $resource_id); // Calculate states available by resource and generate the question. - $plugin = $this->pluginManagerRest->getInstance(['id' => $resource_id]); + $plugin = $this->pluginManagerRest->createInstance($resource_id); $methods = $plugin->availableMethods(); $method = $this->getIo()->choice( diff --git a/src/Command/ServerCommand.php b/src/Command/ServerCommand.php index 92b17d58b..ef8ab25c2 100644 --- a/src/Command/ServerCommand.php +++ b/src/Command/ServerCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Process\ProcessBuilder; use Symfony\Component\Process\PhpExecutableFinder; use Drupal\Console\Core\Command\Command; -use \Drupal\Console\Core\Utils\ConfigurationManager; +use Drupal\Console\Core\Utils\ConfigurationManager; /** * Class ServerCommand diff --git a/src/Command/Shared/LocaleTrait.php b/src/Command/Shared/LocaleTrait.php index 5042dd236..f7b700dc0 100644 --- a/src/Command/Shared/LocaleTrait.php +++ b/src/Command/Shared/LocaleTrait.php @@ -62,14 +62,16 @@ protected function projectsStatus() { $status_report = []; $status = locale_translation_get_status(); - foreach ($status as $project_id => $project) { + $date_formatter = \Drupal::service('date.formatter'); + $date_format = 'html_date'; + foreach ($status as $project) { foreach ($project as $langcode => $project_info) { $info = ''; if ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) { $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : null; $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : null; - $local_age = $local->timestamp? format_date($local->timestamp, 'html_date'): ''; - $remote_age = $remote->timestamp? format_date($remote->timestamp, 'html_date'): ''; + $local_age = $local->timestamp? $date_formatter->format($local->timestamp, $date_format): ''; + $remote_age = $remote->timestamp? $date_formatter->format($remote->timestamp, $date_format): ''; if ($local_age >= $remote_age) { $info = $this->trans('commands.locale.translation.status.messages.translation-project-updated'); @@ -84,7 +86,7 @@ protected function projectsStatus() $info = $this->createInfoString($project_info); } - $status_report[$langcode][] = [$project_info->name, $project_info->version, $local_age, $remote_age ,$info ]; + $status_report[$langcode][] = [$project_info->name, $project_info->version, $local_age, $remote_age, $info ]; } } diff --git a/src/Command/Shared/ProjectDownloadTrait.php b/src/Command/Shared/ProjectDownloadTrait.php index c0eb841af..8dda3f2b0 100644 --- a/src/Command/Shared/ProjectDownloadTrait.php +++ b/src/Command/Shared/ProjectDownloadTrait.php @@ -128,7 +128,7 @@ private function downloadModules($modules, $latest, $path = null, $resultList = return $this->downloadModules($dependencies, $latest, $path, $resultList); } - + private function downloadThemes($themes, $latest, $path = null, $resultList = []) { if (!$resultList) { @@ -164,7 +164,7 @@ private function downloadThemes($themes, $latest, $path = null, $resultList = [] $this->themeHandler->install($themes); $unInstalledThemes = $this->validator->getUninstalledThemes($themes); - + if (!$unInstalledThemes) { return 0; }else{ @@ -175,7 +175,7 @@ private function downloadThemes($themes, $latest, $path = null, $resultList = [] protected function calculateDependencies($modules) { $this->site->loadLegacyFile('/core/modules/system/system.module'); - $moduleList = system_rebuild_module_data(); + $moduleList = \Drupal::service('extension.list.module')->reset()->getList(); $dependencies = []; diff --git a/src/Command/Test/RunCommand.php b/src/Command/Test/RunCommand.php index feefd6b93..885de94e2 100644 --- a/src/Command/Test/RunCommand.php +++ b/src/Command/Test/RunCommand.php @@ -15,7 +15,7 @@ use Drupal\Console\Core\Command\Command; use Drupal\Console\Annotations\DrupalCommand; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\simpletest\TestDiscovery; +use Drupal\Core\Test\TestDiscovery; use Drupal\Core\Datetime\DateFormatter; /** @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->setEnvironment($url); // Create simpletest test id - $testId = db_insert('simpletest_test_id') + $testId = Database::getConnection()->insert('simpletest_test_id') ->useDefaults(['test_id']) ->execute(); diff --git a/src/Command/Update/ExecuteCommand.php b/src/Command/Update/ExecuteCommand.php index 7d652f671..71527f9c2 100644 --- a/src/Command/Update/ExecuteCommand.php +++ b/src/Command/Update/ExecuteCommand.php @@ -127,7 +127,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->site->loadLegacyFile('/core/includes/update.inc'); drupal_load_updates(); - update_fix_compatibility(); $start = $this->getUpdates($this->module!=='all'?$this->module:null); $updates = update_resolve_dependencies($start); diff --git a/src/Command/User/CreateCommand.php b/src/Command/User/CreateCommand.php index 6a14e7b42..237f28c71 100644 --- a/src/Command/User/CreateCommand.php +++ b/src/Command/User/CreateCommand.php @@ -235,7 +235,7 @@ private function createUser($username, $password, $roles, $email = null, $status 'pass' => $password?:user_password(), 'status' => $status, 'roles' => $roles, - 'created' => REQUEST_TIME, + 'created' => \Drupal::time()->getRequestTime(), ] ); diff --git a/src/Command/User/LoginUrlCommand.php b/src/Command/User/LoginUrlCommand.php index 8906b1a0a..ae3a4bff4 100644 --- a/src/Command/User/LoginUrlCommand.php +++ b/src/Command/User/LoginUrlCommand.php @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) //validate if https is on uri $regx = '/^https:.*/s'; if(preg_match($regx, $input->getOption('uri'))){ - $timestamp = REQUEST_TIME; + $timestamp = \Drupal::time()->getRequestTime(); $langcode = $userEntity->getPreferredLangcode(); $url = Url::fromRoute('user.reset', [ diff --git a/src/Command/User/RoleCommand.php b/src/Command/User/RoleCommand.php index 71d618aaf..83ff01317 100644 --- a/src/Command/User/RoleCommand.php +++ b/src/Command/User/RoleCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Drupal\Console\Core\Command\Command; use Drupal\Console\Utils\DrupalApi; +use Drupal\user\Entity\User; /** * Class DebugCommand @@ -79,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $systemRoles = $this->drupalApi->getRoles(); if (is_numeric($user)) { - $userObject = user_load($user); + $userObject = User::load($user); } else { $userObject = user_load_by_name($user); } diff --git a/src/Extension/Manager.php b/src/Extension/Manager.php index f06f008ed..19e4d4a74 100644 --- a/src/Extension/Manager.php +++ b/src/Extension/Manager.php @@ -5,7 +5,9 @@ use Drupal\Console\Utils\Site; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; -use Drupal\Core\Extension\ModuleExtensionList; +use Drupal\Core\Extension\ModuleExtensionList; +use Drupal\Core\Extension\ThemeHandler; +use Drupal\Core\Extension\ModuleHandlerInterface; /** * Class ExtensionManager @@ -49,6 +51,16 @@ class Manager */ private $extensionList; + /** + * @var ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * @var ThemeHandler + */ + protected $themeHandler; + /** * ExtensionManager constructor. * @@ -56,17 +68,23 @@ class Manager * @param Client $httpClient * @param string $appRoot * @param ModuleExtensionList $extensionList + * @param ModuleHandlerInterface $moduleHandler + * @param ThemeHandler $themeHandler */ public function __construct( Site $site, Client $httpClient, $appRoot, - ModuleExtensionList $extensionList + ModuleExtensionList $extensionList, + ModuleHandlerInterface $moduleHandler, + ThemeHandler $themeHandler ) { $this->site = $site; $this->httpClient = $httpClient; $this->appRoot = $appRoot; $this->extensionList = $extensionList; + $this->moduleHandler = $moduleHandler; + $this->themeHandler = $themeHandler; $this->initialize(); } @@ -200,8 +218,8 @@ private function getExtensions( foreach ($this->extensions[$type] as $extension) { $name = $extension->getName(); - $isInstalled = false; - if (property_exists($extension, 'status')) { + $isInstalled = $type=='module' && $this->moduleHandler->moduleExists($name); + if (!$isInstalled && property_exists($extension, 'status')) { $isInstalled = ($extension->status)?true:false; } if (!$showInstalled && $isInstalled) { @@ -236,8 +254,7 @@ private function discoverExtensions($type) } if ($type === 'theme') { - $themeHandler = \Drupal::service('theme_handler'); - $themeHandler->rebuildThemeData(); + $this->themeHandler->rebuildThemeData(); } /* diff --git a/src/Utils/Create/CommentData.php b/src/Utils/Create/CommentData.php index 3d9a1f8d6..f9857fca7 100644 --- a/src/Utils/Create/CommentData.php +++ b/src/Utils/Create/CommentData.php @@ -41,7 +41,7 @@ public function create( 'entity_id' => $nid, 'entity_type' => 'node', 'field_name' => 'comment', - 'created' => REQUEST_TIME - mt_rand(0, $timeRange), + 'created' => \Drupal::time()->getRequestTime() - mt_rand(0, $timeRange), 'uid' => $this->getUserID(), 'status' => true, 'subject' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true), diff --git a/src/Utils/Create/NodeData.php b/src/Utils/Create/NodeData.php index 4d1e98dcc..f25134678 100644 --- a/src/Utils/Create/NodeData.php +++ b/src/Utils/Create/NodeData.php @@ -45,7 +45,7 @@ public function create( [ 'nid' => null, 'type' => $contentType, - 'created' => REQUEST_TIME - mt_rand(0, $timeRange), + 'created' => \Drupal::time()->getRequestTime() - mt_rand(0, $timeRange), 'uid' => $this->getUserID(), 'title' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true), 'revision' => mt_rand(0, 1), @@ -90,7 +90,7 @@ private function addRevision($node, $count) { $node->setTitle($this->getRandom()->sentences(mt_rand(1, 5), true)); $node->setNewRevision(TRUE); $node->revision_log = "Revision number $count was created"; - $node->setRevisionCreationTime(REQUEST_TIME); + $node->setRevisionCreationTime(\Drupal::time()->getRequestTime()); $node->save(); } } diff --git a/src/Utils/Create/UserData.php b/src/Utils/Create/UserData.php index 51a66d78b..9208c943b 100644 --- a/src/Utils/Create/UserData.php +++ b/src/Utils/Create/UserData.php @@ -47,7 +47,7 @@ public function create( 'pass' => $password?:$this->getRandom()->word(mt_rand(8, 16)), 'status' => mt_rand(0, 1), 'roles' => $roles[array_rand($roles)], - 'created' => REQUEST_TIME - mt_rand(0, $timeRange), + 'created' => \Drupal::time()->getRequestTime() - mt_rand(0, $timeRange), ] ); diff --git a/src/Utils/DrupalApi.php b/src/Utils/DrupalApi.php index 6ac8da514..659e0cf49 100644 --- a/src/Utils/DrupalApi.php +++ b/src/Utils/DrupalApi.php @@ -8,8 +8,11 @@ namespace Drupal\Console\Utils; use Drupal\Core\Cache\Cache; +use Drupal\Core\DrupalKernel; +use Drupal\Core\PhpStorage\PhpStorageFactory; use Symfony\Component\DomCrawler\Crawler; use GuzzleHttp\Client; +use Symfony\Component\HttpFoundation\Request; /** * Class DrupalHelper @@ -239,12 +242,12 @@ public function downloadFile($url, $destination) * * @param \Composer\Autoload\ClassLoader $class_loader * The class loader. - * @param \Symfony\Component\HttpFoundation\Request $request + * @param Request $request * The current request. * * @see rebuild.php */ - public function drupal_rebuild($class_loader, \Symfony\Component\HttpFoundation\Request $request) + public function drupal_rebuild($class_loader, Request $request) { // Remove Drupal's error and exception handlers; they rely on a working // service container and other subsystems and will only cause a fatal error @@ -253,16 +256,18 @@ public function drupal_rebuild($class_loader, \Symfony\Component\HttpFoundation\ restore_exception_handler(); // Force kernel to rebuild php cache. - \Drupal\Core\PhpStorage\PhpStorageFactory::get('twig')->deleteAll(); + PhpStorageFactory::get('twig')->deleteAll(); // Bootstrap up to where caches exist and clear them. - $kernel = new \Drupal\Core\DrupalKernel('prod', $class_loader); - $kernel->setSitePath(\Drupal\Core\DrupalKernel::findSitePath($request)); + $kernel = new DrupalKernel('prod', $class_loader); + $kernel->setSitePath(DrupalKernel::findSitePath($request)); // Invalidate the container. $kernel->invalidateContainer(); // Prepare a NULL request. + $kernel->boot(); + $kernel->preHandle($request); if (method_exists($kernel, 'prepareLegacyRequest')) { $kernel->prepareLegacyRequest($request); } diff --git a/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig b/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig index 20352b2dc..dbada2162 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-delete.php.twig @@ -66,7 +66,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock % */ public function getQuestion() { return $this->t('Are you sure you want to delete the revision from %revision-date?', [ - '%revision-date' => format_date($this->revision->getRevisionCreationTime()), + '%revision-date' => \Drupal::service('date.formatter')->format($this->revision->getRevisionCreationTime()), ]); } @@ -101,7 +101,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock % $this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId()); $this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); - $this->messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()])); + $this->messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => \Drupal::service('date.formatter')->format($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()])); $form_state->setRedirect( 'entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $this->revision->id()] diff --git a/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig b/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig index b31d29eff..1037a1bde 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-revert-translation.php.twig @@ -98,7 +98,7 @@ class {{ entity_class }}RevisionRevertTranslationForm extends {{ entity_class }} $latest_revision_translation->setNewRevision(); $latest_revision_translation->isDefaultRevision(TRUE); - $revision->setRevisionCreationTime(REQUEST_TIME); + $revision->setRevisionCreationTime(\Drupal::time()->getRequestTime()); return $latest_revision_translation; } diff --git a/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig b/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig index 53ceef0b8..c16522df8 100644 --- a/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig +++ b/templates/module/src/Entity/Form/entity-content-revision-revert.php.twig @@ -138,7 +138,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock % protected function prepareRevertedRevision({{ entity_class }}Interface $revision, FormStateInterface $form_state) { $revision->setNewRevision(); $revision->isDefaultRevision(TRUE); - $revision->setRevisionCreationTime(REQUEST_TIME); + $revision->setRevisionCreationTime(\Drupal::time()->getRequestTime()); return $revision; } diff --git a/templates/module/src/Plugin/Condition/condition.php.twig b/templates/module/src/Plugin/Condition/condition.php.twig index be455a444..288183991 100644 --- a/templates/module/src/Plugin/Condition/condition.php.twig +++ b/templates/module/src/Plugin/Condition/condition.php.twig @@ -42,7 +42,7 @@ class {{ class_name }} extends ConditionPluginBase {% endblock %} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { // Sort all modules by their names. - $modules = system_rebuild_module_data(); + $modules = \Drupal::service('extension.list.module')->getList(); uasort($modules, 'system_sort_modules_by_info_name'); $options = [NULL => t('Select a module')]; @@ -88,7 +88,7 @@ class {{ class_name }} extends ConditionPluginBase {% endblock %} } $module = $this->configuration['module']; - $modules = system_rebuild_module_data(); + $modules = \Drupal::service('extension.list.module')->getList(); return $modules[$module]->status; } @@ -98,7 +98,7 @@ class {{ class_name }} extends ConditionPluginBase {% endblock %} */ public function summary() { $module = $this->getContextValue('module'); - $modules = system_rebuild_module_data(); + $modules = \Drupal::service('extension.list.module')->getList(); $status = ($modules[$module]->status)?t('enabled'):t('disabled'); diff --git a/uninstall.services.yml b/uninstall.services.yml index 3f4a5a10e..0b6fb832b 100644 --- a/uninstall.services.yml +++ b/uninstall.services.yml @@ -4,7 +4,7 @@ services: arguments: ['@app.root', '@console.configuration_manager'] console.extension_manager: class: Drupal\Console\Extension\Manager - arguments: ['@console.site', '@http_client', '@app.root', '@extension.list.module'] + arguments: ['@console.site', '@http_client', '@app.root', '@extension.list.module', '@module_handler', '@theme_handler'] # Commands console.server: class: Drupal\Console\Command\ServerCommand