public function createApplication() { $required = array('name' => true, 'vk_app' => false, 'fb_app' => false, 'ok_app' => false, 'gcm_conf' => false, 'user_channel' => false, 'qa_channel' => false, 'qa_question_channel' => false, 'qa_answers_channel' => false, 'blacklist_channel' => false); $ownerId = $this->controller->identity->getId(); $params = $this->controller->getParams($required); $this->getConfigs($params); $application = new Application(); $application->setAttributes($params); $application->createAppSecret(); $application->owner_id = (int) $ownerId; if (!$application->save()) { if ($application->hasErrors()) { throw new ApiException($application->getErrors(), 500); } else { throw new ApiException('SaveFailed', 500); } } $this->controller->data = $application; }
/** * Create default application. */ public function init() { if ($default = Application::model()->byName(self::DEFAULT_NAME)->find()) { $this->controller->data = $default; return; } $user = \User::model()->find(); $default = new Application(); $default->name = self::DEFAULT_NAME; $default->createAppSecret(); $default->owner_id = (int) $user->id; if (!$default->save()) { if ($default->hasErrors()) { throw new ApiException($default->getErrors(), 500); } else { throw new ApiException('SaveFailed', 500); } } $this->controller->data = $default; }