Piotr Labudda 9 лет назад
Родитель
Сommit
9e39a8111b
1 измененных файлов с 48 добавлено и 4 удалено
  1. 48 4
      SE/se-lib/Route/Debug.php

+ 48 - 4
SE/se-lib/Route/Debug.php

@@ -53,17 +53,17 @@ class Route_Debug extends RouteBase {
         'caption' => "Log Files " . UI::h('a', [
           'href' => "index.php?_route=Debug&_task=viewLatestUserLog",
           'class' => "btn btn-xs btn-primary"
-        ], "pokaż ostatni") . " " . UI::hButtonPost("Remove all log files", [
+        ], "Pokaż ostatni log") . " " . UI::hButtonPost("Usuń wszystkie swoje pliki", [
           'class' => "btn-danger btn-xs",
           'data' => [
             '_route' => 'Debug',
-            '_task' => 'rmAllLogFiles'
+            '_task' => 'rmAllUserLogFiles'
           ]
-        ]) . " " . UI::hButtonPost("Remove old log files", [
+        ]) . " " . UI::hButtonPost("Usuń stare pliki", [
           'class' => "btn-warning btn-xs",
           'data' => [
             '_route' => 'Debug',
-            '_task' => 'rmOldLogFiles'
+            '_task' => 'rmOldUserLogFiles'
           ]
         ]),
         'cols' => [
@@ -323,6 +323,50 @@ class Route_Debug extends RouteBase {
       $this->defaultView(UI::h('div', ['class'=>"alert alert-danger"], $e->getMessage()));
     }
   }
+  public function rmAllUserLogFilesAction() {
+    session_write_close();
+    try {
+      $userLogin = User::getLogin();
+      $today = date("Y-m-d");
+      $cmd = "rm -v /tmp/se-debug-*-{$userLogin}-*.log 2>&1";
+      V::exec($cmd, $out, $ret);
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
+        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>',
+        (0 === $ret) ? "All Log Files Removed" : "Error?",
+        " (return code: {$ret})",
+        "<br>cmd: <code>{$cmd}</code>",
+        UI::h('pre', [], implode("\n", $out))
+      ]));
+    } catch (AlertSuccessException $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-success"], $e->getMessage()));
+    } catch (AlertWarningException $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-warning"], $e->getMessage()));
+    } catch (Exception $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-danger"], $e->getMessage()));
+    }
+  }
+  public function rmOldUserLogFilesAction() {
+    session_write_close();
+    try {
+      $userLogin = User::getLogin();
+      $today = date("Y-m-d");
+      $cmd = "ls -1 /tmp/se-debug-*-{$userLogin}-*.log | grep -v '/tmp/se-debug-{$today}-' | xargs rm -v 2>&1";
+      V::exec($cmd, $out, $ret);
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-success alert-dismissible"], [
+        '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>',
+        (0 === $ret) ? "Old Log Files Removed" : "Error?",
+        " (return code: {$ret})",
+        "<br>cmd: <code>{$cmd}</code>",
+        UI::h('pre', [], implode("\n", $out))
+      ]));
+    } catch (AlertSuccessException $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-success"], $e->getMessage()));
+    } catch (AlertWarningException $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-warning"], $e->getMessage()));
+    } catch (Exception $e) {
+      $this->defaultView(UI::h('div', ['class'=>"alert alert-danger"], $e->getMessage()));
+    }
+  }
   public function rmLogFileAction() {
     session_write_close();
     try {