Skip to content

Commit

Permalink
Merge pull request #1187 from doctrine/write-file
Browse files Browse the repository at this point in the history
The write-sql option can be a filename
  • Loading branch information
goetas committed Aug 3, 2021
2 parents ce8233b + 225edaa commit 818e317
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Expand Up @@ -12,8 +12,10 @@
use Symfony\Component\Console\Output\OutputInterface;

use function array_map;
use function dirname;
use function getcwd;
use function implode;
use function is_dir;
use function is_string;
use function is_writable;
use function sprintf;
Expand Down Expand Up @@ -130,7 +132,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
: Direction::UP;

$path = $input->getOption('write-sql') ?? getcwd();
if (is_string($path) && ! is_writable($path)) {

if (is_string($path) && ! $this->isPathWritable($path)) {
$this->io->error(sprintf('The path "%s" not writeable!', $path));

return 1;
Expand Down Expand Up @@ -161,4 +164,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return 0;
}

private function isPathWritable(string $path): bool
{
return is_writable($path) || is_dir($path) || is_writable(dirname($path));
}
}
Expand Up @@ -15,8 +15,10 @@
use Symfony\Component\Console\Output\OutputInterface;

use function count;
use function dirname;
use function getcwd;
use function in_array;
use function is_dir;
use function is_string;
use function is_writable;
use function sprintf;
Expand Down Expand Up @@ -143,7 +145,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$versionAlias = $input->getArgument('version');

$path = $input->getOption('write-sql') ?? getcwd();
if (is_string($path) && ! is_writable($path)) {

if (is_string($path) && ! $this->isPathWritable($path)) {
$this->io->error(sprintf('The path "%s" not writeable!', $path));

return 1;
Expand Down Expand Up @@ -279,4 +282,9 @@ private function exitForAlias(string $versionAlias): int

return 0;
}

private function isPathWritable(string $path): bool
{
return is_writable($path) || is_dir($path) || is_writable(dirname($path));
}
}
Expand Up @@ -94,10 +94,12 @@ public function getWriteSqlValues(): array
[true, false, null],
[true, null, getcwd()],
[true, __DIR__ . '/_files', __DIR__ . '/_files'],
[true, __DIR__ . '/_files/run.sql', __DIR__ . '/_files/run.sql'],

[false, false, null],
[false, null, getcwd()],
[false, __DIR__ . '/_files', __DIR__ . '/_files'],
[true, __DIR__ . '/_files/run.sql', __DIR__ . '/_files/run.sql'],
];
}

Expand Down

0 comments on commit 818e317

Please sign in to comment.