Skip to content

Commit

Permalink
Remove deprecated code. (#4324)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
LOBsTerr and simonf7 authored Nov 29, 2021
1 parent 21342d8 commit d292c94
Show file tree
Hide file tree
Showing 34 changed files with 109 additions and 81 deletions.
2 changes: 1 addition & 1 deletion config/services/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/services/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
28 changes: 3 additions & 25 deletions src/Command/Config/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/Command/Config/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/Command/Config/ExportSingleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/Config/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Create/CommentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Cron/ExecuteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
18 changes: 16 additions & 2 deletions src/Command/Debug/ModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}

Expand Down Expand Up @@ -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) ;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Debug/RestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Debug/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/Command/Debug/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Command/DotenvInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 12 additions & 3 deletions src/Command/Module/UninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -48,6 +49,11 @@ class UninstallCommand extends ContainerAwareCommand
*/
protected $extensionManager;

/**
* @var Drupal\Core\Extension\ModuleExtensionList
*/
protected $extensionList;

/**
* InstallCommand constructor.
*
Expand All @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Rest/EnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/Command/Shared/LocaleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 ];
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Command/Shared/ProjectDownloadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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{
Expand All @@ -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 = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Command/Test/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit d292c94

Please sign in to comment.