1<?php
2
3if(!defined('DOKU_INC')) die();
4
5class action_plugin_publish_removeattic extends DokuWiki_Action_Plugin {
6
7    /**
8     * @var helper_plugin_publish
9     */
10    private $hlp;
11
12    function __construct() {
13        $this->hlp = plugin_load('helper','publish');
14    }
15
16    function register(Doku_Event_Handler $controller) {
17        $controller->register_hook('PLUGIN_PUBLISH_APPROVE', 'AFTER', $this, 'remove', array());
18    }
19
20    /**
21     * @param Doku_Event $event
22     * @param array $param
23     */
24    function remove(&$event, $param) {
25        if (!$this->hlp->isActive()) {
26            return;
27        }
28
29        if (!$this->getConf('delete attic on first approve')) {
30            return;
31        }
32
33        if ($this->hlp->getPreviousApprovedRevision()) {
34            return; // previous version exist
35        }
36        global $ID;
37
38        $changelog = new PageChangelog($ID, 0);
39        $revisions = $changelog->getRevisions(0, 0);
40
41        foreach ($revisions as $revision) {
42            $fn = wikiFN($ID, $revision);
43            if (file_exists($fn)) {
44                @unlink($fn);
45            }
46        }
47    }
48
49}
50