1e99041d4SAndreas Gohr<?php 2e99041d4SAndreas Gohr 3e99041d4SAndreas Gohruse dokuwiki\Extension\CLIPlugin; 4e99041d4SAndreas Gohruse splitbrain\phpcli\Options; 5e99041d4SAndreas Gohr 6bf1a58f3SAndreas Gohr/** 7bf1a58f3SAndreas Gohr * statdisplay plugin cli component 8bf1a58f3SAndreas Gohr * 9bf1a58f3SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 10bf1a58f3SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 11bf1a58f3SAndreas Gohr */ 12e99041d4SAndreas Gohrclass cli_plugin_statdisplay extends CLIPlugin 13e99041d4SAndreas Gohr{ 14e99041d4SAndreas Gohr /** 15e99041d4SAndreas Gohr * @inheritDoc 16e99041d4SAndreas Gohr */ 17e99041d4SAndreas Gohr protected function setup(Options $options) 18e99041d4SAndreas Gohr { 19e99041d4SAndreas Gohr $options->setHelp('Control the statdisplay plugin'); 20e99041d4SAndreas Gohr $options->registerCommand('parse', 'Parse and analyse the log file'); 21*1a328e16SAndreas Gohr $options->registerOption( 22*1a328e16SAndreas Gohr 'clear', 23*1a328e16SAndreas Gohr 'Drop all previously parsed log data and reparse the whole log file', 24*1a328e16SAndreas Gohr 'c', 25*1a328e16SAndreas Gohr false, 26*1a328e16SAndreas Gohr 'parse' 27*1a328e16SAndreas Gohr ); 28e99041d4SAndreas Gohr $options->registerOption('lines', 'Number of lines to read per iteration', 'l', 'lines', 'parse'); 29e99041d4SAndreas Gohr } 30e99041d4SAndreas Gohr 31e99041d4SAndreas Gohr /** 32e99041d4SAndreas Gohr * @inheritDoc 33e99041d4SAndreas Gohr */ 34e99041d4SAndreas Gohr protected function main(Options $options) 35e99041d4SAndreas Gohr { 36e99041d4SAndreas Gohr switch ($options->getCmd()) { 37e99041d4SAndreas Gohr case 'parse': 38e99041d4SAndreas Gohr $this->parseData( 39e99041d4SAndreas Gohr $this->options->getOpt('clear'), 40e99041d4SAndreas Gohr (int)$this->options->getOpt('lines', $this->getConf('lines')) 41e99041d4SAndreas Gohr ); 42e99041d4SAndreas Gohr break; 43e99041d4SAndreas Gohr default: 44e99041d4SAndreas Gohr echo $this->options->help(); 45e99041d4SAndreas Gohr } 46e99041d4SAndreas Gohr } 47e99041d4SAndreas Gohr 48e99041d4SAndreas Gohr /** 49e99041d4SAndreas Gohr * Parse the log data 50e99041d4SAndreas Gohr * 51e99041d4SAndreas Gohr * @param bool $clear 52e99041d4SAndreas Gohr */ 53e99041d4SAndreas Gohr protected function parseData($clear, $maxlines) 54e99041d4SAndreas Gohr { 55e99041d4SAndreas Gohr /** @var helper_plugin_statdisplay_log $helper */ 56e99041d4SAndreas Gohr $helper = plugin_load('helper', 'statdisplay_log'); 57e99041d4SAndreas Gohr 58e99041d4SAndreas Gohr if ($clear) { 59e99041d4SAndreas Gohr $helper->resetLogCache(); 60e99041d4SAndreas Gohr } 61e99041d4SAndreas Gohr 62e99041d4SAndreas Gohr do { 63e99041d4SAndreas Gohr $this->info(sprintf('%.2f%%', $helper->progress())); 64e99041d4SAndreas Gohr } while ($helper->parseLogData($maxlines)); 65e99041d4SAndreas Gohr } 66e99041d4SAndreas Gohr} 67