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 * Called on every page write 34 * https://www.dokuwiki.org/devel:event:io_wikipage_write 35 * On update to an existing page this event is called twice, 36 * once for the transfer of the old version to the attic (rev will have a value) 37 * and once to write the new version of the page into the wiki (rev is false) 38 */ 39 $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_update_analytics', array()); 40 41 $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_refresh_analytics', array()); 42 43 } 44 45 public function handle_update_analytics(Doku_Event $event, $param) 46 { 47 48 $rev = $event->data[3]; 49 if ($rev===false){ 50 $id = $event->data[2]; 51 $page = new Page($id); 52 $page->refreshAnalytics(); 53 } 54 55 56 } 57 58 public function handle_refresh_analytics(Doku_Event $event, $param) 59 { 60 61 $sqlite = Sqlite::getSqlite(); 62 $res = $sqlite->query("SELECT ID FROM ANALYTICS_TO_REFRESH"); 63 if (!$res) { 64 LogUtility::msg("There was a problem during the select: {$sqlite->getAdapter()->getDb()->errorInfo()}"); 65 } 66 $rows = $sqlite->res2arr($res,true); 67 $sqlite->res_close($res); 68 foreach($rows as $row){ 69 $page = new Page($row['ID']); 70 $page->refreshAnalytics(); 71 } 72 73 } 74} 75 76 77 78