示例#1
0
 private function importFile(Project $project, FRSRelease $release, PFUser $user, SimpleXMLElement $xml_file, $extraction_path)
 {
     $user = empty($xml_file->user) ? $user : $this->user_finder->getUser($xml_file->user);
     $attrs = $xml_file->attributes();
     $src = $extraction_path . '/' . $attrs['src'];
     $name = isset($attrs['name']) ? (string) $attrs['name'] : basename($src);
     $md5 = strtolower(md5_file($src));
     $time = strtotime($attrs['release-time']);
     $date = strtotime($attrs['post-date']);
     $desc = "";
     $type_id = $this->getFileTypeDao()->searchTypeId($attrs['filetype']);
     if (is_null($type_id)) {
         throw new Exception("Invalid filetype '{$attrs['filetype']}'");
     }
     $proc_id = $this->getProcessorDao()->searchProcessorId($project->getID(), $attrs['arch']);
     if (is_null($proc_id)) {
         throw new Exception("Invalid architecture '{$attrs['arch']}'");
     }
     foreach ($xml_file->children() as $elem) {
         if ($elem->getName() != "description") {
             continue;
         }
         $desc .= (string) $elem;
     }
     if (isset($attrs['md5sum'])) {
         $expected_md5 = strtolower($attrs['md5sum']);
         if ($expected_md5 != $md5) {
             throw new Exception("Import of file {$src} failed because the file is corrupted " . "(expected MD5 {$expected_md5}, got {$md5})");
         }
     }
     $dirPath = $this->file_factory->getSrcDir($project);
     $dest = "{$dirPath}/{$name}";
     if (!copy($src, $dest)) {
         throw new Exception("Could not copy {$src} to {$dest}");
     }
     $newFile = new FRSFile();
     $newFile->setGroup($project);
     $newFile->setRelease($release);
     $newFile->setFileName($name);
     $newFile->setProcessorID($proc_id);
     $newFile->setTypeID($type_id);
     $newFile->setReferenceMd5($md5);
     $newFile->setComputedMd5($md5);
     $newFile->setUserId($user->getId());
     $newFile->setComment($desc);
     $newFile->setReleaseTime($time);
     $newFile->setPostDate($date);
     $this->file_factory->createFile($newFile);
 }
示例#2
0
 /**
  * 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');
     }
 }
示例#3
0
 function testCreateFileIllegalName()
 {
     $ff = new FRSFileFactory();
     $f = new FRSFile();
     $f->setFileName('%toto#.txt');
     try {
         $ff->createFile($f);
     } catch (Exception $e) {
         $this->assertIsA($e, 'FRSFileIllegalNameException');
     }
 }