11c845774SAndreas Gohr<?php 276bbc49cSAnna Dabrowska 31c845774SAndreas Gohr/** 41c845774SAndreas Gohr * QC Cronjob Action Plugin: Clean up the history once per day 51c845774SAndreas Gohr * 61c845774SAndreas Gohr * @author Dominik Eckelmann <dokuwiki@cosmocode.de> 71c845774SAndreas Gohr */ 876bbc49cSAnna Dabrowskaclass action_plugin_qc_cron extends DokuWiki_Action_Plugin 976bbc49cSAnna Dabrowska{ 101c845774SAndreas Gohr 111c845774SAndreas Gohr /** 121c845774SAndreas Gohr * if true a cleanup process is already running 131c845774SAndreas Gohr * or done in the last 24h 141c845774SAndreas Gohr */ 15293182bbSAnna Dabrowska protected $run = false; 161c845774SAndreas Gohr 171c845774SAndreas Gohr /** 181c845774SAndreas Gohr * File with the queue informations 191c845774SAndreas Gohr */ 20293182bbSAnna Dabrowska protected $file; 211c845774SAndreas Gohr 221c845774SAndreas Gohr /** 231c845774SAndreas Gohr * Constructor - set up some pathes 241c845774SAndreas Gohr */ 25293182bbSAnna Dabrowska public function __construct() 2676bbc49cSAnna Dabrowska { 271c845774SAndreas Gohr global $conf; 281c845774SAndreas Gohr $this->file = $conf['tmpdir'] . '/qcgather'; 291c845774SAndreas Gohr } 301c845774SAndreas Gohr 311c845774SAndreas Gohr /** 321c845774SAndreas Gohr * Register its handlers with the dokuwiki's event controller 331c845774SAndreas Gohr * 341c845774SAndreas Gohr * we need hook the indexer to trigger the cleanup 351c845774SAndreas Gohr */ 36293182bbSAnna Dabrowska public function register(Doku_Event_Handler $controller) 3776bbc49cSAnna Dabrowska { 381c845774SAndreas Gohr $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'qccron', array()); 391c845774SAndreas Gohr } 401c845774SAndreas Gohr 411c845774SAndreas Gohr /** 421c845774SAndreas Gohr * start the scan 431c845774SAndreas Gohr * 441c845774SAndreas Gohr * Scan for fixmes 451c845774SAndreas Gohr */ 46*fec39c87SAnna Dabrowska public function qccron(Doku_Event $event, $param) 4776bbc49cSAnna Dabrowska { 481c845774SAndreas Gohr if ($this->run) return; 491c845774SAndreas Gohr 501c845774SAndreas Gohr global $ID; 511c845774SAndreas Gohr if (!$ID) return; 521c845774SAndreas Gohr 531c845774SAndreas Gohr $this->run = true; 541c845774SAndreas Gohr echo 'qc data gatherer: started on ' . $ID . NL; 551c845774SAndreas Gohr /** @var helper_plugin_qc $qc */ 561c845774SAndreas Gohr $qc = $this->loadHelper('qc', true); 571c845774SAndreas Gohr 581c845774SAndreas Gohr $persist = array(); 591c845774SAndreas Gohr if (is_file($this->file)) { 601c845774SAndreas Gohr $persist = file_get_contents($this->file); 611c845774SAndreas Gohr $persist = unserialize($persist); 621c845774SAndreas Gohr } else { 631c845774SAndreas Gohr $persist = array(); 641c845774SAndreas Gohr echo '2'; 651c845774SAndreas Gohr } 661c845774SAndreas Gohr 671c845774SAndreas Gohr $fixme = $qc->getQCData($ID); 681c845774SAndreas Gohr 691c845774SAndreas Gohr // when there are no quality problems we won't need the information 701c845774SAndreas Gohr if ($this->isOk($fixme['err'])) { 711c845774SAndreas Gohr unset($persist[$ID]); 721c845774SAndreas Gohr } else { 731c845774SAndreas Gohr $persist[$ID] = $fixme; 741c845774SAndreas Gohr } 751c845774SAndreas Gohr 761c845774SAndreas Gohr $persist = serialize($persist); 771c845774SAndreas Gohr file_put_contents($this->file, $persist); 781c845774SAndreas Gohr } 791c845774SAndreas Gohr 801c845774SAndreas Gohr /** 811c845774SAndreas Gohr * checks an array to quality 821c845774SAndreas Gohr * 831c845774SAndreas Gohr * @return true when everything is alright 841c845774SAndreas Gohr */ 85293182bbSAnna Dabrowska protected function isOk($arr) 8676bbc49cSAnna Dabrowska { 871c845774SAndreas Gohr return count(array_filter((array) $arr)) == 0; 881c845774SAndreas Gohr } 891c845774SAndreas Gohr} 90