Skip to content

Commit

Permalink
[Generator] [Command|Manager] fixed regression introduced in #cd22336.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Hamon committed Aug 22, 2012
1 parent a24f5fe commit 0b5438a
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
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Propel\Generator\Exception\RuntimeException;

Expand Down Expand Up @@ -87,6 +88,17 @@ protected function getFilesystem()
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)
{
$pos = strpos($connection, '=');
Expand Down
5 changes: 1 addition & 4 deletions src/Propel/Generator/Command/ConfigConvertXmlCommand.php
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));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

namespace Propel\Generator\Manager;

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

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

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

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

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

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

0 comments on commit 0b5438a

Please sign in to comment.