Only create the migration directory when necessary
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
984953ef4a
commit
0f275b1550
|
@ -136,6 +136,8 @@ class <classname> extends SimpleMigrationStep {
|
||||||
];
|
];
|
||||||
$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
|
$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
|
||||||
$dir = $ms->getMigrationsDirectory();
|
$dir = $ms->getMigrationsDirectory();
|
||||||
|
|
||||||
|
$this->ensureMigrationDirExists($dir);
|
||||||
$path = $dir . '/' . $className . '.php';
|
$path = $dir . '/' . $className . '.php';
|
||||||
|
|
||||||
if (file_put_contents($path, $code) === false) {
|
if (file_put_contents($path, $code) === false) {
|
||||||
|
@ -145,4 +147,19 @@ class <classname> extends SimpleMigrationStep {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function ensureMigrationDirExists($directory) {
|
||||||
|
if (file_exists($directory) && is_dir($directory)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($directory)) {
|
||||||
|
throw new \RuntimeException("Could not create folder \"$directory\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->ensureMigrationDirExists(dirname($directory));
|
||||||
|
|
||||||
|
if (!@mkdir($directory) && !is_dir($directory)) {
|
||||||
|
throw new \RuntimeException("Could not create folder \"$directory\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
namespace OC\DB;
|
namespace OC\DB;
|
||||||
|
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
|
||||||
use OC\IntegrityCheck\Helpers\AppLocator;
|
use OC\IntegrityCheck\Helpers\AppLocator;
|
||||||
use OC\Migration\SimpleOutput;
|
use OC\Migration\SimpleOutput;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
@ -78,14 +77,6 @@ class MigrationService {
|
||||||
$namespace = App::buildAppNamespace($appName);
|
$namespace = App::buildAppNamespace($appName);
|
||||||
$this->migrationsPath = "$appPath/lib/Migration";
|
$this->migrationsPath = "$appPath/lib/Migration";
|
||||||
$this->migrationsNamespace = $namespace . '\\Migration';
|
$this->migrationsNamespace = $namespace . '\\Migration';
|
||||||
|
|
||||||
if (!@mkdir($appPath . '/lib') && !is_dir($appPath . '/lib')) {
|
|
||||||
throw new \RuntimeException("Could not create migration folder \"{$this->migrationsPath}\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!@mkdir($this->migrationsPath) && !is_dir($this->migrationsPath)) {
|
|
||||||
throw new \RuntimeException("Could not create migration folder \"{$this->migrationsPath}\"");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +155,10 @@ class MigrationService {
|
||||||
|
|
||||||
protected function findMigrations() {
|
protected function findMigrations() {
|
||||||
$directory = realpath($this->migrationsPath);
|
$directory = realpath($this->migrationsPath);
|
||||||
|
if (!file_exists($directory) || !is_dir($directory)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$iterator = new \RegexIterator(
|
$iterator = new \RegexIterator(
|
||||||
new \RecursiveIteratorIterator(
|
new \RecursiveIteratorIterator(
|
||||||
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS),
|
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS),
|
||||||
|
|
Loading…
Reference in New Issue