xoops_module_install_soapbox()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 46
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 23
nc 4
nop 1
dl 0
loc 46
rs 9.2408
c 1
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 (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Soapbox;
21
use XoopsModules\Soapbox\Common;
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_soapbox(\XoopsModule $module)
30
{
31
    include __DIR__ . '/common.php';
32
    //    /** @var \XoopsModules\Soapbox\Utility $utility */
33
    //    $utility = new \XoopsModules\Soapbox\Utility();
34
35
    //check for minimum XOOPS version
36
    $xoopsSuccess = $utility::checkVerXoops($module);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $utility seems to be never defined.
Loading history...
37
38
    // check for minimum PHP version
39
    $phpSuccess = $utility::checkVerPhp($module);
40
41
    if ($xoopsSuccess && $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_soapbox(\XoopsModule $module)
58
{
59
    require_once dirname(__DIR__) . '/preloads/autoloader.php';
60
    $moduleDirName = basename(dirname(__DIR__));
61
62
    /** @var \XoopsModules\Soapbox\Helper $helper */
63
    /** @var \XoopsModules\Soapbox\Utility $utility */
64
    /** @var \XoopsModules\Soapbox\Common\Configurator $configurator */
65
    $helper       = \XoopsModules\Soapbox\Helper::getInstance();
66
    $utility      = new \XoopsModules\Soapbox\Utility();
67
    $configurator = new \XoopsModules\Soapbox\Common\Configurator();
68
    // Load language files
69
    $helper->loadLanguage('admin');
70
    $helper->loadLanguage('modinfo');
71
72
    // default Permission Settings ----------------------
73
74
    $moduleId = $module->getVar('mid');
75
    //    $moduleId2 = $helper->getModule()->mid();
76
    //$moduleName = $module->getVar('name');
77
    $grouppermHandler = xoops_getHandler('groupperm');
78
    // access rights ------------------------------------------
79
    $grouppermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
0 ignored issues
show
Bug introduced by
The method addRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

79
    $grouppermHandler->/** @scrutinizer ignore-call */ 
80
                       addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId);
Loading history...
80
    $grouppermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId);
81
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId);
82
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId);
83
    $grouppermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId);
84
85
    //  ---  CREATE FOLDERS ---------------
86
    if (count($configurator->uploadFolders) > 0) {
87
        //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
88
        foreach (array_keys($configurator->uploadFolders) as $i) {
89
            $utility::createFolder($configurator->uploadFolders[$i]);
90
        }
91
    }
92
93
    //  ---  COPY blank.png FILES ---------------
94
    if (count($configurator->copyBlankFiles) > 0) {
95
        $file = dirname(__DIR__) . '/assets/images/blank.png';
96
        foreach (array_keys($configurator->copyBlankFiles) as $i) {
97
            $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
98
            $utility::copyFile($file, $dest);
99
        }
100
    }
101
102
    return true;
103
}
104