From 966905a3bf9d2ad50d07363d2d9351db26826f8b Mon Sep 17 00:00:00 2001 From: Marko <52066939+HeX87@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:01:34 +0200 Subject: [PATCH] add Logging --- config/packages/sentry.yaml | 2 +- src/Helper/Hiltes.php | 46 ++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/config/packages/sentry.yaml b/config/packages/sentry.yaml index 86faa51..173ac9d 100644 --- a/config/packages/sentry.yaml +++ b/config/packages/sentry.yaml @@ -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 diff --git a/src/Helper/Hiltes.php b/src/Helper/Hiltes.php index e5de590..44fe874 100644 --- a/src/Helper/Hiltes.php +++ b/src/Helper/Hiltes.php @@ -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; }