Added custom console Application class with migrations

This commit is contained in:
Dmitry Khomutov 2016-12-30 23:40:14 +07:00
commit d78f9f0e5f
19 changed files with 85 additions and 116 deletions

View file

@ -382,9 +382,7 @@ class InstallCommand extends Command
{
$output->write(Lang::get('setting_up_db'));
$phinxBinary = escapeshellarg(ROOT_DIR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phinx');
$phinxScript = escapeshellarg(APP_DIR . 'phinx.php');
shell_exec($phinxBinary . ' migrate -c ' . $phinxScript);
shell_exec(ROOT_DIR . 'bin/console php-censor-migrations:migrate');
$output->writeln('<info>'.Lang::get('ok').'</info>');
}

View file

@ -1,68 +0,0 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCensor\Command;
use b8\Config;
use Monolog\Logger;
use PHPCensor\Helper\Lang;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Generate console command - Reads the database and generates models and stores.
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Console
*/
class UpdateCommand extends Command
{
/**
* @var \Monolog\Logger
*/
protected $logger;
public function __construct(Logger $logger, $name = null)
{
parent::__construct($name);
$this->logger = $logger;
}
protected function configure()
{
$this
->setName('php-censor:update')
->setDescription(Lang::get('update_app'));
}
/**
* Generates Model and Store classes by reading database meta data.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->verifyInstalled()) {
return;
}
$output->write(Lang::get('updating_app'));
shell_exec(ROOT_DIR . 'vendor/bin/phinx migrate -c "' . APP_DIR . 'phinx.php"');
$output->writeln('<info>'.Lang::get('ok').'</info>');
}
protected function verifyInstalled()
{
$config = Config::getInstance();
$url = $config->get('php-censor.url');
return !empty($url);
}
}

View file

@ -0,0 +1,68 @@
<?php
namespace PHPCensor\Console;
use b8\Config;
use Symfony\Component\Console\Application as BaseApplication;
use Phinx\Console\Command\Create;
use Phinx\Console\Command\Migrate;
use Phinx\Console\Command\Rollback;
use Phinx\Console\Command\Status;
use Phinx\Config\Config as PhinxConfig;
class Application extends BaseApplication
{
/**
* Constructor.
*
* @param string $name The name of the application
* @param string $version The version of the application
*/
public function __construct($name = 'PHP Censor - Continuous Integration for PHP', $version = '')
{
parent::__construct($name, $version);
$applicationConfig = Config::getInstance();
$databaseSettings = $applicationConfig->get('b8.database', []);
$phinxSettings = [
'paths' => [
'migrations' => 'src/PHPCensor/Migrations',
],
'environments' => [
'default_migration_table' => 'migration',
'default_database' => 'php-censor',
'php-censor' => [
'adapter' => 'mysql',
'host' => $databaseSettings['servers']['write'],
'name' => $databaseSettings['name'],
'user' => $databaseSettings['username'],
'pass' => $databaseSettings['password'],
],
],
];
$phinxConfig = new PhinxConfig($phinxSettings);
$this->add(
(new Create())
->setConfig($phinxConfig)
->setName('php-censor-migrations:create')
);
$this->add(
(new Migrate())
->setConfig($phinxConfig)
->setName('php-censor-migrations:migrate')
);
$this->add(
(new Rollback())
->setConfig($phinxConfig)
->setName('php-censor-migrations:rollback')
);
$this->add(
(new Status())
->setConfig($phinxConfig)
->setName('php-censor-migrations:status')
);
}
}

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*
@ -9,7 +10,6 @@
namespace PHPCensor\Controller;
use b8;
use PHPCensor\Helper\Lang;
use PHPCensor\Plugin\Util\ComposerPluginInformation;
use PHPCensor\Plugin\Util\FilesPluginInformation;

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*

View file

@ -1,4 +1,5 @@
<?php
/**
* PHPCI - Continuous Integration for PHP
*