From: Louis Jeckel Date: Mon, 14 Sep 2020 09:52:15 +0000 (+0200) Subject: regex ingest file X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=cd6bc5e6bc7eda33c8ec58ef833d860c85498df0;p=psq.git regex ingest file --- 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, ], ],