public function safeDown() { $this->dropTable('IF EXISTS ' . Websites::tableName()); $this->dropTable('IF EXISTS ' . Tasks::tableName()); $this->dropTable('IF EXISTS ' . Deploy::tableName()); $this->dropTable('IF EXISTS ' . DeployHasTasks::tableName()); $this->dropTable('IF EXISTS ' . WebsiteHasUser::tableName()); return true; }
public function deploy($id, $data) { $form = new DeployForm(); $form->websites_id = $id; if ($form->load($data, '') && $form->validate()) { $model = new Deploy(['scenario' => Deploy::SCENARIO_TRANSACTION]); $model->on(Deploy::EVENT_AFTER_INSERT, function ($event) use($form) { $website = $event->sender->website; $this->execDeploy($form, $event->sender); $event->sender->deploy_version = DepControl::run(['deployScript' => $website->deploy_script, 'deployProject' => $website->deploy_project])->current(); $event->sender->update(); DeployHasTasks::batchInsertByCondition(['tasks_id'], (array) $form->tasks_id, ['deploy_id' => $event->sender->id]); Tasks::updateAll(['status' => Tasks::STATUS_SUCCESS], ['id' => $form->tasks_id]); }); $model->setAttributes($form->getAttributes(null, ['tasks_id'])); $model->insert(false, array_keys($model->getAttributes(null, ['deploy_version']))); } return $form; }
public function getDeployHasTask() { return $this->hasMany(DeployHasTasks::className(), ['deploy_id' => 'id']); }