diff --git a/Admin/Install/db.json b/Admin/Install/db.json index a369bcc..c8ac210 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -56,5 +56,67 @@ "null": false } } + }, + "monitoring_request": { + "name": "monitoring_request", + "fields": { + "monitoring_request_id": { + "name": "monitoring_request_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "monitoring_request_host": { + "name": "monitoring_request_host", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_language": { + "name": "monitoring_request_language", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + }, + "monitoring_request_country": { + "name": "monitoring_request_country", + "type": "VARCHAR(2)", + "default": null, + "null": true, + "foreignTable": "country", + "foreignKey": "country_code2" + }, + "monitoring_request_browser": { + "name": "monitoring_request_browser", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_path": { + "name": "monitoring_request_path", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_uri": { + "name": "monitoring_request_uri", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_referer": { + "name": "monitoring_request_referer", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_agent": { + "name": "monitoring_request_agent", + "type": "VARCHAR(255)", + "null": false + }, + "monitoring_request_datetime": { + "name": "monitoring_request_datetime", + "type": "INT", + "null": false + } + } } } \ No newline at end of file diff --git a/Controller/Controller.php b/Controller/Controller.php index 96f736c..53a1b37 100755 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Modules\Monitoring\Controller; +use Modules\Monitoring\Models\ImpressionStatMapper; +use phpOMS\Message\Http\HttpRequest; +use phpOMS\Message\Statistic\ImpressionStat; use phpOMS\Module\ModuleAbstract; /** @@ -73,4 +76,16 @@ class Controller extends ModuleAbstract * @since 1.0.0 */ public static array $dependencies = []; + + public function helperLogRequestStat(HttpRequest $request) : void + { + if (!$this->active) { + return; + } + + $stat = new ImpressionStat($request); + + // This is not run through the createModel() function on purpose + ImpressionStatMapper::create()->execute($stat); + } } diff --git a/Models/ImpressionStatMapper.php b/Models/ImpressionStatMapper.php new file mode 100644 index 0000000..1c9c90d --- /dev/null +++ b/Models/ImpressionStatMapper.php @@ -0,0 +1,75 @@ + + */ +final class ImpressionStatMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'monitoring_request_id' => ['name' => 'monitoring_request_id', 'type' => 'int', 'internal' => 'id'], + 'monitoring_request_host' => ['name' => 'monitoring_request_host', 'type' => 'string', 'internal' => 'host',], + 'monitoring_request_language' => ['name' => 'monitoring_request_language', 'type' => 'string', 'internal' => 'language',], + 'monitoring_request_country' => ['name' => 'monitoring_request_country', 'type' => 'string', 'internal' => 'country',], + 'monitoring_request_browser' => ['name' => 'monitoring_request_browser', 'type' => 'string', 'internal' => 'browser',], + 'monitoring_request_path' => ['name' => 'monitoring_request_path', 'type' => 'string', 'internal' => 'path',], + 'monitoring_request_uri' => ['name' => 'monitoring_request_uri', 'type' => 'string', 'internal' => 'uri',], + 'monitoring_request_referer' => ['name' => 'monitoring_request_referer', 'type' => 'string', 'internal' => 'referer',], + 'monitoring_request_agent' => ['name' => 'monitoring_request_agent', 'type' => 'string', 'internal' => 'agent',], + 'monitoring_request_datetime' => ['name' => 'monitoring_request_datetime', 'type' => 'int', 'internal' => 'datetime',], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'monitoring_request'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'monitoring_request_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = ImpressionStat::class; +}