public function safeUp() { $this->addColumn('{{%object_cbs}}', 'id', Schema::TYPE_PK); $this->addColumn('{{%object_cbs}}', 'created_at', Schema::TYPE_INTEGER . ' NOT NULL'); $this->addColumn('{{%object_cbs}}', 'updated_at', Schema::TYPE_INTEGER . ' NOT NULL'); $query = \app\models\Objects::find(); $query->where(['not', ['cbs' => null]]); $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query]); $objectsArray = $dataProvider->getModels(); foreach ($objectsArray as $objects) { $cbsNames = explode(',', $objects->cbs); foreach ($cbsNames as $cbsName) { // Find the CBS from APIs that matches the name that was saved as a text before $cbs = \app\models\Apis::findOne(['name' => $cbsName]); if ($cbs) { $objectsCBS = new \app\models\ObjectCBS(); $objectsCBS->object = $objects->id; $objectsCBS->cbs = $cbs->id; $objectsCBS->save(); } } } // Drop column cbs from Objects Table that is not needed anymore $this->dropColumn('{{%objects}}', 'cbs'); }
/** * Accept a particular CBS */ public function actionAcceptcbs($id) { $cbs = Apis::findOne($id); $cbs->status = 'Approved'; $cbs->save(); $this->redirect('adminnotifications'); }
/** * Finds the Cbs model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Apis the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Apis::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }