Esempio n. 1
0
 /**
  * file_to_soap : return the soap FRSFile structure giving a PHP FRSFile Object.
  * @access private
  * 
  * WARNING : We check the permissions here : only the readable files are returned.
  *
  * @param Object{FRSFile} $file the file to convert.
  * @return array the SOAPFRSFile corresponding to the FRSFile Object
  */
 function file_to_soap(FRSFile $file)
 {
     $return = null;
     if ($file->isError()) {
         //skip if error
     } else {
         // for the moment, no permissions on files
         $return = array('file_id' => $file->getFileID(), 'release_id' => $file->getReleaseID(), 'file_name' => $file->getFileName(), 'file_size' => $file->getFileSize(), 'type_id' => $file->getTypeID(), 'processor_id' => $file->getProcessorID(), 'release_time' => $file->getReleaseTime(), 'post_date' => $file->getPostDate(), 'computed_md5' => $file->getComputedMd5(), 'reference_md5' => $file->getReferenceMd5(), 'user_id' => $file->getUserID(), 'comment' => $file->getComment());
     }
     return $return;
 }
Esempio n. 2
0
 /**
  * Create a new file based on given objects
  *
  * Given a "transient" file object, physically move the file from it's landing zone to
  * it's release area and create the corresponding entry in the database.
  *
  * @param FRSFile    $file    File to create
  *
  * @return FRSFile
  */
 public function createFile(FRSFile $file, $extraFlags = self::COMPUTE_MD5)
 {
     $rule = new Rule_FRSFileName();
     if (!$rule->isValid($file->getFileName())) {
         throw new FRSFileIllegalNameException($file);
     }
     $rel = $file->getRelease();
     if ($this->isFileBaseNameExists($file->getFileName(), $rel->getReleaseID(), $rel->getGroupID())) {
         throw new FRSFileExistsException($file);
     }
     if ($this->isSameFileMarkedToBeRestored($file->getFileName(), $rel->getReleaseID(), $rel->getGroupID())) {
         throw new FRSFileToBeRestoredException($file);
     }
     clearstatcache();
     $filePath = $this->getSrcDir($rel->getProject()) . '/' . $file->getFileName();
     if (!file_exists($filePath)) {
         throw new FRSFileInvalidNameException($file);
     }
     if (0 != ($extraFlags & self::COMPUTE_MD5)) {
         $file->setComputedMd5(PHP_BigFile::getMd5Sum($filePath));
         if (!$this->compareMd5Checksums($file->getComputedMd5(), $file->getReferenceMd5())) {
             throw new FRSFileMD5SumException($file);
         }
     }
     $file->setFileSize(PHP_BigFile::getSize($filePath));
     $file->setStatus('A');
     $now = time();
     if ($file->getReleaseTime() === null) {
         $file->setReleaseTime($now);
     }
     if ($file->getPostDate() === null) {
         $file->setPostDate($now);
     }
     if ($this->moveFileForge($file)) {
         $fileId = $this->create($file->toArray());
         if ($fileId) {
             $file->setFileID($fileId);
             return $file;
         } else {
             throw new FRSFileDbException($file);
         }
     } else {
         throw new FRSFileForgeException($file);
     }
 }