]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Логирование в файл
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 26 Feb 2025 12:29:00 +0000 (15:29 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 26 Feb 2025 12:29:00 +0000 (15:29 +0300)
erp24/.gitignore
erp24/media/controllers/NotificationController.php

index c25408fcb4a45b289de527a03f1ba07b4ebfcdc3..8943eaeda17a127c56f37b2db685fc72b89d871b 100644 (file)
@@ -40,4 +40,5 @@ tests/_support/_generated
 /data/*
 /runtime/*
 /api2/runtime/*
-/api2/json/*
\ No newline at end of file
+/api2/json/*
+/media/notification/*
\ No newline at end of file
index b36e951d19f4a3ae0d43dab6d18aad723938e989..9c5ef109af415f7099ff53f37aee648a6fabcd70 100644 (file)
@@ -22,6 +22,9 @@ use yii_app\services\MarketplaceService;
 
 class NotificationController extends Controller
 {
+    const OUT_DIR =
+        //"/www/media/notification";
+        "/var/www/erp24/media/notification";
     public function actionTest()
     {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
@@ -66,11 +69,21 @@ class NotificationController extends Controller
         */
 
         $rawBody = Yii::$app->request->getRawBody();
+        file_put_contents(
+            self::OUT_DIR . '/notifications.json',
+            PHP_EOL . date('Y-m-d H:i:s') . ' ' . $rawBody,
+            FILE_APPEND
+        );
         try {
             $data = Json::decode($rawBody);
         } catch (\Exception $e) {
             Yii::error("Ошибка декодирования JSON: " . $e->getMessage());
             Yii::$app->response->statusCode = 400;
+            file_put_contents(
+                self::OUT_DIR . '/notification_error.txt',
+                PHP_EOL . date("d.m.Y H:i:s", time()) . " " . $e->getMessage() . $e->getLine(),
+                FILE_APPEND
+            );
             return $this->asJson([
                 'error' => [
                     'type' => 'WRONG_EVENT_FORMAT',
@@ -285,6 +298,11 @@ class NotificationController extends Controller
                             $returnedAt = $orderReturnData['returnedAt'];
                         } catch (\Exception $e) {
                             Yii::$app->response->statusCode = 400;
+                            file_put_contents(
+                                self::OUT_DIR . '/notification_error.txt',
+                                PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . $e->getLine(),
+                                FILE_APPEND
+                            );
                             return $this->asJson([
                                 'error' => [
                                     'type' => 'WRONG_EVENT_FORMAT',
@@ -339,6 +357,11 @@ class NotificationController extends Controller
 
                 default:
                     Yii::info("Неизвестный тип события: {$eventType}");
+                    file_put_contents(
+                        self::OUT_DIR . '/notification_error.txt',
+                        PHP_EOL . date("d.m.Y H:i:s", time()) . " Неизвестный тип события: {$eventType}",
+                        FILE_APPEND
+                    );
                     return $this->asJson([
                         'success' => true,
                         'message' => 'Unknown event ignored'
@@ -346,6 +369,11 @@ class NotificationController extends Controller
             }
         } catch (\Exception $e) {
             Yii::error("Error processing event {$eventType}: " . $e->getMessage());
+            file_put_contents(
+                self::OUT_DIR . '/notification_error.txt',
+                PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . $e->getLine(),
+                FILE_APPEND
+            );
             Yii::$app->response->statusCode = 500;
             return $this->asJson([
                 'error' => [