xref: /plugin/publish/action/removeattic.php (revision 4e55e2a150e6f7573f375cf59f24812ce94643ec)
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->getConf('delete attic on first approve')) {
26            return;
27        }
28
29        if ($this->hlp->getPreviousApprovedRevision()) {
30            return; // previous version exist
31        }
32        global $ID;
33        $revisions = getRevisions($ID, 0, 0, 0);
34
35        foreach ($revisions as $revision) {
36            $fn = wikiFN($ID, $revision);
37            if (file_exists($fn)) {
38                @unlink($fn);
39            }
40        }
41    }
42
43}