diff --git a/app/Exceptions/InvalidXmlException.php b/app/Exceptions/InvalidXmlException.php
new file mode 100644
index 00000000..4db050d5
--- /dev/null
+++ b/app/Exceptions/InvalidXmlException.php
@@ -0,0 +1,9 @@
+get($filename);
try {
- if ($this->encapsulate) {
- $data = sprintf('%s', $data);
- /** @var SimpleXMLElement|false */
- $xmlContent = simplexml_load_string($data);
- } else {
- /** @var SimpleXMLElement|false */
- $xmlContent = simplexml_load_string($data, null, LIBXML_NOCDATA | LIBXML_PARSEHUGE);
- }
-
- if ($xmlContent === false) {
- $this->log(
- sprintf('File %s could not be parsed (simplexml_load_string)', $filename),
- LogType::critical()
- );
- continue; // ignore the file
+ try {
+ if ($this->encapsulate) {
+ $data = sprintf('%s', $data);
+ /** @var SimpleXMLElement|false */
+ $xmlContent = simplexml_load_string($data);
+ } else {
+ /** @var SimpleXMLElement|false */
+ $xmlContent = simplexml_load_string($data, null, LIBXML_NOCDATA | LIBXML_PARSEHUGE);
+ }
+ if ($xmlContent === false) {
+ throw new InvalidXmlException('XML is Invalid (simplexml_load_string returned false)');
+ }
+ } catch (ErrorException $e) {
+ throw new InvalidXmlException('XML is Invalid', 0, $e);
}
$data = $this->extract($xmlContent);
-
$lines = [];
-
foreach ($data[$entityName] as $traca) {
$line = $this->processFields($traca);
if ($callback) {
@@ -116,7 +122,7 @@ abstract class XmlJobs extends XArcadiaFlux
[$uniqueColumnsKey, $line]
);
}
- } catch (ErrorException | TypeError | QueryException $e) {
+ } catch (InvalidXmlException $e) {
$message = $e->getMessage();
if (get_class($e) === QueryException::class) {
$message = implode(' ', $e->errorInfo);
@@ -130,20 +136,38 @@ abstract class XmlJobs extends XArcadiaFlux
),
LogType::critical()
);
+ $this->sendInvalidXmlEmail($filename, $e);
+ $this->moveToInvalid($filename);
+ continue;
+ } catch (ErrorException | TypeError | QueryException $e) {
+ $message = $e->getMessage();
+ if (get_class($e) === QueryException::class) {
+ $message = implode(' ', $e->errorInfo);
+ }
+ $this->log(
+ sprintf(
+ 'CRITICAL: File %s could not be parsed => %s on line %d',
+ $filename,
+ $message,
+ $e->getLine()
+ ),
+ LogType::critical()
+ );
+ $this->sendErrorParseEmailToServiceWeb($e);
continue; // ignore the file
} catch (AbortXmlImportException $e) {
$this->log(
sprintf(
- 'File %s could not be parsed => %s on line %d',
+ 'ERROR: File %s could not be parsed => %s on line %d',
$filename,
$e->getMessage(),
$e->getLine()
),
LogType::error()
);
+ $this->sendErrorParseEmailToServiceWeb($e);
continue; // ignore the file
}
-
$this->moveToArchives($filename);
}
@@ -277,4 +301,53 @@ abstract class XmlJobs extends XArcadiaFlux
}
return $isXml;
}
+
+ protected function sendErrorParseEmailToServiceWeb(Throwable $e)
+ {
+ Mail::send('emails.exception', ['exception' => $e], function ($m) {
+ $m->to(
+ config('mail.contactsList.serviceweb'),
+ 'Le Gaulois Exception Handler'
+ )->subject('Could not eat INCO, because of its toxicity !');
+ });
+ }
+
+ protected function sendInvalidXmlEmail(string $filename, Throwable $e)
+ {
+ $message = $e->getPrevious()->getMessage();
+ Mail::send('emails.invalidxml', [
+ 'strError' => sprintf(
+ 'File %s could not be parsed => %s on line %d',
+ $filename,
+ $message,
+ $e->getLine()
+ ),
+ 'filename' => $filename,
+ 'exception' => $e->getPrevious()
+ ], function ($m) {
+ $m->to(
+ config('mail.contactsList.invalidInco'),
+ 'Le Gaulois Exception Handler'
+ )->subject('You sent me an invalid XML file, please check its validity before resend ASAP.');
+ });
+ }
+
+ /**
+ * Move the file to invalid folder
+ *
+ * @param string $filename
+ * @return void
+ */
+ protected function moveToInvalid(string $filename): void
+ {
+ if (!$this->getDisk()->move($filename, sprintf('%s/%s', $this->invalidFolderName, $filename))) {
+ $this->log(
+ sprintf(
+ 'File %s could not be moved to invalid folder name',
+ $filename
+ ),
+ LogType::warning()
+ );
+ }
+ }
}
diff --git a/config/mail.php b/config/mail.php
index cff0b98e..c3451abc 100644
--- a/config/mail.php
+++ b/config/mail.php
@@ -93,6 +93,11 @@ return [
'serviceweb' => env('MAIL_LIST_SERVICEWEB', 'informatique.internet@ldc.fr'),
'contact' => env('MAIL_LIST_CONTACT', 'contact.legaulois@ldc.fr'),
'passerelle' => env('MAIL_LIST_PASSERELLE', 'passerelle.ldc@ldc.fr'),
+ 'invalidInco' => [
+ 'informatique.internet@ldc.fr',
+ 'vincent.pierre@ldc.fr',
+ 'christelle.manceau@ldc.fr'
+ ],
'missingOcbBreeders' => [
'sylvain.gouet@ldc.fr',
'marine.detavernier@ldc.fr',
diff --git a/public/robots.txt b/public/robots.txt
index e756f682..2951dedf 100644
--- a/public/robots.txt
+++ b/public/robots.txt
@@ -4,4 +4,4 @@ Disallow:/login/*
Disallow:/mon-compte/*
Disallow:/connexion/*
-Sitemap: https://legaulois.fr/sitemap.xml
+Sitemap: https://www.legaulois.fr/sitemap.xml
diff --git a/resources/views/emails/exception.blade.php b/resources/views/emails/exception.blade.php
index 77ab3aa9..549fa1a7 100644
--- a/resources/views/emails/exception.blade.php
+++ b/resources/views/emails/exception.blade.php
@@ -14,4 +14,3 @@
Veuillez vérifier les logs pour en voir la trace.