xoops_module_install_extcal()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 59
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 26
dl 0
loc 59
rs 9.1928
c 3
b 1
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal\{Helper,
21
    Utility,
22
    Common
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_extcal(\XoopsModule $module)
32
{
33
    include __DIR__ . '/common.php';
34
35
    /** @var Utility $utility */
36
    $utility = new Utility();
37
    //check for minimum XOOPS version
38
    $xoopsSuccess = $utility::checkVerXoops($module);
39
40
    // check for minimum PHP version
41
    $phpSuccess = $utility::checkVerPhp($module);
42
43
    if ($xoopsSuccess && $phpSuccess) {
44
        $moduleTables = &$module->getInfo('tables');
45
        foreach ($moduleTables as $table) {
46
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
47
        }
48
    }
49
50
    return $xoopsSuccess && $phpSuccess;
51
}
52
53
/**
54
 * Performs tasks required during installation of the module
55
 * @param \XoopsModule $xoopsModule
56
 * @return bool true if installation successful, false if not
57
 */
58
function xoops_module_install_extcal(\XoopsModule $xoopsModule)
59
{
60
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
61
62
    $moduleDirName = basename(dirname(__DIR__));
63
64
    /** @var Helper $helper */ /** @var Utility $utility */
65
    /** @var Common\Configurator $configurator */
66
    $helper       = Helper::getInstance();
67
    $utility      = new Utility();
68
    $configurator = new Common\Configurator();
69
    // Load language files
70
    $helper->loadLanguage('admin');
71
    $helper->loadLanguage('modinfo');
72
73
    $moduleId = $xoopsModule->getVar('mid');
74
    /** @var \XoopsGroupPermHandler $grouppermHandler */
75
    $grouppermHandler = xoops_getHandler('groupperm');
76
77
    /*
78
     * Default public category permission mask
79
     */
80
81
    // Access right
82
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 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 . '_perm_mask', 1, /** @scrutinizer ignore-type */ XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
83
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_USERS, $moduleId);
84
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
85
86
    // Can submit
87
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 2, XOOPS_GROUP_ADMIN, $moduleId);
88
89
    // Auto approve
90
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 4, XOOPS_GROUP_ADMIN, $moduleId);
91
92
    // Can Edit
93
    $grouppermHandler->addRight($moduleDirName . '_perm_mask', 8, XOOPS_GROUP_ADMIN, $moduleId);
94
95
    //  ---  CREATE FOLDERS ---------------
96
    if (count($configurator->uploadFolders) > 0) {
97
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
98
        foreach (array_keys($configurator->uploadFolders) as $i) {
99
            $utility::createFolder($configurator->uploadFolders[$i]);
100
        }
101
    }
102
103
    //  ---  COPY blank.png FILES ---------------
104
    if (count($configurator->copyBlankFiles) > 0) {
105
        $file = dirname(__DIR__) . '/assets/images/blank.png';
106
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
107
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
108
            $utility::copyFile($file, $dest);
109
        }
110
    }
111
112
    //delete .html entries from the tpl table
113
    $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
114
    $GLOBALS['xoopsDB']->queryF($sql);
115
116
    return true;
117
}
118