1<?php 2if(!defined('DOKU_INC')) die(); 3 4/** 5 * QC Cronjob Action Plugin: Clean up the history once per day 6 * 7 * @author Dominik Eckelmann <dokuwiki@cosmocode.de> 8 */ 9class action_plugin_qc_cron extends DokuWiki_Action_Plugin { 10 11 /** 12 * if true a cleanup process is already running 13 * or done in the last 24h 14 */ 15 var $run = false; 16 17 /** 18 * File with the queue informations 19 */ 20 var $file; 21 22 /** 23 * Constructor - set up some pathes 24 */ 25 function __construct() { 26 global $conf; 27 $this->file = $conf['tmpdir'] . '/qcgather'; 28 } 29 30 /** 31 * Register its handlers with the dokuwiki's event controller 32 * 33 * we need hook the indexer to trigger the cleanup 34 */ 35 function register(Doku_Event_Handler $controller) { 36 $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'qccron', array()); 37 } 38 39 /** 40 * start the scan 41 * 42 * Scan for fixmes 43 */ 44 function qccron(Doku_Event $event, $param) { 45 if($this->run) return; 46 47 global $ID; 48 if(!$ID) return; 49 50 $this->run = true; 51 echo 'qc data gatherer: started on ' . $ID . NL; 52 /** @var helper_plugin_qc $qc */ 53 $qc = $this->loadHelper('qc', true); 54 55 $persist = array(); 56 if(is_file($this->file)) { 57 $persist = file_get_contents($this->file); 58 $persist = unserialize($persist); 59 } else { 60 $persist = array(); 61 echo '2'; 62 } 63 64 $fixme = $qc->getQCData($ID); 65 66 // when there are no quality problems we won't need the information 67 if($this->isOk($fixme['err'])) { 68 unset($persist[$ID]); 69 } else { 70 $persist[$ID] = $fixme; 71 } 72 73 $persist = serialize($persist); 74 file_put_contents($this->file, $persist); 75 } 76 77 /** 78 * checks an array to quality 79 * 80 * @return true when everything is alright 81 */ 82 function isOk($arr) { 83 return count(array_filter((array) $arr)) == 0; 84 } 85} 86