Browse Source

Module enabled migration apply both up and safeUp methods

master
Egorka 6 years ago
parent
commit
5fe96f10d3
  1. 9
      core/services/ModuleService.php

9
core/services/ModuleService.php

@ -95,14 +95,19 @@ class ModuleService
$migrationFile = basename($migrationPath); $migrationFile = basename($migrationPath);
$migration = str_replace('.php', '', $migrationFile); $migration = str_replace('.php', '', $migrationFile);
if (!$this->migrationExists($migration)) { if (!$this->migrationExists($migration)) {
$addMigrationRecord = false;
// run migration // run migration
require $migrationPath; require $migrationPath;
$obj = new $migration; $obj = new $migration;
if (method_exists($obj, 'safeUp')) { if (method_exists($obj, 'safeUp')) {
$obj->safeUp(); $obj->safeUp();
Yii::$app->moduleManager->appendToMigrationTable($migration); $addMigrationRecord = true;
} elseif (method_exists($obj, 'up')) { }
if (method_exists($obj, 'up')) {
$obj->up(); $obj->up();
$addMigrationRecord = true;
}
if ($addMigrationRecord) {
Yii::$app->moduleManager->appendToMigrationTable($migration); Yii::$app->moduleManager->appendToMigrationTable($migration);
} }
} }

Loading…
Cancel
Save