From e146632624ac565eea83f22913f4c9a30d4d91d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=C4=9Bzslav=20Dvo=C5=99=C3=A1k?= Date: Mon, 9 Dec 2024 11:39:34 +0100 Subject: [PATCH] fail with correct exitcode --- debian/changelog | 11 ++++-- src/pohoda-raiffeisenbank-statements.php | 36 +++++++++++++++++-- ...L-raiffeisenbank-statements-sharepoint.php | 14 +++++++- ...isenbank-statements-sharepoint-checker.php | 9 ++--- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 09cb41b..e63938c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,15 @@ -pohoda-raiffeisenbank (1.1.1) UNRELEASED; urgency=medium +pohoda-raiffeisenbank (1.1.2) UNRELEASED; urgency=medium + * Fail with correct exitpode + + -- Mon, 09 Dec 2024 11:37:42 +0100 + +pohoda-raiffeisenbank (1.1.1) jammy; urgency=medium + + [ vitex ] * code cleanup. PohodaSQL attachnent fix - -- vitex Tue, 03 Dec 2024 00:45:54 +0100 + -- Mon, 09 Dec 2024 11:37:22 +0100 pohoda-raiffeisenbank (1.1.0) jammy; urgency=medium diff --git a/src/pohoda-raiffeisenbank-statements.php b/src/pohoda-raiffeisenbank-statements.php index 4e0fd08..7183ac9 100644 --- a/src/pohoda-raiffeisenbank-statements.php +++ b/src/pohoda-raiffeisenbank-statements.php @@ -22,11 +22,43 @@ /** * Get today's Statements list. */ -\Ease\Shared::init(['POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO', 'CERT_FILE', 'CERT_PASS', 'XIBMCLIENTID', 'ACCOUNT_NUMBER'], $argv[1] ?? '../.env'); +$options = getopt('o::e::', ['output::environment::']); +Shared::init( + [ + 'POHODA_URL', 'POHODA_USERNAME', 'POHODA_PASSWORD', 'POHODA_ICO', + 'CERT_FILE', 'CERT_PASS', 'XIBMCLIENTID', 'ACCOUNT_NUMBER', + ], + \array_key_exists('environment', $options) ? $options['environment'] : '../.env', +); +$destination = \array_key_exists('output', $options) ? $options['output'] : \Ease\Shared::cfg('RESULT_FILE', 'php://stdout'); + PohodaBankClient::checkCertificatePresence(\Ease\Shared::cfg('CERT_FILE')); $engine = new Statementor(\Ease\Shared::cfg('ACCOUNT_NUMBER')); $engine->setScope(\Ease\Shared::cfg('IMPORT_SCOPE', 'last_month')); $engine->logBanner('', 'Scope: '.$engine->scope); +$report = [ + 'sharepoint' => [], + 'pohoda' => [], + 'pohodaSQL' => [], +]; + +try { + $engine->downloadXML(); +} catch (\VitexSoftware\Raiffeisenbank\ApiException $exc) { + $report['mesage'] = $exc->getMessage(); + + $exitcode = $exc->getCode(); + + if (!$exitcode) { + if (preg_match('/cURL error ([0-9]*):/', $report['mesage'], $codeRaw)) { + $exitcode = (int) $codeRaw[1]; + } + } +} -$engine->downloadXML(); $inserted = $engine->import(); + +$written = file_put_contents($destination, json_encode($report, Shared::cfg('DEBUG') ? \JSON_PRETTY_PRINT : 0)); +$engine->addStatusMessage(sprintf(_('Saving result to %s'), $destination), $written ? 'success' : 'error'); + +exit($exitcode); diff --git a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php index 65947e0..ec5a7e3 100644 --- a/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php +++ b/src/pohodaSQL-raiffeisenbank-statements-sharepoint.php @@ -50,7 +50,19 @@ 'pohodaSQL' => [], ]; -$pdfStatements = $engine->downloadPDF(); +try { + $pdfStatements = $engine->downloadPDF(); +} catch (\VitexSoftware\Raiffeisenbank\ApiException $exc) { + $report['mesage'] = $exc->getMessage(); + + $exitcode = $exc->getCode(); + + if (!$exitcode) { + if (preg_match('/cURL error ([0-9]*):/', $report['mesage'], $codeRaw)) { + $exitcode = (int) $codeRaw[1]; + } + } +} if ($pdfStatements) { sleep(5); diff --git a/src/raiffeisenbank-statements-sharepoint-checker.php b/src/raiffeisenbank-statements-sharepoint-checker.php index b4c5387..3f50baf 100644 --- a/src/raiffeisenbank-statements-sharepoint-checker.php +++ b/src/raiffeisenbank-statements-sharepoint-checker.php @@ -88,11 +88,12 @@ } } catch (\VitexSoftware\Raiffeisenbank\ApiException $exc) { $report['mesage'] = $exc->getMessage(); - $engine->addStatusMessage($report['mesage'],'error'); + $engine->addStatusMessage($report['mesage'], 'error'); $exitcode = $exc->getCode(); - if(!$exitcode){ - if(preg_match('/cURL error ([0-9]*):/', $report['mesage'], $codeRaw)){ - $exitcode = (int)$codeRaw[1]; + + if (!$exitcode) { + if (preg_match('/cURL error ([0-9]*):/', $report['mesage'], $codeRaw)) { + $exitcode = (int) $codeRaw[1]; } } }