Added custom console Application class with migrations

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

View file

@ -1,36 +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/
*/
require_once(dirname(__DIR__) . '/bootstrap.php');
$writeServers = $config->get('b8.database.servers.write');
if (!is_array($writeServers)) {
$writeServers = [$writeServers];
}
$conf = [
'paths' => [
'migrations' => 'src/PHPCensor/Migrations',
],
'environments' => [
'default_migration_table' => 'migration',
'default_database' => 'php-censor',
'php-censor' => [
'adapter' => 'mysql',
'host' => end($writeServers),
'name' => $config->get('b8.database.name'),
'user' => $config->get('b8.database.username'),
'pass' => $config->get('b8.database.password'),
],
],
];
return $conf;

View file

@ -11,7 +11,6 @@
use PHPCensor\Command\RunCommand;
use PHPCensor\Command\RebuildCommand;
use PHPCensor\Command\UpdateCommand;
use PHPCensor\Command\InstallCommand;
use PHPCensor\Command\DaemonCommand;
use PHPCensor\Command\PollCommand;
@ -20,8 +19,8 @@ use PHPCensor\Command\CreateBuildCommand;
use PHPCensor\Command\WorkerCommand;
use PHPCensor\Command\RebuildQueueCommand;
use PHPCensor\Service\BuildService;
use Symfony\Component\Console\Application;
use b8\Store\Factory;
use PHPCensor\Console\Application;
define('IS_CONSOLE', true);
@ -32,7 +31,6 @@ $application = new Application();
$application->add(new RunCommand($loggerConfig->getFor('RunCommand')));
$application->add(new RebuildCommand($loggerConfig->getFor('RunCommand')));
$application->add(new InstallCommand);
$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand')));
$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand')));
$application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
$application->add(new CreateAdminCommand(Factory::getStore('User')));

View file

@ -19,7 +19,7 @@ Installing PHP Censor from Composer
* Download Composer if you haven't already: `curl -sS https://getcomposer.org/installer | php`
* Download PHP Censor: `./composer.phar create-project corpsee/php-censor php-censor --keep-vcs --no-dev`
* Go to the newly created PHP Censor directory, and install Composer dependencies: `cd php-censor && ../composer.phar install`
* Run the PHP Censor installer: `./console php-censor:install`
* Run the PHP Censor installer: `./bin/console php-censor:install`
* [Add a virtual host to your web server](virtual_host.md), pointing to the `public` directory within your new PHP Censor directory. You'll need to set up rewrite rules to point all non-existent requests to PHP Censor.
* [Set up the PHP Censor Worker](workers/worker.md), or you can run builds using the [daemon](workers/daemon.md) or [a cron-job](workers/cron.md) to run PHP Censor builds.
@ -30,6 +30,6 @@ Installing PHP Censor Manually
* [Download PHP Censor](https://github.com/corpsee/php-censor/releases/latest) and unzip it.
* Go to the PHP Censor directory: `cd /var/www/php-censor`
* Install dependencies using Composer: `composer install`
* Install PHP Censor itself: `./console php-censor:install`
* Install PHP Censor itself: `./bin/console php-censor:install`
* [Add a virtual host to your web server](virtual_host.md), pointing to the `public` directory within your new PHP Censor directory. You'll need to set up rewrite rules to point all non-existent requests to PHP Censor.
* [Set up the PHP Censor Worker](workers/worker.md), or you can run builds using the [daemon](workers/daemon.md) or [a cron-job](workers/cron.md) to run PHP Censor builds.

View file

@ -5,7 +5,7 @@ Updating PHP Censor to the latest release, or even dev-master updates is somethi
1. Go to your PHP Censor root folder in a Terminal.
2. Pull the latest code. This would look like this: `git pull`
3. Update the PHP Censor database: `./console php-censor:update`
3. Update the PHP Censor database: `./bin/console php-censor-migrations:migrate`
4. Update the composer and its packages: `composer self-update && composer update`
5. Return to the PHP Censor admin screens and check your desired plugins are still installed correctly.
7. Run a build to make sure everything is working as expected.

View file

@ -11,7 +11,7 @@ Setting up the Cron Job
You'll want to set up PHP Censor to run as a regular cronjob, so run `crontab -e` and enter the following:
```sh
* * * * * /usr/bin/php /path/to/php-censor/console php-censor:run-builds
* * * * * /usr/bin/php /path/to/php-censor/bin/console php-censor:run-builds
```
**Note:** Make sure you change the `/path/to/php-censor` to the directory in which you installed PHP Censor, and update the PHP path if necessary.

View file

@ -37,7 +37,7 @@ Using your preferred text editor, create a file named `php-censor.conf` under `/
```
[program:php-censor]
command=/path/to/php-censor/latest/console php-censor:worker
command=/path/to/php-censor/bin/console php-censor:worker
process_name=%(program_name)s_%(process_num)02d
stdout_logfile=/var/log/php-censor.log
stderr_logfile=/var/log/php-censor-err.log

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
*