Completed
Push — master ( 7efdcc...e9c2cc )
by Michael
01:41
created

include/onupdate.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * Contact module
14
 *
15
 * @copyright   XOOPS Project (https://xoops.org)
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      Kazumi Ono (aka Onokazu)
18
 * @author      Trabis <[email protected]>
19
 * @author      Hossein Azizabadi (AKA Voltan)
20
 * @param XoopsModule $module
21
 * @param $version
22
 */
23
24
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser)
25
    || !$GLOBALS['xoopsUser']->IsAdmin()
26
) {
27
    exit('Restricted access' . PHP_EOL);
28
}
29
30
/**
31
 * @param string $tablename
32
 *
33
 * @return bool
34
 */
35
function tableExists($tablename)
36
{
37
    $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
38
39
    return $GLOBALS['xoopsDB']->getRowsNum($result) > 0;
40
}
41
42
/**
43
 *
44
 * Prepares system prior to attempting to install module
45
 * @param XoopsModule $module {@link XoopsModule}
46
 *
47
 * @return bool true if ready to install, false if not
48
 */
49
function xoops_module_pre_update_xxxx(XoopsModule $module)
50
{
51
    $moduleDirName = basename(dirname(__DIR__));
52
    /** @var \ContactUtility $classUtility */
53
    $classUtility     = ucfirst($moduleDirName) . 'Utility';
54
    if (!class_exists($classUtility)) {
55
        xoops_load('utility', $moduleDirName);
56
    }
57
    //check for minimum XOOPS version
58
    if (!$classUtility::checkVerXoops($module)) {
59
        return false;
60
    }
61
62
    // check for minimum PHP version
63
    if (!$classUtility::checkVerPhp($module)) {
64
        return false;
65
    }
66
67
    return true;
68
}
69
70
/**
71
 *
72
 * Performs tasks required during update of the module
73
 * @param XoopsModule $module {@link XoopsModule}
74
 * @param null        $previousVersion
75
 *
76
 * @return bool true if update successful, false if not
77
 */
78
function xoops_module_update_contact(XoopsModule $module, $previousVersion = null)
0 ignored issues
show
The function xoops_module_update_contact() has been defined more than once; this definition is ignored, only the first definition in include/functions_update.php (L22-79) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
79
{
80
    $moduleDirName = basename(dirname(__DIR__));
81
    $capsDirName   = strtoupper($moduleDirName);
82
83
    $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();
84
85 View Code Duplication
    if ($previousVersion < 180) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('contact') . ' (
87
        contact_id int(10) unsigned NOT NULL auto_increment,
88
        contact_uid int(10) NOT NULL,
89
        contact_cid int(10) NOT NULL,
90
        contact_create int(10) NOT NULL,
91
        contact_subject varchar(255) NOT NULL,
92
        contact_name varchar(255) NOT NULL,
93
        contact_mail varchar(255) NOT NULL,
94
        contact_url varchar(255) NOT NULL,
95
        contact_icq varchar(255) NOT NULL,
96
        contact_company varchar(255) NOT NULL,
97
        contact_location varchar(255) NOT NULL,
98
        contact_department varchar(60) NOT NULL,
99
        contact_ip varchar(20) NOT NULL,
100
        contact_phone varchar(20) NOT NULL,
101
        contact_message text NOT NULL,
102
        contact_address text NOT NULL,
103
        contact_reply tinyint(1) NOT NULL,
104
        PRIMARY KEY  (contact_id)
105
        ) ENGINE=MyISAM;';
106
        $xoopsDB->query($sql);
107
    }
108
109 View Code Duplication
    if ($previousVersion < 181) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
        // Add contact_platform
111
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . "` ADD `contact_platform` ENUM('Android','Ios','Web') NOT NULL DEFAULT 'Web'";
112
        $xoopsDB->query($sql);
113
        // Add contact_type
114
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . "` ADD `contact_type` ENUM('Contact','Phone','Mail') NOT NULL DEFAULT 'Contact'";
115
        $xoopsDB->query($sql);
116
        // Add index contact_uid
117
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_uid` ( `contact_uid` )';
118
        $xoopsDB->query($sql);
119
        // Add index contact_cid
120
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_cid` ( `contact_cid` )';
121
        $xoopsDB->query($sql);
122
        // Add index contact_create
123
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_create` ( `contact_create` )';
124
        $xoopsDB->query($sql);
125
        // Add index contact_mail
126
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_mail` ( `contact_mail` )';
127
        $xoopsDB->query($sql);
128
        // Add index contact_phone
129
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_phone` ( `contact_phone` )';
130
        $xoopsDB->query($sql);
131
        // Add index contact_platform
132
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_platform` ( `contact_platform` )';
133
        $xoopsDB->query($sql);
134
        // Add index contact_type
135
        $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_type` ( `contact_type` )';
136
        $xoopsDB->query($sql);
137
    }
138
139
    if ($previousVersion < 226) {
140
        require_once __DIR__ . '/config.php';
141
        $configurator = new ContentConfigurator();
142
        $classUtility    = ucfirst($moduleDirName) . 'Utility';
143
        if (!class_exists($classUtility)) {
144
            xoops_load('utility', $moduleDirName);
145
        }
146
147
        //delete old HTML templates
148
        if (count($configurator->templateFolders) > 0) {
149
            foreach ($configurator->templateFolders as $folder) {
150
                $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder);
151
                if (is_dir($templateFolder)) {
152
                    $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), array('..', '.'));
153
                    foreach ($templateList as $k => $v) {
154
                        $fileInfo = new SplFileInfo($templateFolder . $v);
155
                        if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') {
156
                            if (file_exists($templateFolder . $v)) {
157
                                unlink($templateFolder . $v);
158
                            }
159
                        }
160
                    }
161
                }
162
            }
163
        }
164
165
        //  ---  DELETE OLD FILES ---------------
166
        if (count($configurator->oldFiles) > 0) {
167
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
168
            foreach (array_keys($configurator->oldFiles) as $i) {
169
                $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]);
170
                if (is_file($tempFile)) {
171
                    unlink($tempFile);
172
                }
173
            }
174
        }
175
176
        //  ---  DELETE OLD FOLDERS ---------------
177
        xoops_load('XoopsFile');
178
        if (count($configurator->oldFolders) > 0) {
179
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
180
            foreach (array_keys($configurator->oldFolders) as $i) {
181
                $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]);
182
                /* @var $folderHandler XoopsObjectHandler */
183
                $folderHandler = XoopsFile::getHandler('folder', $tempFolder);
184
                $folderHandler->delete($tempFolder);
185
            }
186
        }
187
188
        //  ---  CREATE FOLDERS ---------------
189 View Code Duplication
        if (count($configurator->uploadFolders) > 0) {
190
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
191
            foreach (array_keys($configurator->uploadFolders) as $i) {
192
                $classUtility::createFolder($configurator->uploadFolders[$i]);
193
            }
194
        }
195
196
        //  ---  COPY blank.png FILES ---------------
197 View Code Duplication
        if (count($configurator->blankFiles) > 0) {
198
            $file = __DIR__ . '/../assets/images/blank.png';
199
            foreach (array_keys($configurator->blankFiles) as $i) {
200
                $dest = $configurator->blankFiles[$i] . '/blank.png';
201
                $classUtility::copyFile($file, $dest);
202
            }
203
        }
204
205
        //delete .html entries from the tpl table
206
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\'';
207
        $GLOBALS['xoopsDB']->queryF($sql);
208
209
        /** @var XoopsGroupPermHandler $gpermHandler */
210
        $gpermHandler = xoops_getHandler('groupperm');
211
        return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read');
212
    }
213
}
214