Skip to content

Commit

Permalink
Merge pull request #296 from hhamon/commands_regression_fix
Browse files Browse the repository at this point in the history
[Generator] [Command|Manager] fixed regression introduced in #cd22336.
  • Loading branch information
willdurand committed Aug 22, 2012
2 parents a24f5fe + 0b5438a commit d0a110d
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 25 deletions.
12 changes: 12 additions & 0 deletions src/Propel/Generator/Command/AbstractCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Propel\Generator\Exception\RuntimeException; use Propel\Generator\Exception\RuntimeException;


Expand Down Expand Up @@ -87,6 +88,17 @@ protected function getFilesystem()
return $this->filesystem; return $this->filesystem;
} }


protected function createDirectory($directory)
{
$filesystem = $this->getFilesystem();

try {
$filesystem->mkdir($directory);
} catch (IOException $e) {
throw new \RuntimeException(sprintf('Unable to write the "%s" directory', $directory), 0, $e);
}
}

protected function parseConnection($connection) protected function parseConnection($connection)
{ {
$pos = strpos($connection, '='); $pos = strpos($connection, '=');
Expand Down
5 changes: 1 addition & 4 deletions src/Propel/Generator/Command/ConfigConvertXmlCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \RuntimeException(sprintf('Unable to find the "%s" configuration file', $inputFilePath)); throw new \RuntimeException(sprintf('Unable to find the "%s" configuration file', $inputFilePath));
} }


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
if (!$filesystem->mkdir($input->getOption('output-dir'))) {
throw new \RuntimeException(sprintf('Unable to write the "%s" output directory', $input->getOption('output-dir')));
};


$outputFilePath = $input->getOption('output-dir') . DIRECTORY_SEPARATOR .$input->getOption('output-file'); $outputFilePath = $input->getOption('output-dir') . DIRECTORY_SEPARATOR .$input->getOption('output-file');
if (!is_writable(dirname($outputFilePath))) { if (!is_writable(dirname($outputFilePath))) {
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/DatabaseReverseCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.reverse.parser.class' => sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', $vendor), 'propel.reverse.parser.class' => sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', $vendor),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new ReverseManager(); $manager = new ReverseManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/GraphvizGenerateCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.packageObjectModel' => true, 'propel.packageObjectModel' => true,
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new GraphvizManager(); $manager = new GraphvizManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/MigrationDiffCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'), 'propel.platform.class' => $input->getOption('platform'),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new MigrationManager(); $manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/MigrationDownCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'), 'propel.platform.class' => $input->getOption('platform'),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new MigrationManager(); $manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/MigrationMigrateCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'), 'propel.platform.class' => $input->getOption('platform'),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new MigrationManager(); $manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/MigrationStatusCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'), 'propel.platform.class' => $input->getOption('platform'),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new MigrationManager(); $manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/MigrationUpCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'), 'propel.platform.class' => $input->getOption('platform'),
)); ));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new MigrationManager(); $manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Command/ModelBuildCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.mysql.tableEngineKeyword' => 'ENGINE', 'propel.mysql.tableEngineKeyword' => 'ENGINE',
), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties'))); ), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new ModelManager(); $manager = new ModelManager();
$manager->setFilesystem($this->getFilesystem());
$manager->setGeneratorConfig($generatorConfig); $manager->setGeneratorConfig($generatorConfig);
$manager->setSchemas($this->getSchemas($input->getOption('input-dir'))); $manager->setSchemas($this->getSchemas($input->getOption('input-dir')));
$manager->setLoggerClosure(function($message) use ($input, $output) { $manager->setLoggerClosure(function($message) use ($input, $output) {
Expand Down
3 changes: 1 addition & 2 deletions src/Propel/Generator/Command/SqlBuildCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.mysql.tableEngineKeyword' => 'ENGINE', 'propel.mysql.tableEngineKeyword' => 'ENGINE',
), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties'))); ), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));


$filesystem = $this->getFilesystem(); $this->createDirectory($input->getOption('output-dir'));
$filesystem->mkdir($input->getOption('output-dir'));


$manager = new SqlManager(); $manager = new SqlManager();
$manager->setValidate($input->getOption('validate')); $manager->setValidate($input->getOption('validate'));
Expand Down
12 changes: 9 additions & 3 deletions src/Propel/Generator/Manager/ModelManager.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


namespace Propel\Generator\Manager; namespace Propel\Generator\Manager;


use Symfony\Component\Filesystem\Filesystem;
use Propel\Generator\Builder\Om\AbstractOMBuilder; use Propel\Generator\Builder\Om\AbstractOMBuilder;
use Propel\Generator\Util\Filesystem;


/** /**
* This manager creates the Object Model classes based on the XML schema file. * This manager creates the Object Model classes based on the XML schema file.
Expand All @@ -20,6 +20,13 @@
*/ */
class ModelManager extends AbstractManager class ModelManager extends AbstractManager
{ {
private $filesystem;

public function setFilesystem(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

public function build() public function build()
{ {
$this->validate(); $this->validate();
Expand Down Expand Up @@ -140,8 +147,7 @@ protected function doBuild(AbstractOMBuilder $builder, $overwrite = true)
$path = $builder->getClassFilePath(); $path = $builder->getClassFilePath();
$file = new \SplFileInfo($this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $path); $file = new \SplFileInfo($this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $path);


$filesystem = new Filesystem(); $this->filesystem->mkdir($file->getPath());
$filesystem->mkdir($file->getPath());


// skip files already created once // skip files already created once
if ($file->isFile() && !$overwrite) { if ($file->isFile() && !$overwrite) {
Expand Down

0 comments on commit d0a110d

Please sign in to comment.