/** * @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; } }