xoops_module_pre_install_myiframe()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 16
rs 9.6111
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\Myiframe;
19
use XoopsModules\Myiframe\Utility;
20
21
//require_once __DIR__ . '/setup.php';
22
23
/**
24
 * Prepares system prior to attempting to install module
25
 * @param \XoopsModule $module {@link XoopsModule}
26
 *
27
 * @return bool true if ready to install, false if not
28
 */
29
function xoops_module_pre_install_myiframe(\XoopsModule $module)
30
{
31
    require_once \dirname(__DIR__) . '/preloads/autoloader.php';
32
    /** @var \Utility $utility */
33
    $utility      = new Utility();
34
    $xoopsSuccess = $utility::checkVerXoops($module);
35
    $phpSuccess   = $utility::checkVerPhp($module);
36
37
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
38
        $moduleTables = &$module->getInfo('tables');
39
        foreach ($moduleTables as $table) {
40
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
41
        }
42
    }
43
44
    return $xoopsSuccess && $phpSuccess;
45
}
46
47
/**
48
 * Performs tasks required during installation of the module
49
 * @param \XoopsModule $module {@link XoopsModule}
50
 *
51
 * @return bool true if installation successful, false if not
52
 */
53
function xoops_module_install_myiframe(\XoopsModule $module)
54
{
55
    require \dirname(__DIR__, 3) . '/mainfile.php';
56
57
    $moduleDirName = \basename(\dirname(__DIR__));
58
59
    /** @var Myiframe\Helper $helper */
60
    $helper = Myiframe\Helper::getInstance();
61
    /** @var Myiframe\Utility $helper */
62
    $utility = new Utility();
63
    /** @var Myiframe\Common\Configurator $helper */
64
    $configurator = new Myiframe\Common\Configurator();
65
    // Load language files
66
    $helper->loadLanguage('admin');
0 ignored issues
show
Bug introduced by
The method loadLanguage() does not exist on XoopsModules\Myiframe\Common\Configurator. ( Ignorable by Annotation )

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

66
    $helper->/** @scrutinizer ignore-call */ 
67
             loadLanguage('admin');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
    $helper->loadLanguage('modinfo');
68
69
    // default Permission Settings ----------------------
70
    global $xoopsModule;
71
    $moduleId = $xoopsModule->getVar('mid');
72
    // $moduleId2        = $helper->getModule()->mid();
73
    /** @var \XoopsGroupPermHandler $grouppermHandler */
74
    $grouppermHandler = xoops_getHandler('groupperm');
75
    // access rights ------------------------------------------
76
    $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

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