xoops_module_uninstall_xoopsfaq()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 42
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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

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