/** * addUploadedFile - add a file in the file release manager, in the release $release_id, in package $package_id 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 file * @param int $package_id the ID of the package we want to add the file * @param int $release_id the ID of the release we want to add the file * @param string $filename the name of the file we want to add (only file name, not directory) * @param int $type_id the ID of the type of the file * @param int $processor_id the ID of the processor of the file * @param string $reference_md5 the md5sum of the file calculated in client side * @param string $comment A comment/description of the uploaded file * @return int the ID of the new created file, * or a soap fault if : * - group_id does not match with a valid project, * - package_id does not match with a valid package, * - package_id does not belong to the project group_id, * - release_id does not match with a valid release, * - release_id does not belong to the project group_id, * - the user does not have the permissions to create a file * - the md5 comparison failed * - the file creation failed. */ function addUploadedFile($sessionKey, $group_id, $package_id, $release_id, $filename, $type_id, $processor_id, $reference_md5, $comment) { if (session_continue($sessionKey)) { try { $pm = ProjectManager::instance(); $pm->getGroupByIdForSoap($group_id, 'addUploadedFile'); } catch (SoapFault $e) { return $e; } // retieve the package $pkg_fact = new FRSPackageFactory(); $package =& $pkg_fact->getFRSPackageFromDb($package_id); if (!$package || $package->getGroupID() != $group_id) { return new SoapFault(invalid_package_fault, 'Invalid Package', 'addUploadedFile'); } // retrieve the release $release_fact = new FRSReleaseFactory(); $release =& $release_fact->getFRSReleaseFromDb($release_id); if (!$release || $release->getPackageID() != $package_id) { return new SoapFault(invalid_release_fault, 'Invalid Release', 'addUploadedFile'); } $file_fact = new FRSFileFactory(); if ($file_fact->userCanAdd($group_id)) { $user = UserManager::instance()->getCurrentUser(); $file = new FRSFile(); $file->setRelease($release); $file->setFileName(basename($filename)); $file->setTypeID($type_id); $file->setProcessorID($processor_id); $file->setReferenceMd5($reference_md5); $file->setUserID($user->getId()); $file->setComment($comment); try { $file_fact->createFile($file); $release_fact->emailNotification($release); return $file->getFileID(); } catch (Exception $e) { return new SoapFault(invalid_file_fault, $e->getMessage(), 'addUploadedFile'); } } else { return new SoapFault(invalid_file_fault, 'User is not allowed to add a file', 'addUploadedFile'); } } else { return new SoapFault(invalid_session_fault, 'Invalid Session', 'addUploadedFile'); } }