xref: /plugin/approve/action/cache.php (revision 1989ee26e4c10d9fe322c2a0aa4ae990f031b47b)
1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6
7class action_plugin_approve_cache extends ActionPlugin
8{
9    /**
10     * @inheritDoc
11     */
12    public function register(EventHandler $controller)
13    {
14        $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_parser_cache_use');
15    }
16    /**
17     * @param Event $event
18     * @param mixed $param
19     */
20    public function handle_parser_cache_use(Event $event, $param)
21    {
22        /** @var cache_renderer $cache */
23        $cache = $event->data;
24
25        if(!$cache->page) return;
26        //purge only xhtml cache
27        if($cache->mode != 'xhtml') return;
28
29        //Check if it is plugins
30        $approve = p_get_metadata($cache->page, 'plugin approve');
31        if(!$approve) return;
32
33        if ($approve['dynamic_approver']) {
34            $cache->_nocache = true;
35        } elseif ($approve['approve_table']) {
36            try {
37                /** @var \helper_plugin_approve_db $db_helper */
38                $db_helper = plugin_load('helper', 'approve_db');
39                $sqlite = $db_helper->getDB();
40                $cache->depends['files'][] = $sqlite->getAdapter()->getDbFile();
41            } catch (Exception $e) {
42                msg($e->getMessage(), -1);
43                return;
44            }
45        }
46    }
47}
48