microcrud for log_db

This commit is contained in:
Shish 2019-12-07 23:00:52 +00:00
parent 151109ca0e
commit 3e83e66d7c
2 changed files with 67 additions and 75 deletions

74
composer.lock generated
View File

@ -388,12 +388,12 @@
"source": {
"type": "git",
"url": "https://github.com/shish/microcrud.git",
"reference": "3767c1f932474cf225c68c74c245536a1d212f6c"
"reference": "060c30d1a7414cf3242f26aaf689d7c8683fb345"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/microcrud/zipball/3767c1f932474cf225c68c74c245536a1d212f6c",
"reference": "3767c1f932474cf225c68c74c245536a1d212f6c",
"url": "https://api.github.com/repos/shish/microcrud/zipball/060c30d1a7414cf3242f26aaf689d7c8683fb345",
"reference": "060c30d1a7414cf3242f26aaf689d7c8683fb345",
"shasum": ""
},
"require": {
@ -429,7 +429,7 @@
"crud",
"generator"
],
"time": "2019-12-01T19:41:08+00:00"
"time": "2019-12-07T22:47:15+00:00"
},
{
"name": "shish/microhtml",
@ -481,16 +481,16 @@
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.3.x-dev",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "ae466f726242e637cebdd526a7d991b9433bacf1"
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1",
"reference": "ae466f726242e637cebdd526a7d991b9433bacf1",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/eca6c638ef64433b2e36a9221826e75e39c65eb9",
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9",
"shasum": ""
},
"require": {
@ -508,7 +508,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.4.x-dev"
}
},
"autoload": {
@ -533,7 +533,7 @@
"constructor",
"instantiate"
],
"time": "2019-10-21T16:45:58+00:00"
"time": "2019-12-06T20:47:21+00:00"
},
{
"name": "myclabs/deep-copy",
@ -1010,6 +1010,59 @@
],
"time": "2019-10-23T09:07:44+00:00"
},
{
"name": "phpunit/php-invoker",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-invoker.git",
"reference": "4ded0adeba3374d20df3d3ac913bbd694363ecd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/4ded0adeba3374d20df3d3ac913bbd694363ecd3",
"reference": "4ded0adeba3374d20df3d3ac913bbd694363ecd3",
"shasum": ""
},
"require": {
"php": "^7.3"
},
"require-dev": {
"ext-pcntl": "*",
"phpunit/phpunit": "^9.0"
},
"suggest": {
"ext-pcntl": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Invoke callables with a timeout",
"homepage": "https://github.com/sebastianbergmann/php-invoker/",
"keywords": [
"process"
],
"time": "2019-12-07T05:02:56+00:00"
},
{
"name": "phpunit/php-text-template",
"version": "1.2.1",
@ -1178,6 +1231,7 @@
"phpspec/prophecy": "^1.8.1",
"phpunit/php-code-coverage": "^7.0.7",
"phpunit/php-file-iterator": "^2.0.2",
"phpunit/php-invoker": "^3.0",
"phpunit/php-text-template": "^1.2.1",
"phpunit/php-timer": "^2.1.2",
"sebastian/comparator": "^3.0.2",

View File

@ -114,71 +114,9 @@ class LogDatabase extends Extension
global $cache, $database, $user;
if ($event->page_matches("log/view")) {
if ($user->can(Permissions::VIEW_EVENTLOG)) {
$wheres = [];
$args = [];
$page_num = $event->try_page_num(0);
if (!empty($_GET["time-start"])) {
$wheres[] = "date_sent > :time_start";
$args["time_start"] = $_GET["time-start"];
}
if (!empty($_GET["time-end"])) {
$wheres[] = "date_sent < :time_end";
$args["time_end"] = $_GET["time-end"];
}
if (!empty($_GET["module"])) {
$wheres[] = $database->scoreql_to_sql("SCORE_STRNORM(section) = SCORE_STRNORM(:module)");
$args["module"] = $_GET["module"];
}
if (!empty($_GET["user"])) {
if ($database->get_driver_name() == DatabaseDriver::PGSQL) {
if (preg_match("#\d+\.\d+\.\d+\.\d+(/\d+)?#", $_GET["user"])) {
# for some reason postgres won't use an index on lower(text(address)), but will text(address)?
$wheres[] = $database->scoreql_to_sql("(SCORE_STRNORM(username) = SCORE_STRNORM(:user1) OR text(address) = :user2)");
$args["user1"] = $_GET["user"];
$args["user2"] = $_GET["user"] . "/32";
} else {
$wheres[] = $database->scoreql_to_sql("SCORE_STRNORM(username) = SCORE_STRNORM(:user)");
$args["user"] = $_GET["user"];
}
} else {
$wheres[] = $database->scoreql_to_sql("(SCORE_STRNORM(username) = SCORE_STRNORM(:user1) OR SCORE_STRNORM(address) = SCORE_STRNORM(:user2))");
$args["user1"] = $_GET["user"];
$args["user2"] = $_GET["user"];
}
}
if (!empty($_GET["priority"])) {
$wheres[] = "priority >= :priority";
$args["priority"] = int_escape($_GET["priority"]);
} else {
$wheres[] = "priority >= :priority";
$args["priority"] = 20;
}
if (!empty($_GET["message"])) {
$wheres[] = $database->scoreql_to_sql("SCORE_STRNORM(message) LIKE SCORE_STRNORM(:message)");
$args["message"] = "%" . $_GET["message"] . "%";
}
$where = "";
if (count($wheres) > 0) {
$where = "WHERE ";
$where .= join(" AND ", $wheres);
}
$limit = 50;
$offset = ($page_num-1) * $limit;
$page_total = $cache->get("event_log_length");
if (!$page_total) {
$page_total = $database->get_one("SELECT count(*) FROM score_log $where", $args);
// don't cache a length of zero when the extension is first installed
if ($page_total > 10) {
$cache->set("event_log_length", $page_total, 600);
}
}
$args["limit"] = $limit;
$args["offset"] = $offset;
$events = $database->get_all("SELECT * FROM score_log $where ORDER BY id DESC LIMIT :limit OFFSET :offset", $args);
$this->theme->display_events($events, $page_num, 100);
$t = new LogTable($database->raw_db());
$t->inputs = $_GET;
$this->theme->display_events($t->table($t->query()), $t->paginator());
}
}
}