xoops_module_pre_install_extgallery()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 19
rs 9.6111
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 (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author       XOOPS Development Team
16
 */
17
18
use XoopsModules\Extgallery;
19
use XoopsModules\Extgallery\Utility;
20
21
/**
22
 * Prepares system prior to attempting to install module
23
 * @param \XoopsModule $module {@link XoopsModule}
24
 *
25
 * @return bool true if ready to install, false if not
26
 */
27
function xoops_module_pre_install_extgallery(\XoopsModule $module)
28
{
29
    require_once __DIR__ . '/common.php';
30
    /** @var Extgallery\Utility $utility */
31
    $utility = new Utility();
32
    //check for minimum XOOPS version
33
    $xoopsSuccess = $utility::checkVerXoops($module);
34
35
    // check for minimum PHP version
36
    $phpSuccess = $utility::checkVerPhp($module);
37
38
    if (false !== $xoopsSuccess && false !== $phpSuccess) {
39
        $moduleTables = &$module->getInfo('tables');
40
        foreach ($moduleTables as $table) {
41
            $GLOBALS['xoopsDB']->queryF('DROP TABLE IF EXISTS ' . $GLOBALS['xoopsDB']->prefix($table) . ';');
42
        }
43
    }
44
45
    return $xoopsSuccess && $phpSuccess;
46
}
47
48
/**
49
 * Performs tasks required during installation of the module
50
 * @param \XoopsModule $module
51
 * @return void true if installation successful, false if not
52
 * @internal param XoopsModule $module <a href='psi_element://XoopsModule'>XoopsModule</a>
53
 */
54
function xoops_module_install_extgallery(\XoopsModule $module)
55
{
56
    require_once \dirname(__DIR__) . '/preloads/autoloader.php';
57
58
    $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
59
60
    $module_id = $module->getVar('mid');
61
    /** @var \XoopsGroupPermHandler $grouppermHandler */
62
    $grouppermHandler = xoops_getHandler('groupperm');
63
    /** @var \XoopsModuleHandler $moduleHandler */
64
    /** @var \XoopsConfigHandler $configHandler */
65
    $configHandler = xoops_getHandler('config');
0 ignored issues
show
Unused Code introduced by
The assignment to $configHandler is dead and can be removed.
Loading history...
66
67
    /**
68
     * Default public category permission mask
69
     */
70
71
    // Access right
72
    $grouppermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_ADMIN, $module_id);
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

72
    $grouppermHandler->addRight('extgallery_public_mask', 1, /** @scrutinizer ignore-type */ XOOPS_GROUP_ADMIN, $module_id);
Loading history...
73
    $grouppermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_USERS, $module_id);
74
    $grouppermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_ANONYMOUS, $module_id);
75
76
    // Public rate
77
    $grouppermHandler->addRight('extgallery_public_mask', 2, XOOPS_GROUP_ADMIN, $module_id);
78
    $grouppermHandler->addRight('extgallery_public_mask', 2, XOOPS_GROUP_USERS, $module_id);
79
80
    // Public eCard
81
    $grouppermHandler->addRight('extgallery_public_mask', 4, XOOPS_GROUP_ADMIN, $module_id);
82
    $grouppermHandler->addRight('extgallery_public_mask', 4, XOOPS_GROUP_USERS, $module_id);
83
84
    // Public download
85
    $grouppermHandler->addRight('extgallery_public_mask', 8, XOOPS_GROUP_ADMIN, $module_id);
86
    $grouppermHandler->addRight('extgallery_public_mask', 8, XOOPS_GROUP_USERS, $module_id);
87
88
    // Public upload
89
    $grouppermHandler->addRight('extgallery_public_mask', 16, XOOPS_GROUP_ADMIN, $module_id);
90
91
    // Public autoapprove
92
    $grouppermHandler->addRight('extgallery_public_mask', 32, XOOPS_GROUP_ADMIN, $module_id);
93
94
    // Public display
95
    $grouppermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_ADMIN, $module_id);
96
    $grouppermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_USERS, $module_id);
97
    $grouppermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_ANONYMOUS, $module_id);
98
99
    /**
100
     * Default User's category permission
101
     */
102
103
    // Private gallery
104
105
    // Private rate
106
    $grouppermHandler->addRight('extgallery_private', 2, XOOPS_GROUP_ADMIN, $module_id);
107
    $grouppermHandler->addRight('extgallery_private', 2, XOOPS_GROUP_USERS, $module_id);
108
109
    // Private eCard
110
    $grouppermHandler->addRight('extgallery_private', 4, XOOPS_GROUP_ADMIN, $module_id);
111
    $grouppermHandler->addRight('extgallery_private', 4, XOOPS_GROUP_USERS, $module_id);
112
113
    // Private download
114
    $grouppermHandler->addRight('extgallery_private', 8, XOOPS_GROUP_ADMIN, $module_id);
115
    $grouppermHandler->addRight('extgallery_private', 8, XOOPS_GROUP_USERS, $module_id);
116
117
    // Private autoapprove
118
    $grouppermHandler->addRight('extgallery_private', 16, XOOPS_GROUP_ADMIN, $module_id);
119
}
120