Пример #1
0
 /**
  * Create a project
  *
  * @param array Fields data
  * @param string The creating user
  * @param bool Create a group for the project
  * @param bool Add user into group
  * @param bool Add user as admin for the project
  * @param bool Create SVN standard directories
  * @return USVN_Db_Table_Row_Project
  */
 public static function createProject(array $data, $login, $create_group, $add_user_to_group, $create_admin, $create_svn_directories)
 {
     //We need check if admin exist before create project because we can't go back
     $user_table = new USVN_Db_Table_Users();
     $user = $user_table->fetchRow(array('users_login = ?' => $login));
     if ($user === null) {
         throw new USVN_Exception(T_('Login %s not found'), $login);
     }
     $groups = new USVN_Db_Table_Groups();
     if ($create_group) {
         $group = $groups->fetchRow(array('groups_name = ?' => $data['projects_name']));
         if ($group !== null) {
             throw new USVN_Exception(T_("Group %s already exists."), $data['projects_name']);
         }
     }
     try {
         $table = new USVN_Db_Table_Projects();
         $table->getAdapter()->beginTransaction();
         $project = $table->createRow($data);
         $project->save();
         USVN_Project::createProjectSVN($data['projects_name'], $create_svn_directories);
         if ($create_group) {
             $group = $groups->createRow();
             $group->description = sprintf(T_("Autocreated group for project %s"), $data['projects_name']);
             $group->name = $data['projects_name'];
             $group->save();
             $project->addGroup($group);
             USVN_Project::ApplyFileRights($project, $group, $create_svn_directories);
         }
         if ($create_group && $add_user_to_group) {
             $group->addUser($user);
             $group->promoteUser($user);
         }
         if ($create_admin) {
             $project->addUser($user);
         }
     } catch (Exception $e) {
         $table->getAdapter()->rollBack();
         throw $e;
     }
     $table->getAdapter()->commit();
     return $project;
 }