argument('id')); $attachment = $repository->findWithoutUser($attachmentId); $attachmentName = trim($this->argument('name')); $storagePath = realpath(trim($this->argument('directory'))); if (is_null($attachment->id)) { $this->error(sprintf('No attachment with id #%d', $attachmentId)); Log::error(sprintf('DecryptAttachment: No attachment with id #%d', $attachmentId)); return; } if ($attachmentName !== $attachment->filename) { $this->error('File name does not match.'); Log::error('DecryptAttachment: File name does not match.'); return; } if (!is_dir($storagePath)) { $this->error(sprintf('Path "%s" is not a directory.', $storagePath)); Log::error(sprintf('DecryptAttachment: Path "%s" is not a directory.', $storagePath)); return; } if (!is_writable($storagePath)) { $this->error(sprintf('Path "%s" is not writable.', $storagePath)); Log::error(sprintf('DecryptAttachment: Path "%s" is not writable.', $storagePath)); return; } $fullPath = $storagePath . DIRECTORY_SEPARATOR . $attachment->filename; $content = $repository->getContent($attachment); $this->line(sprintf('Going to write content for attachment #%d into file "%s"', $attachment->id, $fullPath)); $result = file_put_contents($fullPath, $content); if ($result === false) { $this->error('Could not write to file.'); return; } $this->info(sprintf('%d bytes written. Exiting now..', $result)); return; } }