xoops_module_install_xhelp()   B
last analyzed

Complexity

Conditions 7
Paths 8

Size

Total Lines 58
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 30
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 58
rs 8.5066

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 declare(strict_types=1);
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.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team
16
 */
17
18
use XoopsModules\Xhelp;
19
use XoopsModules\Xhelp\Common;
20
use XoopsModules\Xhelp\Utility;
21
22
/**
23
 * Prepares system prior to attempting to install module
24
 * @param \XoopsModule $module {@link XoopsModule}
25
 *
26
 * @return bool true if ready to install, false if not
27
 */
28
function xoops_module_pre_install_xhelp(\XoopsModule $module): bool
29
{
30
    require_once \dirname(__DIR__) . '/preloads/autoloader.php';
31
    $utility      = new Utility();
32
    $xoopsSuccess = $utility::checkVerXoops($module);
33
    $phpSuccess   = $utility::checkVerPhp($module);
34
35
    if ($xoopsSuccess && $phpSuccess) {
36
        $moduleTables = &$module->getInfo('tables');
37
        foreach ($moduleTables as $table) {
38
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
39
        }
40
    }
41
42
    return $xoopsSuccess && $phpSuccess;
43
}
44
45
/**
46
 * Performs tasks required during installation of the module
47
 * @param \XoopsModule $module {@link XoopsModule}
48
 *
49
 * @return bool true if installation successful, false if not
50
 */
51
function xoops_module_install_xhelp(\XoopsModule $module): bool
52
{
53
    require_once \dirname(__DIR__) . '/preloads/autoloader.php';
54
55
    $moduleDirName = \basename(\dirname(__DIR__));
56
57
    $helper       = Xhelp\Helper::getInstance();
58
    $utility      = new Xhelp\Utility();
59
    $configurator = new Xhelp\Common\Configurator();
60
61
    // Load language files
62
    $helper->loadLanguage('admin');
63
    $helper->loadLanguage('modinfo');
64
65
    // default Permission Settings ----------------------
66
    $moduleId = $module->getVar('mid');
67
68
    //$moduleName = $module->getVar('name');
69
    /** @var \XoopsGroupPermHandler $grouppermHandler */
70
    $grouppermHandler = xoops_getHandler('groupperm');
71
    // access rights ------------------------------------------
72
    $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
XOOPS_GROUP_ADMIN of type string is incompatible with the type integer expected by parameter $gperm_groupid of XoopsGroupPermHandler::addRight(). ( Ignorable by Annotation )

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

72
    $grouppermHandler->addRight($moduleDirName . '_approve', 1, /** @scrutinizer ignore-type */ XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
73
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
74
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
75
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
76
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
77
78
    //  ---  CREATE FOLDERS ---------------
79
    if (count($configurator->uploadFolders) > 0) {
80
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
81
        foreach (array_keys($configurator->uploadFolders) as $i) {
82
            $utility::createFolder($configurator->uploadFolders[$i]);
83
        }
84
    }
85
    //  ---  COPY blank.png FILES ---------------
86
    if (count($configurator->copyBlankFiles) > 0) {
87
        $file = \dirname(__DIR__) . '/assets/images/blank.png';
88
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
89
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
90
            $utility::copyFile($file, $dest);
91
        }
92
    }
93
94
    //  ---  COPY test folder files ---------------
95
    if (count($configurator->copyTestFolders) > 0) {
96
        //        $file =  \dirname(__DIR__) . '/testdata/images/';
97
        foreach (array_keys($configurator->copyTestFolders) as $i) {
98
            $src  = $configurator->copyTestFolders[$i][0];
99
            $dest = $configurator->copyTestFolders[$i][1];
100
            $utility::rcopy($src, $dest);
101
        }
102
    }
103
104
    //delete .html entries from the tpl table
105
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
106
    $GLOBALS['xoopsDB']->queryF($sql);
107
108
    return true;
109
}
110