Skip to content

Commit 67e54dd

Browse files
committed
Exception != statusMessage
1 parent 5a43dc6 commit 67e54dd

File tree

10 files changed

+84
-49
lines changed

10 files changed

+84
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ cd /usr/share/php/AbraFlexi/tools && sudo ./update_all.sh
460460
Server ze kterého se struktura získává se nastavuje v souboru /etc/abraflexi/client.json
461461
nebo proměnnými prostředí definovanými zpravidla v /etc/profile.d/abraflexi-client.sh
462462

463-
Nainstalujte balíček php-abraflexi-config pro snadnou změnu těchto nastavení
463+
Nainstalujte balíček abraflexi-client-config pro snadnou změnu těchto nastavení
464464

465465

466466

debian/README.Debian

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ When your AbaraFlexi server was updated
1111
It is configured by /etc/abraflexi/client.json file or environment variables by
1212
default specified by in /etc/profile.d/abraflexi-client.sh
1313

14-
Install php-abraflexi-config package to modify connection settings
14+
Install abraflexi-client-config package to modify connection settings
1515

1616

1717
-- Vítězslav Dvořák <[email protected]> Ne říj 21 15:17:56 CEST 2021

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Package: php-spojenet-abraflexi
1010
Depends: ${misc:Depends}, php-curl,php-vitexsoftware-ease-core, composer
1111
Provides: php-abraflexi
1212
Conflicts: flexipeehp
13-
Suggests: php-abraflexi-config,abraflexi-client,abraflexi-contract-invoices,abraflexi-dark-gui,abraflexi-digest,abraflexi-matcher,abraflexi-reminder,abraflexi-server,abraflexi-server-backup,abraflexi-tools,multi-abraflexi-setup,abraflexi-mailer,php-vitexsoftware-ease-bootstrap4-widgets-abraflexi,php-vitexsoftware-abraflexi-bricks
13+
Suggests: abraflexi-client-config,abraflexi-client,abraflexi-contract-invoices,abraflexi-dark-gui,abraflexi-digest,abraflexi-matcher,abraflexi-reminder,abraflexi-server,abraflexi-server-backup,abraflexi-tools,multi-abraflexi-setup,abraflexi-mailer,php-vitexsoftware-ease-bootstrap4-widgets-abraflexi,php-vitexsoftware-abraflexi-bricks
1414
Architecture: all
1515
Section: web
1616
Priority: optional

debian/prerm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -f /usr/share/php/AbraFlexi/composer.lock

src/AbraFlexi/Exception.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,52 @@
1818
* @author vitex
1919
*/
2020
class Exception extends \Ease\Exception {
21-
public function __construct($message, $code = 0, \Ease\Exception $previous = null) {
22-
parent::__construct($message, $code, $previous);
21+
22+
/**
23+
* Original server response
24+
* @var string
25+
*/
26+
private $serverResponse = '';
27+
28+
/**
29+
* Error messages sit here
30+
* @var array
31+
*/
32+
private $errorMessages = [];
33+
34+
/**
35+
* AbraFlexi response as Exception
36+
*
37+
* @param string $message good to know
38+
*
39+
* @param RO $caller AbraFlexi Object
40+
*
41+
* @param \Ease\Exception $previous
42+
*/
43+
public function __construct($message, RO $caller, \Ease\Exception $previous = null) {
44+
$this->errorMessages = $caller->getErrors();
45+
$this->serverResponse = $caller->lastCurlResponse;
46+
parent::__construct(get_class($caller) . ': ' . $message, $caller->lastResponseCode, $previous);
47+
}
48+
49+
/**
50+
* Get (first) error message
51+
*
52+
* @param int $index which message
53+
*
54+
* @return string
55+
*/
56+
public function getErrorMessage($index = 0) {
57+
return $this->errorMessages[$index];
58+
}
59+
60+
/**
61+
* All stored Error messages
62+
*
63+
* @return array
64+
*/
65+
public function getErrorMessages() {
66+
return $this->errorMessages;
2367
}
68+
2469
}

src/AbraFlexi/Hooks.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function register($url, $format = 'json') {
4343
foreach ($hooks as $hook) {
4444
if (is_array($hook) && array_key_exists('url', $hook)) {
4545
if ($hook['url'] == $url) {
46-
$this->addStatusMessage(_('Url allready registered'),
47-
'warning');
46+
$this->addStatusMessage(sprintf(_('Url %s allready registered'), $url) , 'debug');
4847
return false;
4948
}
5049
}

src/AbraFlexi/Kontakt.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public function authenticate($login, $password) {
4949
'POST', 'xml');
5050
$this->defaultHttpHeaders = $defaultHttpHeaders;
5151
if (!empty($result['message'])) {
52-
$this->addStatusMessage($result['message'],
53-
$result['success'] == 'true' ? 'success' : 'warning' );
52+
$this->addStatusMessage($result['message'], $result['success'] == 'true' ? 'success' : 'warning' );
53+
if ($this->throwException == true && $result['success'] != 'true') {
54+
throw new Exception($result['message'], $this);
55+
}
5456
}
5557
return array_key_exists('success', $result) && $result['success'] == 'true';
5658
}

src/AbraFlexi/Priloha.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ public static function download($object, $format = 'pdf',
124124

125125
if (isset($attachmentID) && !array_key_exists($attachmentID,
126126
$attachments)) {
127-
$object->addStatusMessage(sprintf(_('Attagment %s does no exist'),
128-
$attachmentID), 'warning');
127+
$object->addStatusMessage(sprintf(_('Attachment %s does no exist'),$attachmentID), 'warning');
128+
if ($this->throwException == true) {
129+
throw new Exception(sprintf(_('Attachment %s does no exist'),$attachmentID), $this);
130+
}
131+
129132
}
130133

131134
$attachmentBody = $object->doCurlRequest(self::getDownloadUrl($object),

src/AbraFlexi/RO.php

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,9 @@ public function rawJsonToArray($rawJson) {
10631063
$responseDecoded = $this->nativeTypes ? $this->fixResponseTypes($responseDecoded[$this->nameSpace]) : $responseDecoded[$this->nameSpace];
10641064
}
10651065
} else {
1066-
if ($this->debug) {
1066+
if ($this->throwException == true) {
1067+
throw new Exception('JSON Decoder: ' . $decodeError, $this);
1068+
} else {
10671069
$this->addStatusMessage('JSON Decoder: ' . $decodeError, 'error');
10681070
$this->addStatusMessage($rawJson, 'debug');
10691071
}
@@ -1140,10 +1142,9 @@ public function parseResponse($responseDecoded, $responseCode) {
11401142
}
11411143
case 401:
11421144
$msg = (array_key_exists('message', $responseDecoded) ? $responseDecoded['message'] : $responseDecoded[key($responseDecoded)]['message']) . ' for ' . $this->getApiURL();
1145+
$this->addStatusMessage($msg, 'error');
11431146
if ($this->throwException) {
1144-
throw new Exception($msg);
1145-
} else {
1146-
$this->addStatusMessage($msg, 'error');
1147+
throw new Exception($msg, $this);
11471148
}
11481149
break;
11491150
case 404: // Page not found
@@ -1156,6 +1157,9 @@ public function parseResponse($responseDecoded, $responseCode) {
11561157
$this->parseError($responseDecoded);
11571158
}
11581159
$this->addStatusMessage($this->lastResponseCode . ': ' . $this->curlInfo['url'] . ' (' . $this->format . ') ' . json_encode($this->getErrors()), 'warning');
1160+
if ($this->throwException) {
1161+
throw new Exception('Problem', $this);
1162+
}
11591163
break;
11601164
}
11611165
return $mainResult;
@@ -1221,8 +1225,11 @@ public function doCurlRequest($url, $method, $format = null) {
12211225
$this->lastResponseCode = $this->curlInfo['http_code'];
12221226
$this->lastCurlError = curl_error($this->curl);
12231227
if (strlen($this->lastCurlError)) {
1224-
$this->addStatusMessage(sprintf('Curl Error (HTTP %d): %s',
1225-
$this->lastResponseCode, $this->lastCurlError), 'error');
1228+
$msg = sprintf('Curl Error (HTTP %d): %s', $this->lastResponseCode, $this->lastCurlError);
1229+
$this->addStatusMessage($msg, 'error');
1230+
if ($this->throwException) {
1231+
throw new Exception($msg, $this);
1232+
}
12261233
}
12271234

12281235
if ($this->debug === true) {
@@ -2398,18 +2405,19 @@ public function getAbraFlexiURL() {
23982405
public function setMyKey($myKeyValue) {
23992406
if (is_string($myKeyValue) && substr($myKeyValue, 0, 4) == 'ext:') {
24002407
if (empty($this->evidenceInfo) || ($this->evidenceInfo['extIdSupported'] == 'false')) {
2401-
$this->addStatusMessage(sprintf(_('Evidence %s does not support extIDs'),
2402-
$this->getEvidence()), 'warning');
2408+
$msg = sprintf(_('Evidence %s does not support extIDs'), $this->getEvidence());
2409+
$this->addStatusMessage($msg, 'warning');
2410+
if ($this->throwException) {
2411+
throw new Exception($msg, $this);
2412+
}
24032413
$res = false;
24042414
} else {
24052415
$extIds = $this->getDataValue('external-ids');
24062416
if (!empty($extIds) && count($extIds)) {
24072417
$extIds = array_combine($extIds, $extIds);
24082418
}
2409-
24102419
$extIds[$myKeyValue] = $myKeyValue;
2411-
$res = $this->setDataValue('external-ids',
2412-
$extIds);
2420+
$res = $this->setDataValue('external-ids', $extIds);
24132421
}
24142422
} else {
24152423
$res = $this->setDataValue($this->getKeyColumn(), $myKeyValue);
@@ -2786,25 +2794,6 @@ public function getErrors() {
27862794
return $this->errors;
27872795
}
27882796

2789-
/**
2790-
* Add message to stack to show or write to file
2791-
* Přidá zprávu do zásobníku pro zobrazení uživateli inbo do logu.
2792-
*
2793-
* @param string $message text zpravy
2794-
* @param string $type fronta
2795-
* @param string $caller Message source name
2796-
*
2797-
* @return boolean message added
2798-
*/
2799-
public function addStatusMessage($message, $type = 'info', $caller = null) {
2800-
$callerFinal = empty($caller) ? $this : $caller;
2801-
if (($this->throwException === true) && (($type == 'warning') || ($type == 'error') )) {
2802-
throw new Exception($type . ': ' . $message . "\n" . 'caller:' . (is_object($callerFinal) ? get_class($callerFinal) : $callerFinal ));
2803-
} else {
2804-
parent::addStatusMessage($message, $type, $callerFinal);
2805-
}
2806-
}
2807-
28082797
/**
28092798
* Reconnect After unserialization
28102799
*/

src/AbraFlexi/RW.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,12 @@ public function takeData($data) {
266266
if (count($fbColumns)) {
267267
foreach ($data as $key => $value) {
268268
if (!array_key_exists($key, $fbColumns)) {
269-
270-
if (!array_key_exists($key, $fbRelations)) {
271-
$this->addStatusMessage(sprintf('unknown column %s for evidence %s',
272-
$key, $this->getEvidence()), 'warning');
269+
if (array_key_exists($key, $fbRelations) && !is_array($value)) {
270+
$msg = sprintf('subevidence %s in evidence %s must bee an array', $key, $this->getEvidence());
273271
} else {
274-
if (!is_array($value)) {
275-
$this->addStatusMessage(sprintf('subevidence %s in evidence %s must bee an array',
276-
$key, $this->getEvidence()), 'warning');
277-
}
272+
$msg = sprintf('unknown column %s for evidence %s', $key, $this->getEvidence());
278273
}
274+
$this->addStatusMessage($msg, 'debug');
279275
}
280276
}
281277
}

0 commit comments

Comments
 (0)