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