11c845774SAndreas Gohr<?php 2*76bbc49cSAnna Dabrowska 31c845774SAndreas Gohrif (!defined('DOKU_INC')) die(); 41c845774SAndreas Gohr 51c845774SAndreas Gohr/** 61c845774SAndreas Gohr * QC Cronjob Action Plugin: Clean up the history once per day 71c845774SAndreas Gohr * 81c845774SAndreas Gohr * @author Dominik Eckelmann <dokuwiki@cosmocode.de> 91c845774SAndreas Gohr */ 10*76bbc49cSAnna Dabrowskaclass action_plugin_qc_cron extends DokuWiki_Action_Plugin 11*76bbc49cSAnna Dabrowska{ 121c845774SAndreas Gohr 131c845774SAndreas Gohr /** 141c845774SAndreas Gohr * if true a cleanup process is already running 151c845774SAndreas Gohr * or done in the last 24h 161c845774SAndreas Gohr */ 171c845774SAndreas Gohr var $run = false; 181c845774SAndreas Gohr 191c845774SAndreas Gohr /** 201c845774SAndreas Gohr * File with the queue informations 211c845774SAndreas Gohr */ 221c845774SAndreas Gohr var $file; 231c845774SAndreas Gohr 241c845774SAndreas Gohr /** 251c845774SAndreas Gohr * Constructor - set up some pathes 261c845774SAndreas Gohr */ 27*76bbc49cSAnna Dabrowska function __construct() 28*76bbc49cSAnna Dabrowska { 291c845774SAndreas Gohr global $conf; 301c845774SAndreas Gohr $this->file = $conf['tmpdir'] . '/qcgather'; 311c845774SAndreas Gohr } 321c845774SAndreas Gohr 331c845774SAndreas Gohr /** 341c845774SAndreas Gohr * Register its handlers with the dokuwiki's event controller 351c845774SAndreas Gohr * 361c845774SAndreas Gohr * we need hook the indexer to trigger the cleanup 371c845774SAndreas Gohr */ 38*76bbc49cSAnna Dabrowska function register(Doku_Event_Handler $controller) 39*76bbc49cSAnna Dabrowska { 401c845774SAndreas Gohr $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'qccron', array()); 411c845774SAndreas Gohr } 421c845774SAndreas Gohr 431c845774SAndreas Gohr /** 441c845774SAndreas Gohr * start the scan 451c845774SAndreas Gohr * 461c845774SAndreas Gohr * Scan for fixmes 471c845774SAndreas Gohr */ 48*76bbc49cSAnna Dabrowska function qccron(Doku_Event $event, $param) 49*76bbc49cSAnna Dabrowska { 501c845774SAndreas Gohr if ($this->run) return; 511c845774SAndreas Gohr 521c845774SAndreas Gohr global $ID; 531c845774SAndreas Gohr if (!$ID) return; 541c845774SAndreas Gohr 551c845774SAndreas Gohr $this->run = true; 561c845774SAndreas Gohr echo 'qc data gatherer: started on ' . $ID . NL; 571c845774SAndreas Gohr /** @var helper_plugin_qc $qc */ 581c845774SAndreas Gohr $qc = $this->loadHelper('qc', true); 591c845774SAndreas Gohr 601c845774SAndreas Gohr $persist = array(); 611c845774SAndreas Gohr if (is_file($this->file)) { 621c845774SAndreas Gohr $persist = file_get_contents($this->file); 631c845774SAndreas Gohr $persist = unserialize($persist); 641c845774SAndreas Gohr } else { 651c845774SAndreas Gohr $persist = array(); 661c845774SAndreas Gohr echo '2'; 671c845774SAndreas Gohr } 681c845774SAndreas Gohr 691c845774SAndreas Gohr $fixme = $qc->getQCData($ID); 701c845774SAndreas Gohr 711c845774SAndreas Gohr // when there are no quality problems we won't need the information 721c845774SAndreas Gohr if ($this->isOk($fixme['err'])) { 731c845774SAndreas Gohr unset($persist[$ID]); 741c845774SAndreas Gohr } else { 751c845774SAndreas Gohr $persist[$ID] = $fixme; 761c845774SAndreas Gohr } 771c845774SAndreas Gohr 781c845774SAndreas Gohr $persist = serialize($persist); 791c845774SAndreas Gohr file_put_contents($this->file, $persist); 801c845774SAndreas Gohr } 811c845774SAndreas Gohr 821c845774SAndreas Gohr /** 831c845774SAndreas Gohr * checks an array to quality 841c845774SAndreas Gohr * 851c845774SAndreas Gohr * @return true when everything is alright 861c845774SAndreas Gohr */ 87*76bbc49cSAnna Dabrowska function isOk($arr) 88*76bbc49cSAnna Dabrowska { 891c845774SAndreas Gohr return count(array_filter((array) $arr)) == 0; 901c845774SAndreas Gohr } 911c845774SAndreas Gohr} 92