xoops_module_install_xoopspartners()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 47
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 26
nc 4
nop 1
dl 0
loc 47
rs 9.1928
c 2
b 0
f 0
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    XOOPS Project https://xoops.org/
14
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Xoopspartners;
21
use XoopsModules\Xoopspartners\Helper;
22
use XoopsModules\Xoopspartners\Utility;
23
use XoopsModules\Xoopspartners\Common;
24
25
//require_once __DIR__ . '/setup.php';
26
27
/**
28
 * Prepares system prior to attempting to install module
29
 * @param \XoopsModule $module {@link XoopsModule}
30
 *
31
 * @return bool true if ready to install, false if not
32
 */
33
function xoops_module_pre_install_xoopspartners(\XoopsModule $module)
34
{
35
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
36
    /** @var Utility $utility */
37
    $utility      = new Utility();
38
    $xoopsSuccess = $utility::checkVerXoops($module);
39
    $phpSuccess   = $utility::checkVerPhp($module);
40
41
    if (false !== $xoopsSuccess && false !== $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_xoopspartners(\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

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

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