コード例 #1
0
 private function migration()
 {
     $config = $this->getDbConfigFromSession();
     $dbConfigModel = new DbConfig();
     $dbConfigModel->setAttributes($config);
     $config = InstallerHelper::createDatabaseConfig($dbConfigModel->getAttributes());
     if (InstallerHelper::createDatabaseConfigFile($config) === false) {
         $this->stderr(Yii::t('app', 'Unable to create db-local config'), Console::FG_RED);
         return false;
     }
     $this->stdout("Running migrations...\n", Console::FG_YELLOW);
     /** @var UpdateHelper $helper */
     $helper = Yii::createObject(['class' => UpdateHelper::className()]);
     $process = $helper->applyAppMigrations(false);
     $process->run();
     return $this->adminUser();
 }
コード例 #2
0
 public function actionMigrate()
 {
     $model = new MigrateModel();
     $model->ignore_time_limit_warning = Yii::$app->session->get('ignore_time_limit_warning', false);
     $model->manual_migration_run = false;
     $model->composerHomeDirectory = Yii::$app->session->get('composerHomeDirectory', './.composer/');
     $model->updateComposer = Yii::$app->session->get('updateComposer', false);
     if ($model->load(Yii::$app->request->post())) {
         $model->validate();
         foreach ($model->getAttributes() as $key => $value) {
             Yii::$app->session->set($key, $value);
         }
     }
     /** @var UpdateHelper $helper */
     $helper = Yii::createObject(['class' => UpdateHelper::className(), 'composerHomeDirectory' => $model->composerHomeDirectory]);
     $process = $helper->applyAppMigrations(false);
     $commandToRun = $process->getCommandLine();
     $check = $this->checkTime($model->ignore_time_limit_warning);
     if (Yii::$app->request->isPost) {
         if ($check && $model->manual_migration_run === false) {
             // create config
             $config = $this->getDbConfigFromSession();
             $dbConfigModel = new DbConfig();
             $dbConfigModel->setAttributes($config);
             $config = InstallerHelper::createDatabaseConfig($dbConfigModel->getAttributes());
             $configOk = true;
             if (InstallerHelper::createDatabaseConfigFile($config) === false) {
                 Yii::$app->session->setFlash('warning', Yii::t('app', 'Unable to create db-local config'));
                 $configOk = false;
             }
             if ($configOk === true) {
                 if ($model->updateComposer) {
                     $composerProcess = $helper->updateComposer();
                     $composerProcess->run();
                     gc_collect_cycles();
                     if ($composerProcess->getExitCode() !== 0) {
                         $process = $composerProcess;
                     } else {
                         $process->run();
                     }
                 } else {
                     $process->run();
                 }
                 if ($process->getExitCode() === 0) {
                     Yii::$app->session->setFlash('info', Yii::t('app', 'Migrations completed successfully'));
                     return $this->redirect(['admin-user']);
                 }
             }
         }
         if ($model->manual_migration_run === true) {
             return $this->redirect(['admin-user']);
         }
     }
     return $this->render('migrate', ['check' => $check, 'commandToRun' => $commandToRun, 'process' => $process, 'model' => $model]);
 }