/** * @param $args * * @return \Models\Project */ public function createProject($args) { try { Project::getDB()->transactionStart(); $name = $args['name']; $identifier = $args['identifier']; $isPublic = $args['is_public']; $project = Project::findOne(['identifier' => $identifier]); if (!empty($project)) { Exception::throwException(10006); } $guid = Loader::library('Guid'); $guid->getGuid(); $account = Request::getParameter('currentAccount'); $project = Project::create(['id' => $guid->toString(), 'name' => $name, 'is_public' => $isPublic, 'identifier' => $identifier, 'uid' => $account->uid]); //创建初始角色 $projectRole = $this->createProjectRole(config('App.project_role_init_name'), config('App.project_role_init_permission'), $project->id); //创建初始项目成员关系 $this->createProjectMemberRelation($project->id, $projectRole->role_id, $account->uid); //创建版本库 $this->createRepository($account->identifier, $project->identifier); Project::getDB()->transactionComplete(); return $project; } catch (\Exception $e) { Project::getDB()->transactionRollback(); throw $e; } }
public function handle(array $params = null) { if (Request::hasParameter('account') && is_array($params) && isset($params[1])) { $currentAccount = null; if (Request::hasParameter('currentAccount')) { $currentAccount = Request::getParameter('currentAccount'); } $account = Request::getParameter('account'); $project = Project::findOne(['uid' => $account->uid, 'identifier' => $params[1]]); if (!empty($project)) { if ($project->is_public != '1') { if (is_null($currentAccount)) { Exception::throwException(10004); } elseif ($project->uid != $currentAccount->uid) { Exception::throwException(10004); } } Request::addParameter('project', $project); } else { Exception::throwException(10003); } } else { Exception::throwException(10001); } }
function __construct() { parent::__construct(); Loader::helper('Url'); View::registerFunction('baseUrl', 'baseUrl'); $this->account = Request::getParameter('account'); $this->project = Request::getParameter('project'); }
public function processCreateProject() { $args = Input::post(); /** * @var \Proxy\ProjectProxy $projectProxy */ $projectProxy = Loader::proxy('ProjectProxy'); //创建项目 $project = $projectProxy->createProject($args); Response::json(['code' => 0, 'data' => ['project' => $project, 'account' => Request::getParameter('currentAccount')]]); }