/**
  * Updates an existing Cbs model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionPropose($id)
 {
     $model = $this->findModel($id);
     $new = new Apis();
     if ($new->load(Yii::$app->request->post())) {
         if ($new->version != $model->version or $new->url != $model->url) {
             $new->name = $model->name . '_v' . $new->version . '_by_' . \app\models\User::findIdentity(Yii::$app->getUser()->getId())->username;
             $new->cbs = 1;
             $new->description = $model->description;
             $new->status = 'pending';
             $new->save();
             return $this->redirect(['index']);
         }
     }
     return $this->render('propose', ['model' => $model]);
 }
 function BuildAPI()
 {
     $model = Apis::find()->where(['name' => $this->_apiName])->one();
     if ($model === null) {
         $model = new Apis();
     } else {
         Properties::deleteAll(['object' => null]);
         $objsToDel = Objects::find()->where(['api' => $model->id])->all();
         foreach ($objsToDel as $objToDel) {
             Properties::deleteAll(['object' => $objToDel->id]);
         }
         Objects::deleteAll(['api' => $model->id]);
     }
     $model->name = $this->_apiName;
     $model->description = $this->_apiDescription;
     $model->published = 1;
     $model->save();
     $this->_apiID = $model->id;
 }
 /**
  * Creates a new Apis model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Apis();
     $model->cbs = 0;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $myId = \Yii::$app->user->id;
         $change = new NotifUserHelper();
         $followersNotified = null;
         $followersNotified = $change->userChangedCreatedApi($myId);
         // Automatically follow the APIs I create
         $followModel = new FollowUserApi();
         $followModel->follower = $myId;
         $followModel->api = $model->id;
         $followModel->save();
         // Elastic Search Insertion
         $esi = new ElasticSearchPut();
         $api = $this->findModel($model->id);
         $esi->setApi($api);
         $esi->MakeJSON();
         $esi->InsertUpdate();
         return $this->redirect(['view', 'id' => $model->id, 'followersNotified' => $followersNotified]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }