xref: /plugin/combo/action/analytics.php (revision 2c0674072a09934e669b230efb4e5389949fae42)
1<?php
2
3use ComboStrap\Analytics;
4use ComboStrap\Page;
5
6/**
7 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved.
8 *
9 * This source code is licensed under the GPL license found in the
10 * COPYING  file in the root directory of this source tree.
11 *
12 * @license  GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
13 * @author   ComboStrap <support@combostrap.com>
14 *
15 */
16
17require_once(__DIR__ . '/../class/'.'Analytics.php');
18
19/**
20 * Class action_plugin_combo_analytics
21 * Update the analytics data
22 */
23class action_plugin_combo_analytics extends DokuWiki_Action_Plugin
24{
25
26
27    public function register(Doku_Event_Handler $controller)
28    {
29
30        /**
31         * Called on every page write
32         * https://www.dokuwiki.org/devel:event:io_wikipage_write
33         * On update to an existing page this event is called twice,
34         * once for the transfer of the old version to the attic (rev will have a value)
35         * and once to write the new version of the page into the wiki (rev is false)
36         */
37        $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_update_analytics', array());
38
39    }
40
41    public function handle_update_analytics(Doku_Event $event, $param)
42    {
43
44        $rev = $event->data[3];
45        if ($rev===false){
46            $id = $event->data[2];
47            Analytics::process($id);
48        }
49
50
51    }
52}
53
54
55
56