/** * 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"); } } }
/** * create article channe;l */ public function actionCreate() { $params = $this->getParams(); $params['accountId'] = $this->getAccountId(); if (empty($params['name'])) { throw new BadRequestHttpException(Yii::t('microSite', 'channel_name_missing')); } if (!empty($params['fields'])) { foreach ($params['fields'] as $field) { if (empty($field['type']) || empty($field['name'])) { throw new BadRequestHttpException(Yii::t('microSite', 'custom_field_missing')); } } } $articleChannel = new ArticleChannel(); $articleChannel->load($params, ''); if (false === $articleChannel->save()) { throw new ServerErrorHttpException(Yii::t('common', 'save_fail')); } return $articleChannel; }
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; } }