This repository has been archived by the owner on May 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jérôme Gamez
committed
May 8, 2014
0 parents
commit 1ae97b3
Showing
15 changed files
with
791 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
composer.lock | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.