Browse Source

Console first commit

quickform
Paweł Jedwabny 5 years ago
parent
commit
9e0a1eaa18
11 changed files with 521 additions and 2 deletions
  1. +5
    -1
      composer.json
  2. +120
    -1
      composer.lock
  3. +72
    -0
      console.php
  4. +28
    -0
      console/CacheRebuildCommand.php
  5. +30
    -0
      console/Maintenance/MaintenanceStatusCommand.php
  6. +44
    -0
      console/Modules/DisableModuleCommand.php
  7. +46
    -0
      console/Modules/EnableModuleCommand.php
  8. +47
    -0
      console/Modules/InstallModuleCommand.php
  9. +51
    -0
      console/Modules/ListModulesCommand.php
  10. +47
    -0
      console/Modules/UninstallModuleCommand.php
  11. +31
    -0
      console/ThemeRebuildCommand.php

+ 5
- 1
composer.json View File

@@ -1,6 +1,10 @@
{
"require": {
"pimple/pimple": "^3.0",
"twig/twig": "^1.24"
"twig/twig": "^1.24",
"symfony/console": "^2.7"
},
"autoload": {
"psr-4": {"Epesi\\Console\\": "console/"}
}
}

+ 120
- 1
composer.lock View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "035e66de727b9972117e6e790e0cc29f",
"hash": "4dd8f565f30959ca3223cf0a171dce3d",
"packages": [
{
"name": "pimple/pimple",
@@ -53,6 +53,125 @@
"time": "2015-09-11 15:10:35"
},
{
"name": "symfony/console",
"version": "v2.8.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/console.git",
"reference": "d0239fb42f98dd02e7d342f793c5d2cdee0c478d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/d0239fb42f98dd02e7d342f793c5d2cdee0c478d",
"reference": "d0239fb42f98dd02e7d342f793c5d2cdee0c478d",
"shasum": ""
},
"require": {
"php": ">=5.3.9",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1|~3.0.0",
"symfony/process": "~2.1|~3.0.0"
},
"suggest": {
"psr/log": "For using the console logger",
"symfony/event-dispatcher": "",
"symfony/process": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Console Component",
"homepage": "https://symfony.com",
"time": "2016-01-14 08:33:16"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "1289d16209491b584839022f29257ad859b8532d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/1289d16209491b584839022f29257ad859b8532d",
"reference": "1289d16209491b584839022f29257ad859b8532d",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2016-01-20 09:13:37"
},
{
"name": "twig/twig",
"version": "v1.24.0",
"source": {


+ 72
- 0
console.php View File

@@ -0,0 +1,72 @@
#!/usr/bin/env php
<?php
// application.php

define('SET_SESSION', false);
require 'include.php';

use Epesi\Console\CacheRebuildCommand;
use Epesi\Console\Maintenance\MaintenanceStatusCommand;
use Epesi\Console\Modules\InstallModuleCommand;
use Epesi\Console\Modules\UninstallModuleCommand;
use Epesi\Console\ThemeRebuildCommand;
use Symfony\Component\Console\Application;
use Epesi\Console\Modules\ListModulesCommand;
use Epesi\Console\Modules\DisableModuleCommand;
use Epesi\Console\Modules\EnableModuleCommand;

class ModuleLoader {
const all_modules = ':all:';

private $lpa;
private $lpa_count;
private $lpa_index = 0;
private $loaded_modules = array();
private $initialized = false;

private function init() {
if (!$this->initialized) {
$this->initialized = true;
$this->lpa = ModuleManager::get_load_priority_array();
$this->lpa_count = count($this->lpa);
ModulesAutoloader::enable();
}
}

function load($modules) {
$this->init();

if (!is_array($modules))
$modules = array($modules);

foreach ($modules as $m) {
if (array_key_exists($m, ModuleManager::$modules))
continue;

while ($this->lpa_index < $this->lpa_count) {
$row = $this->lpa[$this->lpa_index++];
$module = $row['name'];
$version = $row['version'];
ModuleManager :: include_common($module, $version);
ModuleManager :: register($module, $version, ModuleManager::$modules);
if ($m != self::all_modules && $module == $m)
break;
}
}
}

}

(new ModuleLoader())->load(array('Base_User', 'Base_User_Login', 'Base_Acl', 'Base_User_Settings'));


$application = new Application();
$application->add(new ListModulesCommand());
$application->add(new DisableModuleCommand());
$application->add(new EnableModuleCommand());
$application->add(new CacheRebuildCommand());
$application->add(new ThemeRebuildCommand());
$application->add(new MaintenanceStatusCommand());
$application->add(new InstallModuleCommand());
$application->add(new UninstallModuleCommand());
$application->run();

+ 28
- 0
console/CacheRebuildCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console;
use Cache;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CacheRebuildCommand extends Command
{
protected function configure(){
$this
->setName('cache:rebuild')
->setDescription('Rebuild EPESI common cache')
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
Cache::clear();
}
}

+ 30
- 0
console/Maintenance/MaintenanceStatusCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Maintenance;
use DB;
use MaintenanceMode;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MaintenanceStatusCommand extends Command
{
protected function configure(){
$this
->setName('maintenance:status')
->setDescription('Get status of EPESI maintenance mode')
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$status = MaintenanceMode::is_on() ? '<fg=green>enabled</fg=green>' : '<fg=red>disabled</fg=red>';
$output->writeln("Maintenance mode status: $status");
}
}

+ 44
- 0
console/Modules/DisableModuleCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Modules;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DisableModuleCommand extends Command
{
protected function configure(){
$this
->setName('module:disable')
->setDescription('Disable EPESI module')
->addArgument(
'name',
InputArgument::REQUIRED,
'Module name'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$module_name = $input->getArgument('name');
$module = DB::GetRow("SELECT * FROM modules WHERE name = '$module_name'");
if(!$module)
throw new \Exception('Module not found');

if ($module['state'] == ModuleManager::MODULE_DISABLED){
$output->writeln('<fg=yellow>Module ' . $module_name . ' already disabled</fg=yellow>');
return;
}

ModuleManager::set_module_state($module['name'], ModuleManager::MODULE_DISABLED);
$output->writeln('<fg=green>Module ' . $module_name . ' disabled</fg=green>');
}
}

+ 46
- 0
console/Modules/EnableModuleCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Modules;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class EnableModuleCommand extends Command
{
protected function configure(){
$this
->setName('module:enable')
->setDescription('Enable EPESI module')
->addArgument(
'name',
InputArgument::REQUIRED,
'Module name'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$module_name = $input->getArgument('name');
$module = DB::GetRow("SELECT * FROM modules WHERE name = '$module_name'");

if(!$module)
throw new \Exception('Module not found');

if ($module['state'] == ModuleManager::MODULE_ENABLED){
$output->writeln('<fg=yellow>Module ' . $module_name . ' already enabled</fg=yellow>');
return;
}

ModuleManager::set_module_state($module['name'], ModuleManager::MODULE_ENABLED);
$output->writeln('<fg=green>Module ' . $module_name . ' enabled</fg=green>');
}
}

+ 47
- 0
console/Modules/InstallModuleCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Modules;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class InstallModuleCommand extends Command
{
protected function configure(){
$this
->setName('module:install')
->setDescription('Install EPESI module')
->addArgument(
'name',
InputArgument::REQUIRED,
'Module name'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$module_name = $input->getArgument('name');
$module = DB::GetRow("SELECT * FROM available_modules WHERE name = '$module_name'");
if(!$module)
throw new \Exception('Module not found');

if (ModuleManager::is_installed($module['name']) !== -1) {
$output->writeln('<fg=yellow>Module ' . $module_name . ' already installed</fg=yellow>');
return;
}

if (ModuleManager::install($module['name'])) {
$output->writeln('<fg=green>Module ' . $module_name . ' installed</fg=green>');
} else {
$output->writeln('<fg=red>Module ' . $module_name . ' installing error</fg=red>');
}
}
}

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

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Modules;

use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ListModulesCommand extends Command
{
protected function configure()
{
$this
->setName('module:list')
->setDescription('List EPESI modules')
->addOption('installed-only');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('installed-only'))
$modules = DB::GetAssoc('SELECT available_modules.name, available_modules.version, modules.state FROM available_modules LEFT JOIN modules ON modules.name=available_modules.name where state is NOT NULL');
else
$modules = DB::GetAssoc('SELECT available_modules.name, available_modules.version, modules.state FROM available_modules LEFT JOIN modules ON modules.name=available_modules.name');

$table = new Table($output);
$table->setHeaders(array('<fg=white;options=bold>Name</fg=white;options=bold>', '<fg=white;options=bold>Version</fg=white;options=bold>', '<fg=white;options=bold>State</fg=white;options=bold>'));
foreach ($modules as $module) {

if ($module['state'] === (string)ModuleManager::MODULE_ENABLED)
$state = "<fg=green>Active</fg=green>";
if ($module['state'] === (string)ModuleManager::MODULE_DISABLED)
$state = "<fg=yellow>Inactive</fg=yellow>";
if ($module['state'] === null)
$state = "<fg=red>Not installed</fg=red>";

$table->addRow(array($module['name'], $module['version'], $state));
}

$table->render();
}
}

+ 47
- 0
console/Modules/UninstallModuleCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console\Modules;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class UninstallModuleCommand extends Command
{
protected function configure(){
$this
->setName('module:uninstall')
->setDescription('Uninstall EPESI module')
->addArgument(
'name',
InputArgument::REQUIRED,
'Module name'
)
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$module_name = $input->getArgument('name');
$module = DB::GetRow("SELECT * FROM available_modules WHERE name = '$module_name'");
if(!$module)
throw new \Exception('Module not found');

if (!ModuleManager::is_installed($module['name'])) {
$output->writeln('<fg=yellow>Module ' . $module_name . ' already installed</fg=yellow>');
return;
}

if (ModuleManager::uninstall($module['name'])) {
$output->writeln('<fg=green>Module ' . $module_name . ' installed</fg=green>');
} else {
$output->writeln('<fg=red>Module ' . $module_name . ' installing error</fg=red>');
}
}
}

+ 31
- 0
console/ThemeRebuildCommand.php View File

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

/**
* Created by PhpStorm.
* User: pjedwabny
* Date: 08.09.15
* Time: 21:10
*/
namespace Epesi\Console;
use Base_ThemeCommon;
use Cache;
use DB;
use ModuleManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ThemeRebuildCommand extends Command
{
protected function configure(){
$this
->setName('theme:rebuild')
->setDescription('Rebuild EPESI default theme')
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('Rebuilding themes...');
Base_ThemeCommon::themeup();
$output->writeln('Theme rebuilded!');
}
}

Loading…
Cancel
Save