xoops_module_uninstall_xoopsheadline()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 44
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 44
rs 9.7666
c 3
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.fsf.org/copyleft/gpl.html GNU public license}
9
 * @link            https://xoops.org XOOPS
10
 */
11
12
use XoopsModules\Xoopsheadline\Helper;
13
use XoopsModules\Xoopsheadline\Utility;
14
15
/**
16
 * Prepares system prior to attempting to uninstall module
17
 * @param \XoopsModule $module {@link XoopsModule}
18
 *
19
 * @return bool true if ready to uninstall, false if not
20
 */
21
function xoops_module_pre_uninstall_xoopsheadline(\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

21
function xoops_module_pre_uninstall_xoopsheadline(/** @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...
22
{
23
    // Do some synchronization
24
    return true;
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_xoopsheadline(\XoopsModule $module): bool
34
{
35
    //    return true;
36
37
    $moduleDirName      = \basename(\dirname(__DIR__));
38
    $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
39
    $helper             = Helper::getInstance();
40
41
    $utility = new Utility();
42
43
    $success = true;
44
    $helper->loadLanguage('admin');
45
46
    //------------------------------------------------------------------
47
    // Remove uploads folder (and all subfolders) if they exist
48
    //------------------------------------------------------------------
49
50
    $oldDirectories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")];
51
    foreach ($oldDirectories as $oldDir) {
52
        $dirInfo = new \SplFileInfo($oldDir);
53
        if ($dirInfo->isDir()) {
54
            // The directory exists so delete it
55
            if (!$utility::rrmdir($oldDir)) {
56
                $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_DEL_PATH'), $oldDir));
57
                $success = false;
58
            }
59
        }
60
        unset($dirInfo);
61
    }
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_XOOPSHEADLINE_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