xoops_module_pre_install_marquee()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 14
rs 9.6111
1
<?php declare(strict_types=1);
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
use XoopsModules\Marquee\{
14
    Common\Configurator,
15
    Helper,
16
    Utility
17
};
18
19
/**
20
 * @copyright    XOOPS Project (https://xoops.org)
21
 * @license      GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
22
 * @author       XOOPS Development Team
23
 */
24
/**
25
 * Prepares system prior to attempting to install module
26
 * @param \XoopsModule $module {@link XoopsModule}
27
 *
28
 * @return bool true if ready to install, false if not
29
 */
30
function xoops_module_pre_install_marquee(\XoopsModule $module)
31
{
32
    require_once \dirname(__DIR__) . '/preloads/autoloader.php';
33
    $utility      = new Utility();
34
    $xoopsSuccess = $utility::checkVerXoops($module);
35
    $phpSuccess   = $utility::checkVerPhp($module);
36
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
37
        $moduleTables = &$module->getInfo('tables');
38
        foreach ($moduleTables as $table) {
39
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
40
        }
41
    }
42
43
    return $xoopsSuccess && $phpSuccess;
44
}
45
46
/**
47
 * Performs tasks required during installation of the module
48
 * @param \XoopsModule $module {@link XoopsModule}
49
 *
50
 * @return bool true if installation successful, false if not
51
 */
52
function xoops_module_install_marquee(\XoopsModule $module)
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

52
function xoops_module_install_marquee(/** @scrutinizer ignore-unused */ \XoopsModule $module)

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...
53
{
54
    require_once \dirname(__DIR__, 3) . '/mainfile.php';
55
    $moduleDirName = \basename(\dirname(__DIR__));
56
    /** @var Marquee\Helper $helper */ /** @var Marquee\Utility $utility */
57
    /** @var Marquee\Common\Configurator $configurator */
58
    $helper       = Helper::getInstance();
59
    $utility      = new Utility();
60
    $configurator = new Configurator();
61
    // Load language files
62
    $helper->loadLanguage('admin');
63
    $helper->loadLanguage('modinfo');
64
    // default Permission Settings ----------------------
65
    global $xoopsModule;
66
    $moduleId = $xoopsModule->getVar('mid');
67
    // $moduleId2        = $helper->getModule()->mid();
68
    /** @var \XoopsGroupPermHandler $grouppermHandler */
69
    $grouppermHandler = xoops_getHandler('groupperm');
70
    // access rights ------------------------------------------
71
    $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

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