Exemple #1
0
 /**
  * addPackage - add a package in the file release manager of the project $group_id with given values
  *
  * @param string $sessionKey the session hash associated with the session opened by the person who calls the service
  * @param int $group_id the ID of the group we want to add the package
  * @param string $package_name the name of the package
  * @param int $status_id the ID of the status of the package
  * @param int $rank the rank of the package in the package list page (optionnal, by default set to 0)
  * @param int $approve_license true if we need to approve the license before downloading every file in this package, false otherwise.
  * @return int the ID of the new created package, 
  *              or a soap fault if :
  *              - group_id does not match with a valid project, 
  *              - the user does not have the permissions to create a package
  *              - the package creation failed.
  */
 function addPackage($sessionKey, $group_id, $package_name, $status_id, $rank = 0, $approve_license = true)
 {
     if (session_continue($sessionKey)) {
         try {
             $pm = ProjectManager::instance();
             $group = $pm->getGroupByIdForSoap($group_id, 'addPackage');
         } catch (SoapFault $e) {
             return $e;
         }
         $pkg_fact = new FRSPackageFactory();
         if ($pkg_fact->userCanCreate($group_id)) {
             // we check that the package name don't already exist
             if ($pkg_fact->isPackageNameExist($package_name, $group_id)) {
                 return new SoapFault(invalid_package_fault, 'Package name already exists in this project', 'addPackage');
             } else {
                 $pkg_array = array('group_id' => $group->getID(), 'name' => $package_name, 'status_id' => $status_id, 'rank' => $rank, 'approve_license' => $approve_license);
                 $dar = $pkg_fact->create($pkg_array);
                 if (!$dar) {
                     return new SoapFault(invalid_package_fault, $dar->isError(), 'addPackage');
                 } else {
                     // if there is no error, $dar contains the package_id
                     return $dar;
                 }
             }
         } else {
             return new SoapFault(invalid_package_fault, 'User is not allowed to create a package', 'addPackage');
         }
     } else {
         return new SoapFault(invalid_session_fault, 'Invalid Session', 'addPackage');
     }
 }