xoops_module_install_oledrion()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 64
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 64
rs 9.2088
c 0
b 0
f 0
cc 5
nc 4
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
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
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hossein Azizabadi ([email protected])
18
 * @param \XoopsModule $module
19
 * @return bool
20
 */
21
22
use XoopsModules\Oledrion;
23
use XoopsModules\Oledrion\Common;
24
25
/**
26
 * @param \XoopsModule $module
27
 * @return bool
28
 */
29
function xoops_module_pre_install_oledrion(\XoopsModule $module)
30
{
31
    //    require_once dirname(__DIR__) . '/preloads/autoloader.php';
32
    //    include  __DIR__ . '/common.php';
33
    /** @var \XoopsModules\Oledrion\Utility $utility */
34
    $utility = new  \XoopsModules\Oledrion\Utility();
35
36
    //check for minimum XOOPS version
37
    $xoopsSuccess = $utility::checkVerXoops($module);
38
39
    // check for minimum PHP version
40
    $phpSuccess = $utility::checkVerPhp($module);
41
42
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
43
        $moduleTables = &$module->getInfo('tables');
44
        foreach ($moduleTables as $table) {
45
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
46
        }
47
    }
48
49
    return $xoopsSuccess && $phpSuccess;
50
}
51
52
/**
53
 * Performs tasks required during installation of the module
54
 * @param \XoopsModule $module {@link XoopsModule}
55
 *
56
 * @return bool true if installation successful, false if not
57
 */
58
function xoops_module_install_oledrion(\XoopsModule $module)
59
{
60
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
61
62
    $moduleDirName = basename(dirname(__DIR__));
63
64
    /** @var Oledrion\Helper $helper */
65
    /** @var Oledrion\Utility $utility */
66
    /** @var Oledrion\Common\Configurator $configurator */
67
    $helper       = Oledrion\Helper::getInstance();
68
    $utility      = new Oledrion\Utility();
69
    $configurator = new Oledrion\Common\Configurator();
70
71
    // Load language files
72
    $helper->loadLanguage('admin');
73
    $helper->loadLanguage('modinfo');
74
75
    // default Permission Settings ----------------------
76
    $moduleId  = $module->getVar('mid');
77
    // $moduleId2 = $helper->getModule()->mid();
78
    //$moduleName = $module->getVar('name');
79
    /** @var \XoopsGroupPermHandler $grouppermHandler */
80
    $grouppermHandler = xoops_getHandler('groupperm');
81
    // access rights ------------------------------------------
82
    $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

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