Browse Source

[FEATURE] Add console command to enable all modules at once.

quickform
Adam Bukowski 4 years ago
parent
commit
42bb4c2039
4 changed files with 51 additions and 0 deletions
  1. +1
    -0
      console.php
  2. +37
    -0
      console/Modules/EnableAllModuleCommand.php
  3. +2
    -0
      console/Modules/ListModulesCommand.php
  4. +11
    -0
      include/module_manager.php

+ 1
- 0
console.php View File

@@ -26,6 +26,7 @@ $application->add(new \Epesi\Console\Modules\DisableModuleCommand());
$application->add(new \Epesi\Console\Modules\EnableModuleCommand());
$application->add(new \Epesi\Console\Modules\InstallModuleCommand());
$application->add(new \Epesi\Console\Modules\UninstallModuleCommand());
$application->add(new \Epesi\Console\Modules\EnableAllModuleCommand());
$application->add(new \Epesi\Console\CacheRebuildCommand());
$application->add(new \Epesi\Console\ThemeRebuildCommand());
$application->add(new \Epesi\Console\Maintenance\MaintenanceStatusCommand());


+ 37
- 0
console/Modules/EnableAllModuleCommand.php View File

@@ -0,0 +1,37 @@
<?php

namespace Epesi\Console\Modules;

use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class EnableAllModuleCommand extends Command
{
protected function configure()
{
$this
->setName('module:enable:all')
->setDescription('Enable all disabled modules')
->addOption('missing-files', 'f', InputOption::VALUE_NONE, 'Enable only those modules that were disabled because of missing files')
->addOption('disabled', 'd', InputOption::VALUE_NONE, 'Enable only those modules that were disabled by user')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$by_missing_files = $input->getOption('missing-files');
$by_user = $input->getOption('disabled');
if ($by_missing_files) {
ModuleManager::enable_modules(ModuleManager::MODULE_NOT_FOUND);
}
if ($by_user) {
ModuleManager::enable_modules(ModuleManager::MODULE_DISABLED);
}
if (!$by_missing_files && !$by_user) {
ModuleManager::enable_modules();
}
}
}

+ 2
- 0
console/Modules/ListModulesCommand.php View File

@@ -40,6 +40,8 @@ class ListModulesCommand extends Command
$state = "<fg=green>Active</fg=green>";
if ($module['state'] === (string)ModuleManager::MODULE_DISABLED)
$state = "<fg=yellow>Inactive</fg=yellow>";
if ($module['state'] === (string)ModuleManager::MODULE_NOT_FOUND)
$state = "<fg=cyan>Files Not Found</fg=cyan>";
if ($module['state'] === null)
$state = "<fg=red>Not installed</fg=red>";



+ 11
- 0
include/module_manager.php View File

@@ -1093,4 +1093,15 @@ class ModuleManager {
DB::Execute('UPDATE modules SET state=%d WHERE name=%s', array($state, $module));
Cache::clear();
}
public static function enable_modules($state = null)
{
$sql = 'UPDATE modules SET state=%d';
$args = array(ModuleManager::MODULE_ENABLED);
if ($state) {
$sql .= ' WHERE state=%d';
$args[] = $state;
}
DB::Execute($sql, $args);
}
}

Loading…
Cancel
Save