Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Gamez committed May 8, 2014
0 parents commit 1ae97b3
Show file tree
Hide file tree
Showing 15 changed files with 791 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
/vendor/
48 changes: 48 additions & 0 deletions Command/ExecuteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand as BaseExecuteCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for executing single migrations up or down manually.
*/
class ExecuteCommand extends BaseExecuteCommand
{
use CommandTrait;

/**
* {@inheritDoc}
*/
protected function configure()
{
BaseExecuteCommand::configure();

$this->setName('ezpublish:migrations:execute');
}

/**
* {@inheritDoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseExecuteCommand::execute($input, $output);
}
}
121 changes: 121 additions & 0 deletions Command/GenerateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand as BaseGenerateCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for generating new blank migration classes.
*/
class GenerateCommand extends BaseGenerateCommand
{
use CommandTrait;

protected $template =
'<?php
namespace <namespace>;
use Kreait\EzPublish\MigrationsBundle\Migrations\AbstractMigration as AbstractEzPublishMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version<version> extends AbstractEzPublishMigration
{
/**
* Description of this up migration
*
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
<up>
}
/**
* Description of this down migration
*
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
<down>
}
}
';
/**
* {@inheritDoc}
*/
protected function configure()
{
BaseGenerateCommand::configure();

$this->setName('ezpublish:migrations:generate');
}

/**
* {@inheritDoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseGenerateCommand::execute($input, $output);
}

/**
* {@inheritDoc}
*/
protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
{
$placeHolders = array(
'<namespace>',
'<version>',
'<up>',
'<down>'
);
$replacements = array(
$configuration->getMigrationsNamespace(),
$version,
$up ? " " . implode("\n ", explode("\n", $up)) : null,
$down ? " " . implode("\n ", explode("\n", $down)) : null
);
$code = str_replace($placeHolders, $replacements, $this->template);
$dir = $configuration->getMigrationsDirectory();
$dir = $dir ? $dir : getcwd();
$dir = rtrim($dir, '/');
$path = $dir . '/Version' . $version . '.php';

if ( ! file_exists($dir)) {
throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
}

file_put_contents($path, $code);

if ($editorCmd = $input->getOption('editor-cmd')) {
shell_exec($editorCmd . ' ' . escapeshellarg($path));
}

return $path;
}
}
48 changes: 48 additions & 0 deletions Command/LatestCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand as BaseLatestCommand;
use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for outputting the latest version number.
*/
class LatestCommand extends BaseLatestCommand
{
use CommandTrait;

/**
* {@inheritDoc}
*/
protected function configure()
{
BaseLatestCommand::configure();

$this->setName('ezpublish:migrations:latest');
}

/**
* {@inheritDoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseLatestCommand::execute($input, $output);
}
}
42 changes: 42 additions & 0 deletions Command/MigrateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand as BaseMigrateCommand;
use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for executing a migration to a specified version or the latest available version.
*/
class MigrateCommand extends BaseMigrateCommand
{
use CommandTrait;

protected function configure()
{
BaseMigrateCommand::configure();

$this->setName('ezpublish:migrations:migrate');
}

public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseMigrateCommand::execute($input, $output);
}
}
42 changes: 42 additions & 0 deletions Command/StatusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand as BaseStatusCommand;
use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for generating new blank migration classes.
*/
class StatusCommand extends BaseStatusCommand
{
use CommandTrait;

protected function configure()
{
BaseStatusCommand::configure();

$this->setName('ezpublish:migrations:status');
}

public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseStatusCommand::execute($input, $output);
}
}
42 changes: 42 additions & 0 deletions Command/VersionCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the kreait eZ Publish Migrations Bundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand as BaseVersionCommand;
use Kreait\EzPublish\MigrationsBundle\Traits\CommandTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Command for generating new blank migration classes.
*/
class VersionCommand extends BaseVersionCommand
{
use CommandTrait;

protected function configure()
{
BaseVersionCommand::configure();

$this->setName('ezpublish:migrations:version');
}

public function execute(InputInterface $input, OutputInterface $output)
{
/** @var ContainerInterface $container */
$container = $this->getApplication()->getKernel()->getContainer();

$this->setMigrationConfiguration($this->getBasicConfiguration($container, $output));

$configuration = $this->getMigrationConfiguration($input, $output);
$this->configureMigrations($container, $configuration);

BaseVersionCommand::execute($input, $output);
}
}
Loading

0 comments on commit 1ae97b3

Please sign in to comment.