xoops_module_uninstall_about()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 44
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 44
rs 9.7666
cc 4
nc 4
nop 1
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\About\{
12
    Helper,
13
    Utility
14
};
15
16
/** @var Helper $helper */
17
/** @var Utility $utility */
18
    
19
/**
20
 * Prepares system prior to attempting to uninstall module
21
 * @param \XoopsModule $module {@link XoopsModule}
22
 *
23
 * @return bool true if ready to uninstall, false if not
24
 */
25
function xoops_module_pre_uninstall_about(\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

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