Ejemplo n.º 1
0
 /**
  * Create default article channel
  * @param  \MongoId $accountId
  * @throws ServerErrorHttpException when save the record for default article channel failed.
  */
 private function _createDefaultChannel(\MongoId $accountId)
 {
     $defaultChannel = ArticleChannel::getDefault($accountId);
     if (empty($defaultChannel)) {
         $channel = new ArticleChannel();
         $channel->name = Yii::t('microSite', 'default_channel');
         $channel->fields = [];
         $channel->isDefault = true;
         $channel->accountId = $accountId;
         if (!$channel->save()) {
             throw new ServerErrorHttpException("create default article channel failed");
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns the list of all rules of ChatConversation.
  * This method must be overridden by child classes to define available attributes.
  *
  * @return array list of rules.
  */
 public function rules()
 {
     $currentUser = User::findByPk(new \MongoId(CURRENT_USER_ID));
     //get default channel
     if (empty($this->accountId)) {
         throw new ServerErrorHttpException('Account id of article cannot be blank');
     }
     $defaultChannel = ArticleChannel::getDefault($this->accountId);
     if (empty($defaultChannel)) {
         throw new ServerErrorHttpException('Can not found default channel');
     }
     return array_merge(parent::rules(), [[['name', 'content', 'url'], 'required'], ['createdBy', 'default', 'value' => $currentUser->name], ['fields', 'default', 'value' => []], ['fields', 'validateFields'], ['channel', 'default', 'value' => $defaultChannel->_id], ['channel', 'toMongoId']]);
 }
 /**
  * Delete channel
  */
 public function actionDelete($id)
 {
     $channelId = new \MongoId($id);
     $articleCount = Article::countByChannel($channelId);
     if ($articleCount > 0) {
         return $articleCount;
     }
     if (!ArticleChannel::deleteAll(['_id' => $channelId])) {
         throw new ServerErrorHttpException("failed to delete article channel for unknown reason");
     }
     Yii::$app->getResponse()->setStatusCode(204);
 }
Ejemplo n.º 4
0
 private function _createDefaultChannel($accountId)
 {
     $defaultChannel = ArticleChannel::getDefault($accountId);
     if (empty($defaultChannel)) {
         $channel = new ArticleChannel();
         $channel->name = '默认频道';
         $channel->fields = [];
         $channel->isDefault = true;
         $channel->accountId = $accountId;
         if (!$channel->save()) {
             echo $channel->getErrors() . PHP_EOL;
             exit;
         }
     } else {
         echo $accountId . 'data is exists' . PHP_EOL;
     }
 }