xref: /plugin/acknowledge/action/pagesave.php (revision c38b6ca85313c7f98e013ff1ce06b406d156a85b)
1<?php
2
3/**
4 * DokuWiki Plugin acknowledge (Action Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author  Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de>
8 */
9
10use dokuwiki\Extension\ActionPlugin;
11use dokuwiki\Extension\EventHandler;
12use dokuwiki\Extension\Event;
13
14class action_plugin_acknowledge_pagesave extends ActionPlugin
15{
16    /** @inheritDoc */
17    public function register(EventHandler $controller)
18    {
19        $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'AFTER', $this, 'handlePageSave');
20    }
21
22    /**
23     * Manage page meta data
24     *
25     * Store page last modified date
26     * Handle page deletions
27     * Handle page creations
28     *
29     * @param Event $event
30     * @param $param
31     */
32    public function handlePageSave(Event $event, $param)
33    {
34        /** @var helper_plugin_acknowledge $helper */
35        $helper = plugin_load('helper', 'acknowledge');
36
37        if ($event->data['changeType'] === DOKU_CHANGE_TYPE_DELETE) {
38            $helper->removePage($event->data['id']); // this cascades to assignments
39        } elseif ($event->data['changeType'] !== DOKU_CHANGE_TYPE_MINOR_EDIT) {
40            $helper->storePageDate($event->data['id'], $event->data['newRevision'], $event->data['newContent']);
41        }
42
43        // Remove page assignees here because the syntax might have been removed
44        // they are readded on metadata rendering if still there
45        $helper->clearPageAssignments($event->data['id']);
46
47        if ($event->data['changeType'] === DOKU_CHANGE_TYPE_CREATE) {
48            // new pages need to have their auto assignments updated based on the existing patterns
49            $helper->setAutoAssignees($event->data['id']);
50        }
51    }
52}
53