From cd6bc5e6bc7eda33c8ec58ef833d860c85498df0 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Mon, 14 Sep 2020 11:52:15 +0200 Subject: [PATCH] regex ingest file --- app/Console/Commands/IngestPdfFiles.php | 13 ++++++++++--- app/PdfFile.php | 2 +- config/horizon.php | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/IngestPdfFiles.php b/app/Console/Commands/IngestPdfFiles.php index 987460e..316ddba 100644 --- a/app/Console/Commands/IngestPdfFiles.php +++ b/app/Console/Commands/IngestPdfFiles.php @@ -53,9 +53,16 @@ class IngestPdfFiles extends Command if($this->argument('mode') === 'fileName'){ $fileName = basename($path, '.pdf'); - $ref = Str::after($fileName, 'PSQ '); - $date = \File::lastModified($path); - $date = Carbon::createFromFormat("U", $date); + $regex = "/PSQ (?\d{4}) - (?\d\d_\d\d_\d\d)/"; + if(preg_match($regex, $fileName, $matches)) { + $ref = $matches['number']; + + } else { + $this->error('Could not parse file name'); + continue; + } + + $date = Carbon::createFromFormat("d_m_y", $matches['date']); } else { $fileName = basename($path, '.pdf'); diff --git a/app/PdfFile.php b/app/PdfFile.php index 37938c6..3691412 100644 --- a/app/PdfFile.php +++ b/app/PdfFile.php @@ -573,7 +573,7 @@ class PdfFile extends TwillModel implements Sortable */ public static function last(): Builder { - return self::query()->orderByDesc('id'); + return self::query()->orderByDesc('created_at'); } /** diff --git a/config/horizon.php b/config/horizon.php index 3a7752c..866e3e5 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -172,6 +172,7 @@ return [ 'balance' => 'simple', 'processes' => 10, 'tries' => 1, + 'timeout' => 300, ], ], -- 2.39.5