/**
  * @hass-todo 没有添加事务
  * @return string
  */
 public function actionIndex()
 {
     $model = new MigrationUtility();
     $upStr = new OutputString();
     $downStr = new OutputString();
     if ($model->load(\Yii::$app->getRequest()->post())) {
         if (!empty($model->tableSchemas)) {
             list($up, $down) = $this->generalTableSchemas($model->tableSchemas, $model->tableOption, $model->foreignKeyOnUpdate, $model->foreignKeyOnDelete);
             $upStr->outputStringArray = array_merge($upStr->outputStringArray, $up->outputStringArray);
             $downStr->outputStringArray = array_merge($downStr->outputStringArray, $down->outputStringArray);
         }
         if (!empty($model->tableDatas)) {
             list($up, $down) = $this->generalTableDatas($model->tableDatas);
             $upStr->outputStringArray = array_merge($upStr->outputStringArray, $up->outputStringArray);
             $downStr->outputStringArray = array_merge($downStr->outputStringArray, $down->outputStringArray);
         }
         $path = Yii::getAlias($model->migrationPath);
         if (!is_dir($path)) {
             FileHelper::createDirectory($path);
         }
         $name = 'm' . gmdate('ymd_His') . '_' . $model->migrationName;
         $file = $path . DIRECTORY_SEPARATOR . $name . '.php';
         $content = $this->renderFile(Yii::getAlias("@hass/migration/views/migration.php"), ['className' => $name, 'up' => $upStr->output(), 'down' => $downStr->output()]);
         file_put_contents($file, $content);
         $this->flash("success", "迁移成功,保存在" . $file);
     }
     if ($model->migrationPath == null) {
         $model->migrationPath = $this->module->migrationPath;
     }
     return $this->render('index', ['model' => $model]);
 }
예제 #2
0
?>
			</div>
			<div class="col-md-6">
			  <?php 
echo $form->field($model, 'foreignKeyOnDelete')->dropDownList($array)->hint('');
?>
			</div>
		</div>
	</div>
</div>


  
<?php 
echo $form->boxField($model, "tableSchemas")->checkboxList(MigrationUtility::getTableNames())->header("迁移表结构")->hint(Html::a("全选", 'javascript:void(0)', ['class' => "select-all"]));
echo $form->boxField($model, "tableDatas")->checkboxList(MigrationUtility::getTableNames())->header("迁移表数据")->hint(Html::a("全选", 'javascript:void(0)', ['class' => "select-all"]));
?>


<div class="form-group">
     <?php 
echo Html::submitButton('迁移', ['class' => 'btn bg-maroon btn-flat btn-block ', 'name' => 'button-submit', 'id' => 'button-submit']);
?>
</div>

<?php 
ActiveForm::end();
?>