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