From 2ef7d50f44b408994ed2d2bbdc6f01902e889ec4 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 12 Mar 2024 14:49:14 +0300 Subject: [PATCH] page stats --- erp24/commands/HelloController.php | 2 +- ...12_111331_create_table_page_statistics.php | 32 +++++++++++++++++++ erp24/web/index.php | 16 ++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 erp24/migrations/m240312_111331_create_table_page_statistics.php diff --git a/erp24/commands/HelloController.php b/erp24/commands/HelloController.php index 9ec914d3..f9f6ab03 100644 --- a/erp24/commands/HelloController.php +++ b/erp24/commands/HelloController.php @@ -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 index 00000000..310305ce --- /dev/null +++ b/erp24/migrations/m240312_111331_create_table_page_statistics.php @@ -0,0 +1,32 @@ +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); + } +} diff --git a/erp24/web/index.php b/erp24/web/index.php index 6062df6b..8af96dec 100644 --- a/erp24/web/index.php +++ b/erp24/web/index.php @@ -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; -- 2.39.5