xoops_module_install_mymenus()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 51
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 28
nc 4
nop 1
dl 0
loc 51
rs 9.1608
c 2
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Mymenus;
21
22
//require __DIR__ . '/setup.php';
23
24
/**
25
 *
26
 * Prepares system prior to attempting to install module
27
 * @param XoopsModule $module {@link XoopsModule}
28
 *
29
 * @return bool true if ready to install, false if not
30
 */
31
function xoops_module_pre_install_mymenus(\XoopsModule $module)
32
{
33
    /** @var Mymenus\Utility $utility */
34
    $utility = new \XoopsModules\Mymenus\Utility();
35
36
    //check for minimum XOOPS version
37
    if (!$utility::checkVerXoops($module)) {
38
        return false;
39
    }
40
41
    // check for minimum PHP version
42
    if (!$utility::checkVerPhp($module)) {
43
        return false;
44
    }
45
46
    $mod_tables =& $module->getInfo('tables');
47
    foreach ($mod_tables as $table) {
48
        $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
49
    }
50
51
    return true;
52
}
53
54
/**
55
 *
56
 * Performs tasks required during installation of the module
57
 * @param XoopsModule $module {@link XoopsModule}
58
 *
59
 * @return bool true if installation successful, false if not
60
 */
61
function xoops_module_install_mymenus(\XoopsModule $module)
62
{
63
    require   dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
64
    require   dirname(__DIR__) . '/include/config.php';
65
66
    $moduleDirName = basename(dirname(__DIR__));
67
    /** @var \XoopsModules\Mymenus\Helper $helper */
68
    $helper = \XoopsModules\Mymenus\Helper::getInstance();
69
70
    // Load language files
71
    $helper->loadLanguage('admin');
72
    $helper->loadLanguage('modinfo');
73
74
    $configurator = new Mymenus\Common\Configurator();
75
    /** @var Mymenus\Utility $utility */
76
    $utility = new \XoopsModules\Mymenus\Utility();
77
78
    // default Permission Settings ----------------------
79
    global $xoopsModule;
80
    $moduleId     = $xoopsModule->getVar('mid');
81
    $moduleId2    = $helper->getModule()->mid();
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleId2 is dead and can be removed.
Loading history...
82
    /** @var \XoopsGroupPermHandler $grouppermHandler */
83
    $grouppermHandler = xoops_getHandler('groupperm');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
    $grouppermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
84
    // access rights ------------------------------------------
85
    $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
86
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
87
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
88
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_USERS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
89
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
0 ignored issues
show
Bug introduced by
The constant XOOPS_GROUP_ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
90
91
    //  ---  CREATE FOLDERS ---------------
92
    if (count($configurator->uploadFolders) > 0) {
93
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
94
        foreach (array_keys($configurator->uploadFolders) as $i) {
95
            $utility::createFolder($configurator->uploadFolders[$i]);
96
        }
97
    }
98
99
    //  ---  COPY blank.png FILES ---------------
100
    if (count($configurator->copyBlankFiles) > 0) {
101
        $file =  dirname(__DIR__) . '/assets/images/blank.png';
102
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
103
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
104
            $utility::copyFile($file, $dest);
105
        }
106
    }
107
    //delete .html entries from the tpl table
108
    $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsDB seems to be never defined.
Loading history...
109
    $xoopsDB->queryF($sql);
110
111
    return true;
112
}
113