xoops_module_install_adslight()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 82
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 82
rs 8.4586
cc 7
nc 16
nop 1

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\Adslight\{
19
    Common\Configurator,
20
    Utility
21
};
22
23
include \dirname(__DIR__) . '/preloads/autoloader.php';
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_adslight(\XoopsModule $module): bool
32
{
33
    require_once __DIR__ . '/common.php';
34
    $utility = new Utility();
35
    //check for minimum XOOPS version
36
    $xoopsSuccess = $utility::checkVerXoops($module);
37
38
    // check for minimum PHP version
39
    $phpSuccess = $utility::checkVerPhp($module);
40
41
    if ($xoopsSuccess && $phpSuccess) {
42
        $moduleTables = &$module->getInfo('tables');
43
        foreach ($moduleTables as $table) {
44
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
45
        }
46
    }
47
48
    return $xoopsSuccess && $phpSuccess;
49
}
50
51
/**
52
 * Performs tasks required during installation of the module
53
 * @param XoopsModule $module {@link XoopsModule}
54
 *
55
 * @return bool true if installation successful, false if not
56
 */
57
function xoops_module_install_adslight(\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

57
function xoops_module_install_adslight(/** @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...
58
{
59
    require_once \dirname(__DIR__, 3) . '/mainfile.php';
60
61
    global $xoopsDB;
62
    //    $moduleDirName = $module->getVar('dirname');
63
    $moduleDirName = \basename(\dirname(__DIR__));
64
    xoops_loadLanguage('admin', $moduleDirName);
65
    xoops_loadLanguage('modinfo', $moduleDirName);
66
67
    //    $configurator = require_once __DIR__   . '/config.php';
68
    $configurator = new Configurator();
69
    $utility      = new Utility();
70
71
    /*
72
73
    // default Permission Settings ----------------------
74
    $moduleId = $module->getVar('mid');
75
    //    $module_name = $module->getVar('name');
76
    //    $module_dirname = $module->getVar('dirname');
77
    //    $module_version = $module->getVar('version');
78
    $grouppermHandler = xoops_getHandler('groupperm');
79
    // access rights ------------------------------------------
80
    $grouppermHandler->addRight($moduleDirName . '_premium', 1, XOOPS_GROUP_ADMIN, $moduleId);
81
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
82
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
83
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_USERS, $moduleId);
84
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
85
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
86
87
    $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_categories');
88
    $result8 = $xoopsDB->query($sql);
89
    $sql = 'SELECT * FROM ' . $xoopsDB->prefix('adslight_categories') . '';
90
    $rowsCount = $xoopsDB->getRowsNum($xoopsDB->query($sql));
91
92
93
94
    $utility::saveCategoryPermissions($groups, $categoryId, $permName);
95
*/
96
97
    $groups1 = [XOOPS_GROUP_ADMIN];
98
    $groups2 = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS];
99
    $groups3 = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS];
100
101
    $permName1 = $moduleDirName . '_premium';
102
    $permName2 = $moduleDirName . '_submit';
103
    $permName3 = $moduleDirName . '_view';
104
105
    $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('adslight_categories') . ' ';
106
    $rowsCount = $xoopsDB->getRowsNum($xoopsDB->query($sql));
0 ignored issues
show
Unused Code introduced by
The assignment to $rowsCount is dead and can be removed.
Loading history...
107
108
    $sql    = 'SELECT cid FROM ' . $xoopsDB->prefix('adslight_categories');
109
    $result = $xoopsDB->query($sql);
110
    if (!$xoopsDB->isResultSet($result)) {
111
        \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
112
    }
113
114
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
115
        $categoryId = (int)$myrow['cid'];
116
        $utility::saveCategoryPermissions($groups1, $categoryId, $permName1);
117
        $utility::saveCategoryPermissions($groups2, $categoryId, $permName2);
118
        $utility::saveCategoryPermissions($groups3, $categoryId, $permName3);
119
    }
120
121
    //  ---  CREATE FOLDERS ---------------
122
    if (count($configurator->uploadFolders) > 0) {
123
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
124
        foreach (array_keys($configurator->uploadFolders) as $i) {
125
            $utility::createFolder($configurator->uploadFolders[$i]);
126
        }
127
    }
128
129
    //  ---  COPY blank.png FILES ---------------
130
    if (count($configurator->copyBlankFiles) > 0) {
131
        $file = \dirname(__DIR__) . '/assets/images/blank.png';
132
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
133
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
134
            $utility::copyFile($file, $dest);
135
        }
136
    }
137
138
    return true;
139
}
140