private function addFilesIntoArchive(Tracker_Artifact_ChangesetValue_File $value, ZipArchive $archive) { $archive->addEmptyDir(self::DATA_DIR); foreach ($value->getFiles() as $file_info) { $archive->addFile($file_info->getPath(), self::DATA_DIR . DIRECTORY_SEPARATOR . self::FILE_PREFIX . $file_info->getId()); } }
private function addFilesIntoArchive(Tracker_Artifact_ChangesetValue_File $value, ArchiveInterface $archive) { $archive->addEmptyDir(ArchiveInterface::DATA_DIR); foreach ($value->getFiles() as $file_info) { $path_in_archive = ArchiveInterface::DATA_DIR . DIRECTORY_SEPARATOR . self::FILE_PREFIX . $file_info->getId(); if (file_exists($file_info->getPath())) { $archive->addFile($path_in_archive, $file_info->getPath()); } else { $archive->addFromString($path_in_archive, $file_info->getPath()); } } }
public function testSoapValue_with_lot_of_files() { $description = 'struff'; $submitted_by = 112; $filesize = 69874; $filetype = 'image/png'; $attachment1_id = 12; $filename1 = 'Screenshot1.png'; $attachment2_id = 13; $filename2 = 'Screenshot2.png'; $attachment3_id = 14; $filename3 = 'Screenshot3.png'; $field = new MockTracker_FormElement_Field_File(); $info1 = new Tracker_FileInfo($attachment1_id, $field, $submitted_by, $description, $filename1, $filesize, $filetype); $info2 = new Tracker_FileInfo($attachment2_id, $field, $submitted_by, $description, $filename2, $filesize, $filetype); $info3 = new Tracker_FileInfo($attachment3_id, $field, $submitted_by, $description, $filename3, $filesize, $filetype); $value_file = new Tracker_Artifact_ChangesetValue_File(111, $field, false, array($info1, $info2, $info3)); $this->assertEqual($value_file->getSoapValue($this->user), array('file_info' => array(array('id' => $attachment1_id, 'description' => $description, 'submitted_by' => $submitted_by, 'filename' => $filename1, 'filesize' => $filesize, 'filetype' => $filetype, 'action' => ''), array('id' => $attachment2_id, 'description' => $description, 'submitted_by' => $submitted_by, 'filename' => $filename2, 'filesize' => $filesize, 'filetype' => $filetype, 'action' => ''), array('id' => $attachment3_id, 'description' => $description, 'submitted_by' => $submitted_by, 'filename' => $filename3, 'filesize' => $filesize, 'filetype' => $filetype, 'action' => '')))); }
function testSoapValue_with_lot_of_files() { $info1 = new MockTracker_FileInfo(); $info1->setReturnValue('getFilename', 'Screenshot1.png'); $info2 = new MockTracker_FileInfo(); $info2->setReturnValue('getFilename', 'Screenshot2.png'); $info3 = new MockTracker_FileInfo(); $info3->setReturnValue('getFilename', 'Screenshot3.png'); $field = new MockTracker_FormElement_Field_File(); $file_1 = new Tracker_Artifact_ChangesetValue_File(111, $field, false, array($info1, $info2, $info3)); $this->assertEqual($file_1->getSoapValue(), "Screenshot1.png,Screenshot2.png,Screenshot3.png"); }
/** * Returns a diff between this changeset value and the one passed in param * * @param Tracker_Artifact_ChangesetValue_File $changeset_value the changeset value to compare * @param PFUser $user The user or null * * @return string The difference between another $changeset_value, false if no differneces */ public function diff($changeset_value, $format = 'html', PFUser $user = null) { if ($this->files !== $changeset_value->getFiles()) { $result = ''; $removed = array(); foreach (array_diff($changeset_value->getFiles(), $this->files) as $fi) { $removed[] = $fi->getFilename(); } if ($removed = implode(', ', $removed)) { $result .= $removed . ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'removed'); } $added = array(); foreach (array_diff($this->files, $changeset_value->getFiles()) as $fi) { $added[] = $fi->getFilename(); } if ($added = implode(', ', $added)) { if ($result) { $result .= PHP_EOL; } $result .= $added . ' ' . $GLOBALS['Language']->getText('plugin_tracker_artifact', 'added'); } return $result; } return false; }