Code

< 40 %
40-60 %
> 60 %
1
<?php
2
/**
3
 * DokuWiki Plugin gdpr (CLI Component)
4
 *
5
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6
 * @author  Michael Große <[email protected]>
7
 */
8
9
10
use splitbrain\phpcli\Options;
11
12
class cli_plugin_gdpr extends DokuWiki_CLI_Plugin
13
{
14
15
    /**
16
     * Register options and arguments on the given $options object
17
     *
18
     * @param Options $options
19
     *
20
     * @return void
21
     */
22
    protected function setup(Options $options)
23
    {
24
        $options->setHelp('Clean ips from all changelog entries older than $conf[\'recent_days\']');
25
    }
26
27
    /**
28
     * Your main program
29
     *
30
     * Arguments and options have been parsed when this is run
31
     *
32
     * @param Options $options
33
     *
34
     * @return void
35
     */
36
    protected function main(Options $options)
37
    {
38
        global $conf;
39
        $searchOpts = array('depth' => 0, 'skipacl' => true);
40
41
        $this->log('info', 'Collecting pages...');
42
        /** @var helper_plugin_gdpr_utils $gdprUtils */
43
        $gdprUtils = plugin_load('helper', 'gdpr_utils');
44
        $pageChangelogs = $gdprUtils->collectChangelogs(dir($conf['metadir']));
45
        $this->log('info', count($pageChangelogs) . ' pages found.');
46
        $this->log('info', 'Cleaning page changelogs...');
47
        /** @var action_plugin_gdpr_oldips $action */
48
        $action = plugin_load('action', 'gdpr_oldips');
49
        foreach ($pageChangelogs as $changelogFN) {
50
            $this->log('debug', 'Cleaning changelog ' . $changelogFN);
51
            $action->cleanChangelog($changelogFN);
52
        }
53
        $this->log('success', 'The page changelogs have been cleaned.');
54
55
        $this->log('info', 'Collecting media files...');
56
        $mediaChangelogs = $gdprUtils->collectChangelogs(dir($conf['mediametadir']));
57
        $this->log('info', count($mediaChangelogs) . ' media files found.');
58
        $this->log('info', 'Cleaning media changelogs...');
59
        foreach ($mediaChangelogs as $changelogFN) {
60
            $this->log('debug', 'Cleaning media changelog ' . $changelogFN);
61
            $action->cleanChangelog($changelogFN);
62
        }
63
        $this->log('success', 'The media changelogs have been cleaned.');
64
    }
65
}
66