From 3c4f1f712ab942e80efaece69604ad89767cfd10 Mon Sep 17 00:00:00 2001 From: "Siwat T." Date: Sun, 2 Jun 2024 17:18:02 +0700 Subject: [PATCH] feat: support multiple number document in FetchEmailCommand --- app/Console/Commands/FetchEmailCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/FetchEmailCommand.php b/app/Console/Commands/FetchEmailCommand.php index 90a53da..fc95d7c 100644 --- a/app/Console/Commands/FetchEmailCommand.php +++ b/app/Console/Commands/FetchEmailCommand.php @@ -105,7 +105,11 @@ public function handle(): void $this->line('- Processing message '.$subject); $subject = str_replace(['Copy of ', 'สำเนา '], '', $subject); $list = []; - if (preg_match('/(?:สพจ|SMCU)(?:\.|\s|-){1,2}(\d+)(?:_|-|\/)(25\d\d)(?:\s|-).+/i', $subject, $list, PREG_UNMATCHED_AS_NULL)) { + // Regex pattern for document title; e.g. + // SMCU 623-624_2567 ขอความอนุเคราะห์ใช้สถานที่.pdf OR + // สพจ. 623-2567 ขอความอนุเคราะห์ใช้สถานที่.pdf + if (preg_match('/(?:สพจ|SMCU)(?:\.|\s|-){1,2}(\d+)(?:_|-|\/)(?:\d+(?:_|-|\/))?(25\d\d)(?:\s|-).+/i', $subject, $list, + PREG_UNMATCHED_AS_NULL)) { $document = Document::where('number', $list[1])->where('year', $list[2])->first(); if ($document) { $this->line('-- Found update of document '.$document->id.' ('.$document->number.'/'.$document->year.') '.$document->title);