/** * Adds a file attachment to an issue. */ private function addAttachmentToIssue(Issue $issue, RawFile $file, $attnum = 0) { // First we need to make sure we've got the filepath for the // client this issue is attached to. $client = $this->clientService->getClient($issue->clientid); if (!$client) { throw new Exception("Invalid request for attaching files to"); } $path = 'Clients/' . $client->title . '/Issues/' . $issue->id; if (!$this->fileService->createDirectory($path)) { throw new Exception("Failed creating directory {$path} for saving request files"); } $existing = $this->fileService->getFileByPath($path . '/' . $file->filename); if ($attnum && $file->filename == 'Email Attachment') { $file->filename .= " #{$attnum}"; } if (!$existing) { $existing = $this->fileService->createFile($file->filename, $path); } $this->fileService->setFileContent($existing, $file->content, $file->contentType); }