function testCreateFileDoNotSetReleaseTimeIfAlreadySet() { $p = new MockProject($this); $p->setReturnValue('getUnixName', 'prj'); $r = new FRSRelease(); $r->setReleaseID(456); $r->setPackageID(123); $r->setGroupID(1113); $r->setProject($p); $f = new FRSFile(); $f->setRelease($r); $f->setGroup($p); $f->setFileName('file_sample'); $f->setReleaseTime(3125); $f->setPostDate(3125); $dao = new MockFRSFileDao($this); stub($dao)->searchFileByName()->returnsEmptyDar(); $ff = new FRSFileFactoryFakeCreation(); $ff->setReturnValue('create', 55); $ff->setReturnValue('moveFileForge', True); $ff->dao = $dao; $rf = new MockFRSReleaseFactory($this); $rf->setReturnValue('getFRSReleaseFromDb', $r); $ff->release_factory = $rf; $before = time(); $ff->createFile($f); $after = time(); $this->assertTrue($f->getPostDate() == 3125); $this->assertTrue($f->getReleaseTime() == 3125); }
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); }