/** * Get the field data for artifact submission * @throws Tracker_Artifact_Attachment_FileNotFoundException * @throws Tracker_Artifact_Attachment_AlreadyLinkedToAnotherArtifactException */ public function buildFieldDataForREST($rest_value, Tracker_Artifact $artifact = null) { $field_data = array(); $already_attached_file_ids = array(); if ($artifact) { $already_attached_file_ids = $this->getAlreadyAttachedFileIds($artifact); } $given_rest_file_ids = $rest_value->value; // Ids given in REST foreach ($given_rest_file_ids as $file_id) { $linked_artifact = $this->file_info_factory->getArtifactByFileInfoIdInLastChangeset($file_id); // Temporary => link if (!$linked_artifact && $this->isFileIdTemporary($file_id)) { $temporary_file = $this->getFile($file_id); if (!$this->exists($temporary_file->getTemporaryName())) { throw new Tracker_Artifact_Attachment_FileNotFoundException('Temporary file #' . $file_id . ' not found'); } $field_data[] = $this->file_info_factory->buildFileInfoData($temporary_file, $this->getPath($temporary_file->getTemporaryName())); } elseif (!$linked_artifact && !$this->isFileIdTemporary($file_id)) { throw new Tracker_Artifact_Attachment_FileNotFoundException('Temporary file #' . $file_id . ' not found'); // Already attached to another artifact => error } elseif ($artifact && $artifact->getId() != $linked_artifact->getId() || !$artifact && $linked_artifact) { throw new Tracker_Artifact_Attachment_AlreadyLinkedToAnotherArtifactException('File #' . $file_id . ' is already linked to artifact #' . $linked_artifact->getId()); } } // Already attached file ids foreach ($already_attached_file_ids as $file_id) { // Not in given ids => unlink if (!in_array($file_id, $given_rest_file_ids)) { $field_data['delete'][] = $file_id; } } return $field_data; }
/** * Return a part of the requested attachment, base64 encoded. * * @param String $session_key * @param Integer $artifact_id * @param Integer $attachment_id * @param Integer $offset * @param Integer $size * * @return String */ public function getArtifactAttachmentChunk($session_key, $artifact_id, $attachment_id, $offset, $size) { try { $current_user = $this->soap_request_validator->continueSession($session_key); $artifact = $this->getArtifactById($artifact_id, $current_user, 'getArtifactAttachmentChunk'); $file_info = $this->fileinfo_factory->getById($attachment_id); if ($file_info && $file_info->fileExists()) { $field = $file_info->getField(); if ($field->userCanRead($current_user)) { return $file_info->getContent($offset, $size); } else { return new SoapFault(invalid_field_fault, 'Permission denied: you cannot access this field'); } } else { return new SoapFault(invalid_field_fault, 'Permission denied: you cannot access this field'); } } catch (Exception $e) { return new SoapFault((string) $e->getCode(), $e->getMessage()); } }