1<?php 2 3use ComboStrap\Analytics; 4use ComboStrap\LogUtility; 5use ComboStrap\Page; 6use ComboStrap\Sqlite; 7 8/** 9 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved. 10 * 11 * This source code is licensed under the GPL license found in the 12 * COPYING file in the root directory of this source tree. 13 * 14 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 15 * @author ComboStrap <support@combostrap.com> 16 * 17 */ 18 19require_once(__DIR__ . '/../class/'.'Analytics.php'); 20 21/** 22 * Class action_plugin_combo_analytics 23 * Update the analytics data 24 */ 25class action_plugin_combo_analytics extends DokuWiki_Action_Plugin 26{ 27 28 29 public function register(Doku_Event_Handler $controller) 30 { 31 32 /** 33 * Analytics to refresh because they have lost or gain a backlinks 34 * are done via Sqlite table (The INDEXER_TASKS_RUN gives a way to 35 * manipulate this queue) 36 * 37 * There is no need to do it at page write 38 * https://www.dokuwiki.org/devel:event:io_wikipage_write 39 * because after the page is written, the page is shown and trigger the index tasks run 40 */ 41 $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_refresh_analytics', array()); 42 43 } 44 45 public function handle_refresh_analytics(Doku_Event $event, $param) 46 { 47 48 /** 49 * Check that the actual page has analytics data 50 * (if there is a cache, it's pretty quick) 51 */ 52 global $ID; 53 Analytics::process($ID,true); 54 55 /** 56 * Check the analytics to refresh 57 */ 58 $sqlite = Sqlite::getSqlite(); 59 $res = $sqlite->query("SELECT ID FROM ANALYTICS_TO_REFRESH"); 60 if (!$res) { 61 LogUtility::msg("There was a problem during the select: {$sqlite->getAdapter()->getDb()->errorInfo()}"); 62 } 63 $rows = $sqlite->res2arr($res,true); 64 $sqlite->res_close($res); 65 foreach($rows as $row){ 66 $page = new Page($row['ID']); 67 $page->refreshAnalytics(); 68 } 69 70 } 71} 72 73 74 75