private function importPackage(Project $project, SimpleXMLElement $xml_pkg, $extraction_path) { $attrs = $xml_pkg->attributes(); $rank = isset($attrs['rank']) ? $attrs['rank'] : 'end'; $hidden = isset($attrs['hidden']) ? $attrs['hidden'] : 'false'; $hidden = $hidden == 'true' || $hidden == '1'; $package = new FRSPackage(); $package->setGroupId($project->getId()); $package->setName((string) $attrs['name']); $package->setStatusID($hidden ? FRSPackage::STATUS_HIDDEN : FRSPackage::STATUS_ACTIVE); $package->setRank($rank); $package->setApproveLicense(true); $package->setPackageID($this->package_factory->create($package->toArray())); $read_perms = array(); foreach ($xml_pkg->{'read-access'} as $perm) { $ugroup_name = (string) $perm->ugroup; $ugroup = $this->getUGroupManager()->getUGroupByName($project, $ugroup_name); $read_perms[] = $ugroup->getId(); } $this->getPermissionsManager()->savePermissions($project, $package->getPackageID(), FRSPackage::PERM_READ, $read_perms); foreach ($xml_pkg->children() as $xml_rel) { if ($xml_rel->getName() != "release") { continue; } $this->importRelease($project, $package, $xml_rel, $extraction_path); } }
/** * 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'); } }
case 'create': if (!$request->exist('submit')) { $GLOBALS['Response']->addFeedback('info', $Language->getText('file_admin_editpackages', 'create_canceled')); $GLOBALS['Response']->redirect('/file/?group_id=' . $group_id); } else { $package_data = $request->get('package'); $package_data['group_id'] = $group_id; if (isset($package_data['name']) && isset($package_data['rank']) && isset($package_data['status_id'])) { $package_data['name'] = htmlspecialchars($package_data['name']); if ($frspf->isPackageNameExist($package_data['name'], $group_id)) { $GLOBALS['Response']->addFeedback('error', $Language->getText('file_admin_editpackages', 'p_name_exists')); $package = new FRSPackage($package_data); frs_display_package_form($package, $GLOBALS['Language']->getText('file_admin_editpackages', 'create_new_p'), '?func=create&group_id=' . $group_id, $existing_packages); } else { //create a new package $res_id = $frspf->create($package_data); $GLOBALS['Response']->addFeedback('info', $Language->getText('file_admin_editpackages', 'p_added')); $GLOBALS['Response']->redirect('/file/?group_id=' . $group_id); } } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'missing_parameters')); frs_display_package_form($package, $GLOBALS['Language']->getText('file_admin_editpackages', 'create_new_p'), '?func=create&group_id=' . $group_id, $existing_packages); } } break; case 'edit': $vPackageId = new Valid_UInt('id'); if ($request->valid($vPackageId)) { $package_id = $request->get('id'); } else { $GLOBALS['Response']->redirect('../showfiles.php?group_id=' . $group_id);