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

Commit

Permalink
Simplify GenerateCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Jan 27, 2016
1 parent 2c8aed7 commit b1fd521
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
namespace Kreait\EzPublish\MigrationsBundle\Command;

use Doctrine\Bundle\MigrationsBundle\Command\MigrationsGenerateDoctrineCommand;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Tools\Console\Helper\MigrationDirectoryHelper;
use Symfony\Component\Console\Input\InputInterface;

/**
* Command for generating new blank migration classes.
Expand Down Expand Up @@ -63,32 +60,8 @@ protected function configure()
$this->setDescription('Generate a blank eZ Publish/Platform enabled migration class');
}

protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
protected function getTemplate()
{
$placeHolders = [
'<namespace>',
'<version>',
'<up>',
'<down>',
];
$replacements = [
$configuration->getMigrationsNamespace(),
$version,
$up ? ' '.implode("\n ", explode("\n", $up)) : null,
$down ? ' '.implode("\n ", explode("\n", $down)) : null,
];
$code = str_replace($placeHolders, $replacements, $this->ezMigrationTemplate);
$code = preg_replace('/^ +$/m', '', $code);
$migrationDirectoryHelper = new MigrationDirectoryHelper($configuration);
$dir = $migrationDirectoryHelper->getMigrationDirectory();
$path = $dir.'/Version'.$version.'.php';

file_put_contents($path, $code);

if ($editorCmd = $input->getOption('editor-cmd')) {
proc_open($editorCmd.' '.escapeshellarg($path), [], $pipes);
}

return $path;
return $this->ezMigrationTemplate;
}
}

0 comments on commit b1fd521

Please sign in to comment.