1<?php
2
3use dokuwiki\plugin\structpublish\meta\Constants;
4
5class action_plugin_structpublish_publish extends DokuWiki_Action_Plugin
6{
7    /** @inheritDoc */
8    public function register(Doku_Event_Handler $controller)
9    {
10        $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'changeStatus');
11    }
12
13    /**
14     * Handle the publish button and version field
15     *
16     * @param Doku_Event $event
17     * @return void
18     * @throws Exception
19     */
20    public function changeStatus(Doku_Event $event)
21    {
22        if ($event->data != 'show') {
23            return;
24        }
25
26        global $INPUT;
27
28        $in = $INPUT->arr('structpublish');
29        $action = key($in);
30        if (!$action || !in_array($action, [Constants::ACTION_PUBLISH, Constants::ACTION_APPROVE])) {
31            return;
32        }
33
34        if (!checkSecurityToken()) return;
35
36        /** @var helper_plugin_structpublish_publish $helper */
37        $helper = plugin_load('helper', 'structpublish_publish');
38        $newRevision = $helper->saveRevision(key($in), $INPUT->str('version'));
39
40        /** @var helper_plugin_structpublish_notify $notifyHelper */
41        $notifyHelper  = plugin_load('helper', 'structpublish_notify');
42        $notifyHelper->sendEmails($action, $newRevision);
43    }
44}
45