Esempio n. 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);
 }