Completed
Push — master ( 141e43...3982f3 )
by Michael
10s
created

onuninstall.php ➔ rmdirr()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 5
nop 1
dl 0
loc 28
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * uninstall.php - cleanup on module uninstall
4
 *
5
 * @author          XOOPS Module Development Team
6
 * @copyright       {@link http://xoops.org 2001-2016 XOOPS Project}
7
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
8
 * @link            http://xoops.org XOOPS
9
 */
10
11
12
/**
13
 * Prepares system prior to attempting to uninstall module
14
 * @param XoopsModule $module {@link XoopsModule}
15
 *
16
 * @return bool true if ready to uninstall, false if not
17
 */
18
19
function xoops_module_pre_uninstall_xfguestbook(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
{
21
    // Do some synchronization
22
    return true;
23
}
24
25
/**
26
 *
27
 * Performs tasks required during uninstallation of the module
28
 * @param XoopsModule $module {@link XoopsModule}
29
 *
30
 * @return bool true if uninstallation successful, false if not
31
 */
32
function xoops_module_uninstall_xfguestbook(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
{
34
    return true;
35
}
36
37
38
39
//=======================================================
40
41
42
43
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
45
/**
46
 * @param XoopsModule $module
47
 *
48
 * @return bool
49
 */
50
function xoops_module_uninstall_XXXX(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
{
52
    // global $xoopsDB,$xoopsConfig;
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
    //
54
    // nothing to do yet
55
    return true;
56
57
    //routine to delete a cache directory
58
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
     $cacheDir = XOOPS_ROOT_PATH . '/uploads/shoutbox';
60
    //Always check if a directory exists prior to creation
61
    if (!is_dir($cacheDir)) {
62
        return true;
63
    } else {
64
        return rmdirr($cacheDir); // see the function below
65
    }
66
     */
67
68
    //------------- example from user log --------------
69
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
     $logsetObj = UserlogSetting::getInstance();
71
72
    return $logsetObj->cleanCache(); // delete all settings caches
73
74
     */
75
}
76
77
/**
78
 * Delete a file, or a folder and its contents
79
 *
80
 * @author      Aidan Lister <[email protected]>
81
 * @param  string $dirname The directory to delete
82
 * @return bool   Returns true on success, false on failure
83
 */
84
85
function rmdirr($dirname)
86
{
87
    // Simple delete for a file
88
    if (is_file($dirname)) {
89
        return unlink($dirname);
90
    }
91
92
    // Loop through the folder
93
    $dir = dir($dirname);
94
    while (false !== $entry = $dir->read()) {
95
        // Skip pointers
96
        if ($entry == '.' || $entry == '..') {
97
            continue;
98
        }
99
100
        // Deep delete directories
101
        if (is_dir("$dirname/$entry")) {
102
            rmdirr("$dirname/$entry");
103
        } else {
104
            unlink("$dirname/$entry");
105
        }
106
    }
107
108
    // Clean up
109
    $dir->close();
110
111
    return rmdir($dirname);
112
}
113