--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\FileCollection;
+use App\PdfFile;
+use Carbon\Carbon;
+use Illuminate\Console\Command;
+use Illuminate\Http\File;
+use Illuminate\Support\Str;
+
+class IngestPdfFiles extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'pdf:ingest';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Ingests Pdf Files';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ * @throws \Spatie\PdfToImage\Exceptions\PdfDoesNotExist
+ */
+ public function handle()
+ {
+ $files = \Storage::files('ingest');
+
+
+ foreach ($files as $file) {
+ $path = \Storage::path($file);
+ $fileName = basename($path, '.pdf');
+ $ref = Str::after($fileName, 'PSQ ');
+
+ $lastModified = \File::lastModified($path);
+ $lastModified = Carbon::createFromFormat("U", $lastModified);
+
+ $collection = FileCollection::findOrFail(1);
+ $title = "{$collection->short_name} - $ref";
+
+ if(PdfFile::where('ref', $ref)->exists()) {
+ $this->warn("$title already exists");
+ continue;
+ }
+
+ /** @var PdfFile $pdfFile */
+ $pdfFile = PdfFile::create([
+ 'ref' => $ref,
+ 'collection_id' => $collection->id,
+ 'slug' => Str::slug("{$collection->slug}_{$ref}"),
+ 'title' => $title,
+ 'headlines' => [],
+ 'published' => 1,
+ 'created_at' => $lastModified
+ ]);
+
+ $this->info("$pdfFile created. Processing file.");
+
+ \Storage::makeDirectory($pdfFile->directory);
+
+ copy($path, $pdfFile->absolutePdfPath);
+
+ $pdfFile->process();
+
+ $this->info("$pdfFile ingested");
+
+ return;
+
+
+
+ }
+
+
+ }
+}