]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
page stats
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 12 Mar 2024 11:49:14 +0000 (14:49 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 12 Mar 2024 11:49:14 +0000 (14:49 +0300)
erp24/commands/HelloController.php
erp24/migrations/m240312_111331_create_table_page_statistics.php [new file with mode: 0755]
erp24/web/index.php

index 9ec914d3c5afbcfc8fa3bac9e27040fb805bf3e5..f9f6ab03152445645319b80bb957cb16157ff1e6 100644 (file)
@@ -5,7 +5,7 @@
  * @license https://www.yiiframework.com/license/
  */
 
-namespace app\commands;
+namespace yii_app\commands;
 
 use yii\console\Controller;
 use yii\console\ExitCode;
diff --git a/erp24/migrations/m240312_111331_create_table_page_statistics.php b/erp24/migrations/m240312_111331_create_table_page_statistics.php
new file mode 100755 (executable)
index 0000000..310305c
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240312_111331_create_table_page_statistics
+ */
+class m240312_111331_create_table_page_statistics extends Migration
+{
+    const TABLE_NAME = "page_statistics";
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable(self::TABLE_NAME, [
+            'id' => $this->primaryKey(),
+            'admin_id' => $this->integer()->notNull()->comment('ID в таблице admins'),
+            'url' => $this->string()->notNull()->comment('api request url'),
+            'post' => $this->text()->null()->comment('POST параметры, если имеются'),
+            'created_at' => $this->datetime()->notNull()->comment('дата создания лога'),
+        ]);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropTable(self::TABLE_NAME);
+    }
+}
index 6062df6b6ff060ccc316d377b4a257e417b87769..8af96decc73acb32cb4e536198041d1160488a1a 100644 (file)
@@ -18,6 +18,22 @@ Yii::setAlias('@dist', dirname(__DIR__) . '/dist');
 
 $app = (new yii\web\Application($config));
 
+$url = Yii::$app->request->url;
+if (
+    !in_array($url, ['/notification/pending', '/site/menu-tree'])
+    && strpos($url, '/i/') !== 0
+    && strpos($url, '/debug/default/toolbar') !== 0
+    && strpos($url, '/assets/') !== 0
+) {
+    $postJson = Yii::$app->request->post();
+    unset($postJson["_csrf"]);
+    $post = \yii\helpers\Json::encode($postJson);
+    $app->db->createCommand(
+        'INSERT INTO page_statistics (admin_id, url, post, created_at) VALUES ("' . $_SESSION['admin_id'] . '", "'
+        . $url . '", :post, NOW())'
+    )->bindParam(':post', $post, PDO::PARAM_STR)->execute();
+}
+
 //$app->params['API2_TOKEN'] = $app->db->createCommand(
 //    'SELECT access_token FROM api_user WHERE "login"=\'erp\' LIMIT 1;')->queryAll()[0]['access_token'] ?? null;