mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 05:22:59 +00:00
stats/cli: add show subcommand
This commit is contained in:
parent
2324517abc
commit
45ec042dc6
1 changed files with 35 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
register_module([
|
register_module([
|
||||||
"name" => "Statistics",
|
"name" => "Statistics",
|
||||||
"version" => "0.4",
|
"version" => "0.4.1",
|
||||||
"author" => "Starbeamrainbowlabs",
|
"author" => "Starbeamrainbowlabs",
|
||||||
"description" => "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
"description" => "An extensible statistics calculation system. Comes with a range of built-in statistics, but can be extended by other modules too.",
|
||||||
"id" => "feature-stats",
|
"id" => "feature-stats",
|
||||||
|
@ -229,6 +229,14 @@ register_module([
|
||||||
if($env->action !== "stats-update" && !is_cli())
|
if($env->action !== "stats-update" && !is_cli())
|
||||||
update_statistics(false);
|
update_statistics(false);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ██████ ██ ██
|
||||||
|
* ██ ██ ██
|
||||||
|
* ██ ██ ██
|
||||||
|
* ██ ██ ██
|
||||||
|
* ██████ ███████ ██
|
||||||
|
*/
|
||||||
if(module_exists("feature-cli")) {
|
if(module_exists("feature-cli")) {
|
||||||
cli_register("stats", "Interact with and update the wiki statistics", function(array $args) : int {
|
cli_register("stats", "Interact with and update the wiki statistics", function(array $args) : int {
|
||||||
global $settings, $env;
|
global $settings, $env;
|
||||||
|
@ -239,6 +247,7 @@ Usage:
|
||||||
|
|
||||||
Subcommands:
|
Subcommands:
|
||||||
recalculate Recalculates the statistics
|
recalculate Recalculates the statistics
|
||||||
|
show Shows the current statistics
|
||||||
");
|
");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -251,6 +260,31 @@ Subcommands:
|
||||||
echo("done in ".round((microtime(true) - $start_time) * 1000, 2)."ms\n");
|
echo("done in ".round((microtime(true) - $start_time) * 1000, 2)."ms\n");
|
||||||
echo("Recalculated {$env->perfdata->stats_recalcuated} statistics in {$env->perfdata->stats_calctime}ms (not including serialisation / saving to disk)\n");
|
echo("Recalculated {$env->perfdata->stats_recalcuated} statistics in {$env->perfdata->stats_calctime}ms (not including serialisation / saving to disk)\n");
|
||||||
break;
|
break;
|
||||||
|
case "show":
|
||||||
|
$stats = stats_load();
|
||||||
|
foreach($stats as $name => $stat) {
|
||||||
|
$lastupdated = render_timestamp($stat->lastupdated, true, false);
|
||||||
|
if(is_object($stat->value)) {
|
||||||
|
echo("*** $stat->name *** (last updated $lastupdated)\n");
|
||||||
|
$i = 0;
|
||||||
|
foreach($stat->value as $key => $value) {
|
||||||
|
if($i >= 25) break;
|
||||||
|
echo("$key: $value\n");
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(is_array($stat->value)) {
|
||||||
|
// Display array differently, and truncate to 25 entries
|
||||||
|
echo("*** $stat->name *** (last updated $lastupdated)\n");
|
||||||
|
echo(implode("\n", array_slice($stat->value, 0, 25)));
|
||||||
|
echo("\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
echo("$stat->name: ".var_export($stat->value, true)." (last updated $lastupdated)\n");
|
||||||
|
|
||||||
|
echo("\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue