Passed
Push — master ( 9778b7...bce46e )
by Michael
03:49
created

tableExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
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\Moduleinstaller;
19
20
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)
21
    || !$GLOBALS['xoopsUser']->isAdmin()) {
22
    exit('Restricted access' . PHP_EOL);
23
}
24
25
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_update_moduleinstaller(\XoopsModule $module)
34
{
35
    $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
36
    /** @var Moduleinstaller\Helper $helper */
37
    /** @var Moduleinstaller\Utility $utility */
38
    $helper  = Moduleinstaller\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
39
    $utility = new Moduleinstaller\Utility();
40
41
    $xoopsSuccess = $utility::checkVerXoops($module);
42
    $phpSuccess   = $utility::checkVerPhp($module);
43
44
    return $xoopsSuccess && $phpSuccess;
45
}
46
47
/**
48
 * Performs tasks required during update of the module
49
 * @param \XoopsModule $module {@link XoopsModule}
50
 * @param null         $previousVersion
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $previousVersion is correct as it would always require null to be passed?
Loading history...
51
 *
52
 * @return bool true if update successful, false if not
53
 */
54
function xoops_module_update_moduleinstaller(\XoopsModule $module, $previousVersion = null)
55
{
56
    $moduleDirName      = \basename(\dirname(__DIR__));
57
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirNameUpper is dead and can be removed.
Loading history...
58
59
    /** @var Moduleinstaller\Helper $helper */ /** @var Moduleinstaller\Utility $utility */
60
    /** @var Moduleinstaller\Common\Configurator $configurator */
61
    $helper       = Moduleinstaller\Helper::getInstance();
62
    $utility      = new Moduleinstaller\Utility();
63
    $configurator = new Moduleinstaller\Common\Configurator();
64
65
    $helper->loadLanguage('common');
66
67
    if ($previousVersion < 240) {
68
        //delete old HTML templates
69
        if (count($configurator->templateFolders) > 0) {
70
            foreach ($configurator->templateFolders as $folder) {
71
                $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder);
72
                if (is_dir($templateFolder)) {
73
                    $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);
74
                    foreach ($templateList as $k => $v) {
75
                        $fileInfo = new \SplFileInfo($templateFolder . $v);
76
                        if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) {
77
                            if (is_file($templateFolder . $v)) {
78
                                unlink($templateFolder . $v);
79
                            }
80
                        }
81
                    }
82
                }
83
            }
84
        }
85
86
        //  ---  DELETE OLD FILES ---------------
87
        if (count($configurator->oldFiles) > 0) {
88
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
89
            foreach (array_keys($configurator->oldFiles) as $i) {
90
                $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]);
91
                if (is_file($tempFile)) {
92
                    unlink($tempFile);
93
                }
94
            }
95
        }
96
97
        //  ---  DELETE OLD FOLDERS ---------------
98
        xoops_load('XoopsFile');
99
        if (count($configurator->oldFolders) > 0) {
100
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
101
            foreach (array_keys($configurator->oldFolders) as $i) {
102
                $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]);
103
                /* @var XoopsObjectHandler $folderHandler */
104
                $folderHandler = XoopsFile::getHandler('folder', $tempFolder);
105
                $folderHandler->delete($tempFolder);
106
            }
107
        }
108
109
        //  ---  CREATE FOLDERS ---------------
110
        if (count($configurator->uploadFolders) > 0) {
111
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
112
            foreach (array_keys($configurator->uploadFolders) as $i) {
113
                $utility::createFolder($configurator->uploadFolders[$i]);
114
            }
115
        }
116
117
        //  ---  COPY blank.png FILES ---------------
118
        if (count($configurator->copyBlankFiles) > 0) {
119
            $file = dirname(__DIR__) . '/assets/images/blank.png';
120
            foreach (array_keys($configurator->copyBlankFiles) as $i) {
121
                $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
122
                $utility::copyFile($file, $dest);
123
            }
124
        }
125
126
        //delete .html entries from the tpl table
127
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\'';
128
        $GLOBALS['xoopsDB']->queryF($sql);
129
130
        /** @var \XoopsGroupPermHandler $grouppermHandler */
131
        $grouppermHandler = xoops_getHandler('groupperm');
132
133
        return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read');
134
    }
135
136
    return true;
137
}
138