summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-07-06 09:58:39 +0200
committerJoas Schilling <coding@schilljs.com>2017-07-06 09:58:39 +0200
commit0f275b15503a58c34fe6a90a3eababa8956b6ede (patch)
treeac0e01806f56c05652ee72b72bb834f480f2bbb9
parent984953ef4a5917e672118a96e3b3714862011308 (diff)
downloadnextcloud-server-0f275b15503a58c34fe6a90a3eababa8956b6ede.tar.gz
nextcloud-server-0f275b15503a58c34fe6a90a3eababa8956b6ede.zip
Only create the migration directory when necessary
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--core/Command/Db/Migrations/GenerateCommand.php17
-rw-r--r--lib/private/DB/MigrationService.php13
2 files changed, 21 insertions, 9 deletions
diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php
index b6e1a17d683..e6c38d06e5d 100644
--- a/core/Command/Db/Migrations/GenerateCommand.php
+++ b/core/Command/Db/Migrations/GenerateCommand.php
@@ -136,6 +136,8 @@ class <classname> extends SimpleMigrationStep {
];
$code = str_replace($placeHolders, $replacements, self::$_templateSimple);
$dir = $ms->getMigrationsDirectory();
+
+ $this->ensureMigrationDirExists($dir);
$path = $dir . '/' . $className . '.php';
if (file_put_contents($path, $code) === false) {
@@ -145,4 +147,19 @@ class <classname> extends SimpleMigrationStep {
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\"");
+ }
+ }
}
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index a4276b08c12..92041b5e324 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -25,7 +25,6 @@
namespace OC\DB;
-use Doctrine\DBAL\Schema\Schema;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\Migration\SimpleOutput;
use OCP\AppFramework\App;
@@ -78,14 +77,6 @@ class MigrationService {
$namespace = App::buildAppNamespace($appName);
$this->migrationsPath = "$appPath/lib/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() {
$directory = realpath($this->migrationsPath);
+ if (!file_exists($directory) || !is_dir($directory)) {
+ return [];
+ }
+
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS),