add Logging

This commit is contained in:
Marko 2024-07-30 17:01:34 +02:00
parent ac955e5988
commit 966905a3bf
No known key found for this signature in database
2 changed files with 34 additions and 14 deletions

View File

@ -16,7 +16,7 @@ when@prod:
handlers:
sentry:
type: sentry
level: !php/const Monolog\Logger::ERROR
level: !php/const Monolog\Logger::INFO
hub_id: Sentry\State\HubInterface
# Uncomment these lines to register a log message processor that resolves PSR-3 placeholders

View File

@ -37,7 +37,7 @@ class Hiltes
* @param string $data
* @return void
*/
public function export(string $data)
public function export(string $data) : void
{
try {
$new_file_path = $this->current_dir_path . "/hiltes/c2h/" . $this->createFileName();
@ -196,9 +196,6 @@ class Hiltes
$param = array(
'Username' => (!empty($usr) ? $usr : $this->hiltesUsr),
'Password' => (!empty($pass) ? $pass : $this->hiltesPass),
# 'parse_mode' => 'html',
# 'disable_notification' => $disable_notification,
# 'text' => $message_text
);
$r = $this->sendToHiltes($url, $param);
@ -238,6 +235,10 @@ class Hiltes
# Setup request to send json via POST.
$payload = json_encode($param);
if ($auth) {
$this->logger->info('Send Order ' . $url . ' ' . $payload);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', $authorization));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
# Return response instead of printing.
@ -254,7 +255,7 @@ class Hiltes
* @param mixed $data The data to be converted to JSON.
* @return array The JSON object.
*/
public function createJson($data)
public function createJson($data) : array
{
$arr = array(
'File' => array(
@ -359,21 +360,40 @@ class Hiltes
}
$t = json_decode($r, true);
$order = $this->orderRepository->findOneBy(array('orderId' => $data['SaleList'][0]['OrderNumber']));
try {
$order = $this->orderRepository->findOneBy(array('orderId' => $data['SaleList'][0]['OrderNumber']));
$order->setStatus(3);
$order->setHiltes($t);
$this->orderRepository->update($order, true);
} catch (\Exception $exception) {
$this->logger->error('Send Order Error ' . $exception->getMessage() . __LINE__);
if (!$order) {
$this->logger->error('Order not found ' . $data['SaleList'][0]['OrderNumber']);
return false;
}
if ($t['Success']) {
try {
//Status 3 für erfolgreich exportiert
$order->setStatus(3);
$order->setHiltes($t);
$this->orderRepository->update($order, true);
} catch (\Exception $exception) {
$this->logger->error('Send Order Error ' . $exception->getMessage() . __LINE__);
return false;
}
return true;
} else {
try {
//Status 4 für Fehler
$order->setStatus(4);
$order->setHiltes($t);
$this->orderRepository->update($order, true);
} catch (\Exception $exception) {
$this->logger->error('Send Order Error ' . $exception->getMessage() . __LINE__);
return false;
}
$this->logger->error('Send Order Error ' . var_export($t['errors'], 1) . __LINE__);
return false;
}