From e340cef18803622b2d8d4ca75645abed1456f1b7 Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Sat, 13 Apr 2024 10:57:41 +0300 Subject: [PATCH] craft 5: initial release --- CHANGELOG.md | 3 ++ composer.json | 2 +- src/Plugin.php | 2 +- .../VueTablesActivityLogRetriever.php | 29 ++++++++++++++++--- src/templates/index.twig | 10 +++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e7d56..7446b65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Release Notes for Activity Log +## 2.0.0 - 2024-04-13 +- Craft 5: Initial Release + ## 1.7.0 - 2024-01-26 ### Fixed - Install Migration: Use dateTime()->notNull() instead of timestamp() diff --git a/composer.json b/composer.json index d6b9ffe..481c793 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "docs": "https://github.com/matfish2/craft-activity-log/blob/master/README.md" }, "require": { - "craftcms/cms": "^4.0.0", + "craftcms/cms": "^5.0.0", "ext-json": "*", "nesbot/carbon": "^2.58" }, diff --git a/src/Plugin.php b/src/Plugin.php index c74d2a2..48f1340 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -163,7 +163,7 @@ public function getCpNavItem(): ?array $item['subnav'] = [ 'logs' => ['label' => 'Logs', 'url' => 'activity-logs'], 'stats' => ['label' => 'Statistics', 'url' => 'activity-logs/stats'], - 'actions' => ['label' => 'Actions', 'url' => 'activity-logs/actions'] +// 'actions' => ['label' => 'Actions', 'url' => 'activity-logs/actions'] ]; return $item; diff --git a/src/services/VueTablesActivityLogRetriever.php b/src/services/VueTablesActivityLogRetriever.php index ddfb433..dec6d4a 100644 --- a/src/services/VueTablesActivityLogRetriever.php +++ b/src/services/VueTablesActivityLogRetriever.php @@ -8,6 +8,9 @@ class VueTablesActivityLogRetriever { + /** + * @throws \JsonException + */ public function retrieve(): array { $req = \Craft::$app->request; @@ -22,16 +25,34 @@ public function retrieve(): array ]); $filters = $req->getQueryParam('query'); $createdAt = $req->getQueryParam('createdAt'); - $createdAt = $createdAt ? json_decode($createdAt, true, 512, JSON_THROW_ON_ERROR) : null; - $filters = $filters ? json_decode($filters, true) : []; + if ($createdAt) { + if (is_string($createdAt)) { + $createdAt = json_decode($createdAt, true, 512, JSON_THROW_ON_ERROR); + } + } else { + $createdAt = null; + } + + + if ($filters) { + if (is_string($filters)) { + $filters = json_decode($filters, true, 512, JSON_THROW_ON_ERROR); + } + } else { + $filters = []; + } + $createdAtStart = $createdAt ? $createdAt['start'] : Carbon::today()->format('d/m/Y'); $createdAtEnd = $createdAt ? $createdAt['end'] : Carbon::today()->format('d/m/Y'); $start = Carbon::createFromFormat('d/m/Y', $createdAtStart)->startOfDay()->format('Y-m-d H:i:s'); $end = Carbon::createFromFormat('d/m/Y', $createdAtEnd)->endOfDay()->format('Y-m-d H:i:s'); $action = $req->getQueryParam('actionSegments'); - $action = $action ? json_decode($action, true) : null; + + if ($action && is_string($action)) { + $action = json_decode($action, true, 512, JSON_THROW_ON_ERROR); + } $payload = $req->getQueryParam('payload'); @@ -51,7 +72,7 @@ public function retrieve(): array foreach ($filters as $key => $value) { if ($key === 'url') { - $q->andWhere("[[$key]] LIKE '%{$value}%' OR [[query]] LIKE '%{$value}%'"); + $q = $q->andWhere("([[$key]] LIKE '%{$value}%' OR [[query]] LIKE '%{$value}%')"); } elseif ($key === 'responseCode') { $valueEnd = $value + 99; $q->andWhere("[[$key]]>=$value AND [[$key]]<=$valueEnd"); diff --git a/src/templates/index.twig b/src/templates/index.twig index 43ebfc0..da246fb 100644 --- a/src/templates/index.twig +++ b/src/templates/index.twig @@ -124,5 +124,15 @@ + + {% endblock %}