mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 04:23:01 +00:00
feature-stats: add cli command
This commit is contained in:
parent
91bc906bc9
commit
2324517abc
1 changed files with 39 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
register_module([
|
||||
"name" => "Statistics",
|
||||
"version" => "0.3",
|
||||
"version" => "0.4",
|
||||
"author" => "Starbeamrainbowlabs",
|
||||
"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",
|
||||
|
@ -225,9 +225,36 @@ register_module([
|
|||
}
|
||||
]);
|
||||
|
||||
// Perform an automatic recalculation of the statistics if needed
|
||||
if($env->action !== "stats-update")
|
||||
// Perform an automatic recalculation of the statistics if needed, but only if we're not on the CLI
|
||||
if($env->action !== "stats-update" && !is_cli())
|
||||
update_statistics(false);
|
||||
|
||||
if(module_exists("feature-cli")) {
|
||||
cli_register("stats", "Interact with and update the wiki statistics", function(array $args) : int {
|
||||
global $settings, $env;
|
||||
if(count($args) < 1) {
|
||||
echo("stats: interact with an manipulate the wiki statistics
|
||||
Usage:
|
||||
stats {subcommand}
|
||||
|
||||
Subcommands:
|
||||
recalculate Recalculates the statistics
|
||||
");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch($args[0]) {
|
||||
case "recalculate":
|
||||
echo("Updating statistics - ");
|
||||
$start_time = microtime(true);
|
||||
update_statistics(true, true);
|
||||
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");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
|
@ -239,7 +266,7 @@ register_module([
|
|||
*/
|
||||
function update_statistics($update_all = false, $force = false)
|
||||
{
|
||||
global $settings, $paths, $statistic_calculators;
|
||||
global $settings, $env, $paths, $statistic_calculators;
|
||||
|
||||
$stats_mtime = filemtime($paths->statsindex);
|
||||
|
||||
|
@ -289,9 +316,14 @@ function update_statistics($update_all = false, $force = false)
|
|||
}
|
||||
}
|
||||
|
||||
header("x-stats-recalculated: $stats_updated");
|
||||
$env->perfdata->stats_recalcuated = $stats_updated;
|
||||
$env->perfdata->stats_calctime = round((microtime(true) - $start_time)*1000, 3);
|
||||
|
||||
if(!is_cli()) {
|
||||
header("x-stats-recalculated: {$env->perfdata->stats_recalcuated}");
|
||||
//round((microtime(true) - $pageindex_read_start)*1000, 3)
|
||||
header("x-stats-calctime: " . round((microtime(true) - $start_time)*1000, 3) . "ms");
|
||||
header("x-stats-calctime: {$env->perfdata->stats_calctime}ms");
|
||||
}
|
||||
|
||||
stats_save($stats);
|
||||
// If we ran out of time, reset the mtime for performance reasons (see the
|
||||
|
|
Loading…
Reference in a new issue