xoops_module_uninstall_xlanguage()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 43
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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

24
function xoops_module_pre_uninstall_xlanguage(/** @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...
25
{
26
    // Do some synchronization
27
    return true;
28
}
29
30
/**
31
 * Performs tasks required during uninstallation of the module
32
 * @param \XoopsModule $module {@link XoopsModule}
33
 *
34
 * @return bool true if uninstallation successful, false if not
35
 */
36
function xoops_module_uninstall_xlanguage(\XoopsModule $module)
37
{
38
    //    return true;
39
40
    $moduleDirName      = \basename(\dirname(__DIR__));
41
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
42
    $helper             = Helper::getInstance();
43
    $utility            = new 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 (!$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_XLANGUAGE_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