Skip to content

Commit

Permalink
fail with correct exitcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Vítězslav Dvořák committed Dec 9, 2024
1 parent 251602c commit e146632
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
11 changes: 9 additions & 2 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
pohoda-raiffeisenbank (1.1.1) UNRELEASED; urgency=medium
pohoda-raiffeisenbank (1.1.2) UNRELEASED; urgency=medium

* Fail with correct exitpode

-- <vitezslav.dvorak@spojenet.cz> Mon, 09 Dec 2024 11:37:42 +0100

pohoda-raiffeisenbank (1.1.1) jammy; urgency=medium

[ vitex ]
* code cleanup. PohodaSQL attachnent fix

-- vitex <info@vitexsoftware.cz> Tue, 03 Dec 2024 00:45:54 +0100
-- <vitezslav.dvorak@spojenet.cz> Mon, 09 Dec 2024 11:37:22 +0100

pohoda-raiffeisenbank (1.1.0) jammy; urgency=medium

Expand Down
36 changes: 34 additions & 2 deletions src/pohoda-raiffeisenbank-statements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
14 changes: 13 additions & 1 deletion src/pohodaSQL-raiffeisenbank-statements-sharepoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/raiffeisenbank-statements-sharepoint-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
Expand Down

0 comments on commit e146632

Please # to comment.