/** * 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']]); }
/** * 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"); } } }
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; } }