]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-493 Команда для очистки логов origin/feature_filippov_erp-493_api_logs_clear_scheduler
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Wed, 19 Nov 2025 12:07:27 +0000 (15:07 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Wed, 19 Nov 2025 12:07:27 +0000 (15:07 +0300)
erp24/commands/CronClearController.php [new file with mode: 0644]

diff --git a/erp24/commands/CronClearController.php b/erp24/commands/CronClearController.php
new file mode 100644 (file)
index 0000000..e58c734
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace yii_app\commands;
+
+use Yii;
+use yii\console\Controller;
+use yii\console\ExitCode;
+use yii_app\records\ApiLogs;
+
+/**
+ * CronClear command controller
+ */
+class CronClearController extends Controller
+{
+    /**
+     * Default action
+     * @return int Exit code
+     */
+    public function actionIndex()
+    {
+        echo "CronClear command executed\n";
+
+        return ExitCode::OK;
+    }
+
+    /**
+     * Clear old API logs older than 8 days
+     * @return int Exit code
+     */
+    public function actionClearOldApiLogs()
+    {
+        echo "Starting cleanup of old API logs...\n";
+
+        try {
+            $deletedCount = ApiLogs::deleteAll(
+                ['<', 'date', new \yii\db\Expression("NOW() - INTERVAL '8 days'")]
+            );
+
+            echo "Successfully deleted {$deletedCount} old API log records\n";
+
+            return ExitCode::OK;
+        } catch (\Exception $e) {
+            echo "Error during cleanup: " . $e->getMessage() . "\n";
+            return ExitCode::UNSPECIFIED_ERROR;
+        }
+    }
+}