class DevelReinstallCommand
Same name in this branch
- 5.x src/Drush/Commands/DevelReinstallCommand.php \Drupal\devel\Drush\Commands\DevelReinstallCommand
Uninstalls modules and installs them again.
Attributes
#[AsCommand(name: self::NAME, description: 'Uninstall, and Install modules.', aliases: [
'dre',
'devel-reinstall',
], usages: [
'devel:reinstall devel_generate,webprofiler',
])]
Hierarchy
- class \Drupal\devel\Command\DevelReinstallCommand
Expanded class hierarchy of DevelReinstallCommand
3 files declare their use of DevelReinstallCommand
- DevelCommandsKernelTest.php in tests/
src/ Kernel/ DevelCommandsKernelTest.php - DevelReinstallCommand.php in src/
Drush/ Commands/ DevelReinstallCommand.php - DevelReinstallCommandTest.php in tests/
src/ Kernel/ DevelReinstallCommandTest.php
File
-
src/
Command/ DevelReinstallCommand.php, line 19
Namespace
Drupal\devel\CommandView source
class DevelReinstallCommand {
public const NAME = 'devel:reinstall';
public function __construct(protected readonly ModuleInstallerInterface $moduleInstaller, protected readonly ModuleHandlerInterface $moduleHandler) {
}
/**
* Uninstalls the modules and installs them again.
*/
public function __invoke(InputInterface $input, OutputInterface $output, #[Argument('A comma-separated list of module names.')] string $modules) : int {
$modules = array_values(array_filter(array_map(trim(...), explode(',', $modules))));
if ($modules === []) {
throw new \InvalidArgumentException('No modules specified.');
}
$missing = array_filter($modules, fn(string $module): bool => !$this->moduleHandler
->moduleExists($module));
if ($missing !== []) {
throw new \InvalidArgumentException(sprintf('Not installed: %s', implode(', ', $missing)));
}
$reasons = $this->moduleInstaller
->validateUninstall($modules);
if ($reasons !== []) {
$messages = [];
foreach ($reasons as $module => $module_reasons) {
$messages[] = $module . ': ' . implode(' ', array_map(strval(...), $module_reasons));
}
throw new \RuntimeException(sprintf('Unable to uninstall. %s', implode(' ', $messages)));
}
// Like the reinstall form, leave dependent modules alone.
$this->moduleInstaller
->uninstall($modules, FALSE);
$this->moduleInstaller
->install($modules, FALSE);
(new SymfonyStyle($input, $output))->success(sprintf('%s reinstalled.', implode(',', $modules)));
return Command::SUCCESS;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| DevelReinstallCommand::NAME | public | constant | |
| DevelReinstallCommand::__construct | public | function | |
| DevelReinstallCommand::__invoke | public | function | Uninstalls the modules and installs them again. |