xoops_module_uninstall_xdonations()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 46
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 46
rs 9.7666
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 https://xoops.org 2001-2016 XOOPS Project}
7
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
8
 * @link            https://xoops.org XOOPS
9
 */
10
11
use XoopsModules\Xdonations;
12
13
/**
14
 * Prepares system prior to attempting to uninstall module
15
 * @param XoopsModule $module {@link XoopsModule}
16
 *
17
 * @return bool true if ready to uninstall, false if not
18
 */
19
20
function xoops_module_pre_uninstall_xdonations(\XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

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

20
function xoops_module_pre_uninstall_xdonations(/** @scrutinizer ignore-unused */ \XoopsModule $module)

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

Loading history...
21
{
22
    // Do some synchronization
23
    return true;
24
}
25
26
/**
27
 *
28
 * Performs tasks required during uninstallation of the module
29
 * @param XoopsModule $module {@link XoopsModule}
30
 *
31
 * @return bool true if uninstallation successful, false if not
32
 */
33
function xoops_module_uninstall_xdonations(\XoopsModule $module)
34
{
35
    //    return true;
36
37
    $moduleDirName      = basename(dirname(__DIR__));
38
    $moduleDirNameUpper = strtoupper($moduleDirName);
39
    /** @var Xdonations\Helper $helper */
40
    $helper = Xdonations\Helper::getInstance();
41
42
    /** @var Xdonations\Utility $utility */
43
    $utility = new Xdonations\Utility();
44
45
    $success = true;
46
    $helper->loadLanguage('admin');
47
48
    //------------------------------------------------------------------
49
    // Remove uploads folder (and all subfolders) if they exist
50
    //------------------------------------------------------------------
51
52
    $old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")];
53
    foreach ($old_directories as $old_dir) {
54
        $dirInfo = new \SplFileInfo($old_dir);
55
        if ($dirInfo->isDir()) {
56
            // The directory exists so delete it
57
            if (false === $utility::rrmdir($old_dir)) {
58
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH'), $old_dir));
59
                $success = false;
60
            }
61
        }
62
        unset($dirInfo);
63
    }
64
    /*
65
    //------------ START ----------------
66
    //------------------------------------------------------------------
67
    // Remove xsitemap.xml from XOOPS root folder if it exists
68
    //------------------------------------------------------------------
69
    $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml');
70
    if (is_file($xmlfile)) {
71
        if (false === ($delOk = unlink($xmlfile))) {
72
            $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_REMOVE, $xmlfile));
73
        }
74
    }
75
//    return $success && $delOk; // use this if you're using this routine
76
*/
77
78
    return $success;
79
    //------------ END  ----------------
80
}
81