Passed
Push — master ( 077fbd...836ec9 )
by Michael
04:09
created

tableExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
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    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal;
21
22
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)
23
    || !$GLOBALS['xoopsUser']->IsAdmin()) {
24
    exit('Restricted access' . PHP_EOL);
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_extcal(\XoopsModule $module)
34
{
35
    /** @var Extcal\Helper $helper */
36
    /** @var Extcal\Utility $utility */
37
    $helper  = Extcal\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
38
    $utility = new Extcal\Utility();
39
40
    $xoopsSuccess = $utility::checkVerXoops($module);
0 ignored issues
show
Unused Code introduced by
The assignment to $xoopsSuccess is dead and can be removed.
Loading history...
41
    $phpSuccess   = $utility::checkVerPhp($module);
0 ignored issues
show
Unused Code introduced by
The assignment to $phpSuccess is dead and can be removed.
Loading history...
42
43
    //mb    return $xoopsSuccess && $phpSuccess;
44
45
    //    XoopsLoad::load('migrate', 'extcal');
46
    /** @var \XoopsModules\Extcal\Common\Configurator $configurator */
47
    $configurator = new \XoopsModules\Extcal\Common\Configurator();
48
49
    $migrator = new \XoopsModules\Extcal\Common\Migrate($configurator);
50
    $migrator->synchronizeSchema();
51
52
    return true;
53
}
54
55
/**
56
 * Performs tasks required during update of the module
57
 * @param \XoopsModule $module {@link XoopsModule}
58
 * @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...
59
 *
60
 * @return bool true if update successful, false if not
61
 */
62
function xoops_module_update_extcal(\XoopsModule $module, $previousVersion = null)
63
{
64
    //    global $xoopsDB;
65
    $moduleDirName = basename(dirname(__DIR__));
66
67
    $newVersion = $module->getVar('version') * 100;
68
    if ($newVersion == $previousVersion) {
69
        return true;
70
    }
71
72
    $fld = XOOPS_ROOT_PATH . '/modules/' . $module->getVar('dirname') . '/versions/';
73
    $cls = 'Extcal_%1$s';
74
75
    $version = [
76
        '2_04' => 204,
77
        '2_15' => 215,
78
        '2_21' => 221,
79
        '2_28' => 228,
80
        '2_29' => 229,
81
        '2_33' => 233,
82
        '2_34' => 234,
83
        '2_35' => 235,
84
        '2_37' => 237,
85
    ];
86
87
    //    while (list($key, $val) = each($version)) {
88
    foreach ($version as $key => $val) {
89
        if ($previousVersion < $val) {
90
            $name = sprintf($cls, $key);
91
            $f    = $fld . $name . '.php';
92
            //ext_echo ("<hr>{$f}<hr>");
93
            if (is_readable($f)) {
94
                echo "update version: {$key} = {$val}<br>";
95
                require_once $f;
96
                $cl = new $name($module, ['previousVersion' => $previousVersion]);
0 ignored issues
show
Unused Code introduced by
The assignment to $cl is dead and can be removed.
Loading history...
97
            }
98
        }
99
    }
100
101
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirNameUpper is dead and can be removed.
Loading history...
102
103
    /** @var Extcal\Helper $helper */ /** @var Extcal\Utility $utility */
104
    /** @var Extcal\Common\Configurator $configurator */
105
    $helper       = Extcal\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
106
    $utility      = new Extcal\Utility();
107
    $configurator = new Extcal\Common\Configurator();
108
109
    $migrator = new \XoopsModules\Extcal\Common\Migrate($configurator);
110
    $migrator->synchronizeSchema();
111
112
    if ($previousVersion < 240) {
113
        //delete old HTML templates
114
        if (count($configurator->templateFolders) > 0) {
115
            foreach ($configurator->templateFolders as $folder) {
116
                $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder);
117
                if (is_dir($templateFolder)) {
118
                    $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);
0 ignored issues
show
Bug introduced by
It seems like scandir($templateFolder, SCANDIR_SORT_NONE) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

118
                    $templateList = array_diff(/** @scrutinizer ignore-type */ scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);
Loading history...
119
                    foreach ($templateList as $k => $v) {
120
                        $fileInfo = new SplFileInfo($templateFolder . $v);
121
                        if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) {
122
                            if (file_exists($templateFolder . $v)) {
123
                                unlink($templateFolder . $v);
124
                            }
125
                        }
126
                    }
127
                }
128
            }
129
        }
130
131
        //  ---  COPY blank.png FILES ---------------
132
        if (count($configurator->copyBlankFiles) > 0) {
133
            $file = __DIR__ . '/../assets/images/blank.png';
134
            foreach (array_keys($configurator->copyBlankFiles) as $i) {
135
                $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
136
                $utility::copyFile($file, $dest);
137
            }
138
        }
139
140
        //  ---  DELETE OLD FILES ---------------
141
        if (count($configurator->oldFiles) > 0) {
142
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
143
            foreach (array_keys($configurator->oldFiles) as $i) {
144
                $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]);
145
                if (is_file($tempFile)) {
146
                    unlink($tempFile);
147
                }
148
            }
149
        }
150
151
        //---------------------
152
153
        //delete .html entries from the tpl table
154
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
155
        $GLOBALS['xoopsDB']->queryF($sql);
156
157
        // Load class XoopsFile ====================
158
        xoops_load('XoopsFile');
159
160
        //delete /images directory ============
161
        $imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/');
162
        $folderHandler   = \XoopsFile::getHandler('folder', $imagesDirectory);
163
        $folderHandler->delete($imagesDirectory);
164
    }
165
    /** @var \XoopsGroupPermHandler $grouppermHandler */
166
    $grouppermHandler = xoops_getHandler('groupperm');
167
168
    return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read');
169
}
170