xoops_module_uninstall_newbb()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 39
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 15
nc 3
nop 1
dl 0
loc 39
rs 9.7666
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * uninstall.php - cleanup on module uninstall
5
 *
6
 * @author          XOOPS Module Development Team
7
 * @copyright       {@link https://xoops.org 2001-2016 XOOPS Project}
8
 * @license         {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
9
 * @link            https://xoops.org XOOPS
10
 */
11
12
use XoopsModules\Newbb\{
13
    Helper,
14
    Utility
15
};
16
17
/** @var Helper $helper */
18
/** @var Utility $utility */
19
20
/**
21
 *  Prepares system prior to attempting to uninstall module
22
 *
23
 * @param \XoopsModule $module {@link XoopsModule}
24
 *
25
 * @return true true if ready to uninstall, false if not
26
 */
27
function xoops_module_pre_uninstall_newbb(\XoopsModule $module): bool
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

27
function xoops_module_pre_uninstall_newbb(/** @scrutinizer ignore-unused */ \XoopsModule $module): bool

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...
28
{
29
    // Do some synchronization
30
    return true;
31
}
32
33
/**
34
 * Performs tasks required during uninstallation of the module
35
 * @param \XoopsModule $module {@link XoopsModule}
36
 *
37
 * @return bool true if uninstallation successful, false if not
38
 */
39
function xoops_module_uninstall_newbb(\XoopsModule $module): bool
40
{
41
    //    return true;
42
43
    $moduleDirName      = \basename(\dirname(__DIR__));
44
    $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
45
    $helper             = Helper::getInstance();
46
    $utility            = new Utility();
0 ignored issues
show
Unused Code introduced by
The assignment to $utility is dead and can be removed.
Loading history...
47
48
    $success = true;
49
    $helper->loadLanguage('admin');
50
51
    // Rename uploads folder to BAK and add date to name
52
    $uploadDirectory = $GLOBALS['xoops']->path("uploads/$moduleDirName");
53
    $dirInfo = new \SplFileInfo($uploadDirectory);
54
    if ($dirInfo->isDir()) {
55
        // The directory exists so rename it
56
        $date = date('Y-m-d');
57
        if (!rename($uploadDirectory, $uploadDirectory . "_bak_$date")) {
58
            $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_BAD_DEL_PATH'), $uploadDirectory));
59
            $success = false;
60
        }
61
    }
62
    unset($dirInfo);
63
    /*
64
    //------------ START ----------------
65
    //------------------------------------------------------------------
66
    // Remove xsitemap.xml from XOOPS root folder if it exists
67
    //------------------------------------------------------------------
68
    $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml');
69
    if (is_file($xmlfile)) {
70
        if (false === ($delOk = unlink($xmlfile))) {
71
            $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_REMOVE, $xmlfile));
72
        }
73
    }
74
//    return $success && $delOk; // use this if you're using this routine
75
*/
76
77
    return $success;
78
    //------------ END  ----------------
79
}
80