From 15d9e87bb7730a9e4917fa56f40854fafee1a84d Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Sun, 16 Aug 2020 18:21:01 +0200 Subject: [PATCH] ingest pdf file artisan command --- app/Console/Commands/IngestPdfFiles.php | 94 +++++++++++++++++++++++++ app/Http/Controllers/Controller.php | 1 - app/Http/Controllers/HomeController.php | 2 +- app/PdfFile.php | 8 ++- 4 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 app/Console/Commands/IngestPdfFiles.php diff --git a/app/Console/Commands/IngestPdfFiles.php b/app/Console/Commands/IngestPdfFiles.php new file mode 100644 index 0000000..1377f14 --- /dev/null +++ b/app/Console/Commands/IngestPdfFiles.php @@ -0,0 +1,94 @@ +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; + + + + } + + + } +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 854e0c7..09fcf5b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -18,5 +18,4 @@ class Controller extends BaseController } } - } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 91a573b..e332c49 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -15,7 +15,7 @@ class HomeController extends Controller */ public function index() { - \View::share('last_pdf', PdfFile::query()->orderByDesc('id')->published()->take(7)->get()); + \View::share('last_pdf', PdfFile::query()->orderByDesc('created_at')->published()->take(7)->get()); return view('home.index'); } diff --git a/app/PdfFile.php b/app/PdfFile.php index 0cce635..0b8aaef 100644 --- a/app/PdfFile.php +++ b/app/PdfFile.php @@ -67,6 +67,7 @@ class PdfFile extends TwillModel implements Sortable 'ref', 'headlines', 'published', + 'created_at' ]; protected $casts = [ @@ -127,9 +128,10 @@ class PdfFile extends TwillModel implements Sortable $this->makeJson(); $this->makeCover(); -// $this->makeSearchable(); -// if(!env('APP_ENV') === 'local') -// $this->shortenLinks(); + if(!config('app.env') === 'local'){ + $this->shortenLinks(); + $this->makeSearchable(); + } $this->saveToCloud(); } -- 2.39.5