* */ require_once(__DIR__ . '/../class/'.'Analytics.php'); /** * Class action_plugin_combo_analytics * Update the analytics data */ class action_plugin_combo_analytics extends DokuWiki_Action_Plugin { public function register(Doku_Event_Handler $controller) { /** * Called on every page write * https://www.dokuwiki.org/devel:event:io_wikipage_write * On update to an existing page this event is called twice, * once for the transfer of the old version to the attic (rev will have a value) * and once to write the new version of the page into the wiki (rev is false) */ //$controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_update_analytics', array()); /** * Analytics to refresh because they have lost or gain a backlinks * are done via Sqlite table (The INDEXER_TASKS_RUN gives a way to * manipulate this queue) */ $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_refresh_analytics', array()); } public function handle_update_analytics(Doku_Event $event, $param) { $rev = $event->data[3]; if ($rev===false){ $id = $event->data[2]; $page = new Page($id); $page->refreshAnalytics(); } } public function handle_refresh_analytics(Doku_Event $event, $param) { /** * Check that the actual page has analytics data * (if there is a cache, it's pretty quick) */ global $ID; Analytics::process($ID,true); /** * Check the analytics to refresh */ $sqlite = Sqlite::getSqlite(); $res = $sqlite->query("SELECT ID FROM ANALYTICS_TO_REFRESH"); if (!$res) { LogUtility::msg("There was a problem during the select: {$sqlite->getAdapter()->getDb()->errorInfo()}"); } $rows = $sqlite->res2arr($res,true); $sqlite->res_close($res); foreach($rows as $row){ $page = new Page($row['ID']); $page->refreshAnalytics(); } } }