Passed
Push — master ( 630eee...e4be3b )
by Mark
05:32 queued 10s
created

admin_plugin_openlayersmap_purge   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
eloc 51
c 1
b 0
f 0
dl 0
loc 97
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMenuSort() 0 2 1
A getMenuIcon() 0 3 1
B handle() 0 15 7
A html() 0 33 1
B rrmdir() 0 16 7
1
<?php
2
/*
3
 * Copyright (c) 2008-2015 Mark C. Prins <[email protected]>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 *
17
 * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
18
 */
19
20
/**
21
 * DokuWiki Plugin openlayersmap (Admin Component).
22
 * This component purges the cached tiles and maps.
23
 *
24
 * @author Mark Prins
25
 */
26
class admin_plugin_openlayersmap_purge extends DokuWiki_Admin_Plugin {
0 ignored issues
show
Bug introduced by
The type DokuWiki_Admin_Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
    /**
28
     * (non-PHPdoc)
29
     * @see DokuWiki_Admin_Plugin::getMenuSort()
30
     */
31
    public function getMenuSort(): int {
32
        return 800;
33
    }
34
35
    public function getMenuIcon(): string {
36
        $plugin = $this->getPluginName();
37
        return DOKU_PLUGIN . $plugin . '/admin/purge.svg';
0 ignored issues
show
Bug introduced by
The constant DOKU_PLUGIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
    }
39
40
    /**
41
     * (non-PHPdoc)
42
     * @see DokuWiki_Admin_Plugin::handle()
43
     */
44
    public function handle(): void {
45
        global $conf;
46
        if(!isset($_REQUEST['continue']) || !checkSecurityToken()) {
0 ignored issues
show
Bug introduced by
The function checkSecurityToken was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        if(!isset($_REQUEST['continue']) || !/** @scrutinizer ignore-call */ checkSecurityToken()) {
Loading history...
47
            return;
48
        }
49
        if(isset($_REQUEST['purgetiles'])) {
50
            $path = $conf['cachedir'] . '/olmaptiles';
51
            if($this->rrmdir($path)) {
52
                msg($this->getLang('admin_purged_tiles'), 0);
0 ignored issues
show
Bug introduced by
The function msg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
                /** @scrutinizer ignore-call */ 
53
                msg($this->getLang('admin_purged_tiles'), 0);
Loading history...
53
            }
54
        }
55
        if(isset($_REQUEST['purgemaps'])) {
56
            $path = $conf['mediadir'] . '/olmapmaps';
57
            if($this->rrmdir($path)) {
58
                msg($this->getLang('admin_purged_maps'), 0);
59
            }
60
        }
61
    }
62
63
    /**
64
     * Recursively delete the directory.
65
     * @param string $sDir directory path
66
     * @return boolean true when succesful
67
     */
68
    private function rrmdir(string $sDir): bool {
69
        if(is_dir($sDir)) {
70
            dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: ');
0 ignored issues
show
Bug introduced by
The function dbglog was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
            /** @scrutinizer ignore-call */ 
71
            dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: ');
Loading history...
71
            $sDir = rtrim($sDir, '/');
72
            $oDir = dir($sDir);
73
            while(($sFile = $oDir->read()) !== false) {
74
                if($sFile !== '.' && $sFile !== '..') {
75
                    (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ?
76
                        $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile");
77
                }
78
            }
79
            $oDir->close();
80
            rmdir($sDir);
81
            return true;
82
        }
83
        return false;
84
    }
85
86
    /**
87
     * (non-PHPdoc)
88
     * @see DokuWiki_Admin_Plugin::html()
89
     */
90
    public function html(): void {
91
        echo $this->locale_xhtml('admin_intro');
92
        $form = new Doku_Form(array('id' => 'olmap_purgeform', 'method' => 'post'));
0 ignored issues
show
Bug introduced by
The type Doku_Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
        $form->addHidden('continue', 'go');
94
95
        $form->startFieldset($this->getLang('admin_tiles'));
96
        $form->addElement('<p>');
97
        $form->addElement(
98
            '<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />'
99
        );
100
        $form->addElement(
101
            '<label for="purgetiles" class="label">' . $this->getLang('admin_purge_tiles')
102
            . '</label>'
103
        );
104
        $form->addElement('</p>');
105
        $form->endFieldset();
106
107
        $form->startFieldset($this->getLang('admin_maps'));
108
        $form->addElement('<p>');
109
        $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />');
110
        $form->addElement(
111
            '<label for="purgemaps" class="label">' . $this->getLang('admin_purge_maps') . '</label>'
112
        );
113
        $form->addElement('</p>');
114
        $form->endFieldset();
115
116
        $form->addElement(
117
            form_makeButton(
0 ignored issues
show
Bug introduced by
The function form_makeButton was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

117
            /** @scrutinizer ignore-call */ 
118
            form_makeButton(
Loading history...
118
                'submit', 'admin', $this->getLang('admin_submit'),
119
                array('accesskey' => 'p', 'title' => $this->getLang('admin_submit'))
120
            )
121
        );
122
        $form->printForm();
123
    }
124
}
125