xoops_module_update_wfdownloads()   D
last analyzed

Complexity

Conditions 18
Paths 33

Size

Total Lines 73
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 37
nc 33
nop 2
dl 0
loc 73
rs 4.8666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * Wfdownloads module
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package         wfdownload
18
 * @since           3.23
19
 * @author          Xoops Development Team
20
 */
21
22
use XoopsModules\Wfdownloads;
23
use XoopsModules\Wfdownloads\{
24
    Helper,
25
    Utility
26
};
27
/** @var Helper $helper */
28
/** @var Utility $utility */
29
30
if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof XoopsUser)
31
    || !$GLOBALS['xoopsUser']->isAdmin()) {
32
    exit('Restricted access' . PHP_EOL);
33
}
34
35
/**
36
 * @param string $tablename
37
 *
38
 * @return bool
39
 */
40
function tableExists($tablename)
41
{
42
    $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'");
43
44
    return $GLOBALS['xoopsDB']->getRowsNum($result) > 0;
45
}
46
47
/**
48
 * Prepares system prior to attempting to install module
49
 * @param \XoopsModule $module {@link XoopsModule}
50
 *
51
 * @return bool true if ready to install, false if not
52
 */
53
function xoops_module_pre_update_wfdownloads(XoopsModule $module)
54
{
55
    /** @var \XoopsModules\Wfdownloads\Helper $helper */
56
    /** @var Wfdownloads\Utility $utility */
57
    $moduleDirName = basename(dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
58
    $helper        = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
59
    $utility       = new Wfdownloads\Utility();
60
61
    $xoopsSuccess = $utility::checkVerXoops($module);
62
    $phpSuccess   = $utility::checkVerPhp($module);
63
64
    //TODO Migration
65
    //    XoopsLoad::load('migrate', 'newbb');
66
67
    //    $newbbMigrate = new Wfdownloads\Migrate();
68
    //    $newbbMigrate->synchronizeSchema();
69
    //
70
    //    return true;
71
72
    return $xoopsSuccess && $phpSuccess;
73
}
74
75
/**
76
 * Performs tasks required during update of the module
77
 * @param \XoopsModule $module {@link XoopsModule}
78
 * @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...
79
 */
80
function xoops_module_update_wfdownloads(XoopsModule $module, $previousVersion = null)
81
{
82
    $moduleDirName      = basename(dirname(__DIR__));
83
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirNameUpper is dead and can be removed.
Loading history...
84
85
    /** @var \XoopsModules\Wfdownloads\Helper $helper */ /** @var Wfdownloads\Utility $utility */
86
    /** @var Wfdownloads\Common\Configurator $configurator */
87
    $helper       = Helper::getInstance();
88
    $utility      = new Wfdownloads\Utility();
89
    $configurator = new Wfdownloads\Common\Configurator();
90
91
    if ($previousVersion < 325) {
92
        //delete old HTML templates
93
        if (count($configurator->templateFolders) > 0) {
94
            foreach ($configurator->templateFolders as $folder) {
95
                $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder);
96
                if (is_dir($templateFolder)) {
97
                    $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

97
                    $templateList = array_diff(/** @scrutinizer ignore-type */ scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);
Loading history...
98
                    foreach ($templateList as $k => $v) {
99
                        $fileInfo = new SplFileInfo($templateFolder . $v);
100
                        if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) {
101
                            if (is_file($templateFolder . $v)) {
102
                                unlink($templateFolder . $v);
103
                            }
104
                        }
105
                    }
106
                }
107
            }
108
        }
109
110
        //  ---  DELETE OLD FILES ---------------
111
        if (count($configurator->oldFiles) > 0) {
112
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
113
            foreach (array_keys($configurator->oldFiles) as $i) {
114
                $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]);
115
                if (is_file($tempFile)) {
116
                    unlink($tempFile);
117
                }
118
            }
119
        }
120
121
        //  ---  DELETE OLD FOLDERS ---------------
122
        xoops_load('XoopsFile');
123
        if (count($configurator->oldFolders) > 0) {
124
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
125
            foreach (array_keys($configurator->oldFolders) as $i) {
126
                $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]);
127
                /** @var \XoopsObjectHandler $folderHandler */
128
                $folderHandler = $helper->getHandler('Folder', $tempFolder);
0 ignored issues
show
Unused Code introduced by
The call to XoopsModules\Wfdownloads\Helper::getHandler() has too many arguments starting with $tempFolder. ( Ignorable by Annotation )

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

128
                /** @scrutinizer ignore-call */ 
129
                $folderHandler = $helper->getHandler('Folder', $tempFolder);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
129
                $folderHandler->delete($tempFolder);
130
            }
131
        }
132
133
        //  ---  CREATE FOLDERS ---------------
134
        if (count($configurator->uploadFolders) > 0) {
135
            //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
136
            foreach (array_keys($configurator->uploadFolders) as $i) {
137
                $utility::createFolder($configurator->uploadFolders[$i]);
138
            }
139
        }
140
141
        //  ---  COPY blank.png FILES ---------------
142
        if (count($configurator->copyBlankFiles) > 0) {
143
            $file = dirname(__DIR__) . '/assets/images/blank.png';
144
            foreach (array_keys($configurator->copyBlankFiles) as $i) {
145
                $dest = $configurator->copyBlankFiles[$i] . '/blank.png';
146
                $utility::copyFile($file, $dest);
147
            }
148
        }
149
150
        //delete .html entries from the tpl table
151
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'";
152
        $GLOBALS['xoopsDB']->queryF($sql);
153
    }
154
}
155
156
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
157
require_once __DIR__ . '/common.php';
158
//@require_once WFDOWNLOADS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/admin.php';
159
xoops_loadLanguage('admin', $helper->getModule()->dirname());
160
161
/**
162
 * @param \XoopsModule $xoopsModule
163
 * @param              $previousVersion
164
 *
165
 * @return bool
166
 */
167
function xoops_module_update_wfdownloads2(XoopsModule $xoopsModule, $previousVersion)
168
{
169
    ob_start();
170
    invert_nohtm_dohtml_values();
171
    if ($previousVersion < 322) {
172
        update_tables_to_322($xoopsModule);
173
    }
174
    if ($previousVersion < 323) {
175
        update_permissions_to_323($xoopsModule);
176
        update_tables_to_323($xoopsModule);
177
    }
178
    $feedback = ob_get_clean();
179
    if (method_exists($xoopsModule, 'setMessage')) {
180
        $xoopsModule->setMessage($feedback);
181
    } else {
182
        echo $feedback;
183
    }
184
    Utility::setMeta('version', '3.23'); //Set meta version to current
185
186
    return true;
187
}
188
189
// =========================================================================================
190
// This function updates any existing table of a 3.22 version to the format used
191
// in the release of Wfdownloads 3.23
192
// =========================================================================================
193
/**
194
 * @param \XoopsModule $module
195
 */
196
function update_tables_to_323(XoopsModule $module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

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

196
function update_tables_to_323(/** @scrutinizer ignore-unused */ XoopsModule $module)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
197
{
198
    $dbupdater = new Wfdownloads\Dbupdater();
199
200
    // update wfdownloads_downloads table
201
    $download_fields = [
202
        'lid'             => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false],
203
        'cid'             => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true],
204
        'title'           => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
205
        'url'             => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
206
        'filename'        => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true],
207
        'filetype'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
208
        'homepage'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
209
        'version'         => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true],
210
        'size'            => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true],
211
        'platform'        => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true],
212
        'screenshot'      => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
213
        'screenshot2'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
214
        'screenshot3'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
215
        'screenshot4'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
216
        'submitter'       => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
217
        'publisher'       => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
218
        'status'          => ['Type' => "tinyint(2) NOT NULL default '" . _WFDOWNLOADS_STATUS_WAITING . "'", 'Default' => true],
219
        'date'            => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
220
        'hits'            => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
221
        'rating'          => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true],
222
        'votes'           => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
223
        'comments'        => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
224
        'license'         => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
225
        'mirror'          => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
226
        'price'           => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true],
227
        'paypalemail'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
228
        'features'        => ['Type' => 'text NULL', 'Default' => false],
229
        'requirements'    => ['Type' => 'text NULL', 'Default' => false],
230
        'homepagetitle'   => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
231
        'forumid'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
232
        'limitations'     => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true],
233
        'versiontypes'    => ['Type' => "varchar(255) NOT NULL default 'None'", 'Default' => true],
234
        'dhistory'        => ['Type' => 'text NULL', 'Default' => false],
235
        'published'       => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true],
236
        'expired'         => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
237
        'updated'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
238
        'offline'         => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
239
        'description'     => ['Type' => 'text NULL', 'Default' => false],
240
        'ipaddress'       => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true],
241
        'notifypub'       => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true],
242
        'summary'         => ['Type' => 'text NULL', 'Default' => false],
243
        'formulize_idreq' => ['Type' => "int(5) NOT NULL default '0'", 'Default' => true],
244
        // added 3.23
245
        'screenshots'     => ['Type' => 'text NOT NULL', 'Default' => true],
246
        'dohtml'          => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
247
        'dosmiley'        => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
248
        'doxcode'         => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
249
        'doimage'         => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
250
        'dobr'            => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
251
    ];
252
    //$renamed_fields = array(
253
    //    "old_name" => "new_name"
254
    //);
255
    echo "<br><span style='font-weight: bold;'>Checking Download table</span><br>";
256
    /** @var Wfdownloads\DownloadHandler $downloadHandler */
257
    $downloadHandler = $helper->getHandler('Download');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
258
    $download_table  = new Wfdownloads\DbupdaterTable('wfdownloads_downloads');
259
    $fields          = get_table_info($downloadHandler->table, $download_fields);
260
    // check for renamed fields
261
    //rename_fields($download_table, $renamed_fields, $fields, $download_fields);
262
    // check for updated fields
263
    update_table($download_fields, $fields, $download_table);
264
    if ($dbupdater->updateTable($download_table)) {
265
        echo 'Downloads table updated<br>';
266
    }
267
    unset($fields);
268
    // populate screenshots with screenshot, screenshot2, screenshot3, screenshot4 values
269
    $downloadsObjs = $downloadHandler->getObjects();
270
    foreach ($downloadsObjs as $downloadsObj) {
271
        $screenshots   = [];
272
        $screenshots[] = $downloadsObj->getVar('screenshot');
273
        $screenshots[] = $downloadsObj->getVar('screenshot2');
274
        $screenshots[] = $downloadsObj->getVar('screenshot3');
275
        $screenshots[] = $downloadsObj->getVar('screenshot4');
276
        $downloadsObj->setVar('screenshots', $screenshots);
277
        unset($screenshots);
278
        $downloadHandler->insert($downloadsObj);
279
    }
280
281
    // update wfdownloads_mod table
282
    $mod_fields = [
283
        'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false],
284
285
        'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
286
        'requestdate'     => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
287
288
        'lid'             => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
289
        'cid'             => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true],
290
        'title'           => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
291
        'url'             => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
292
        'filename'        => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true],
293
        'filetype'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
294
        'homepage'        => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
295
        'version'         => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true],
296
        'size'            => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true],
297
        'platform'        => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true],
298
        'screenshot'      => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
299
        'screenshot2'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
300
        'screenshot3'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
301
        'screenshot4'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
302
        'submitter'       => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
303
        'publisher'       => ['Type' => 'text NULL', 'Default' => false],
304
        'status'          => ['Type' => "tinyint(2) NOT NULL default '" . _WFDOWNLOADS_STATUS_WAITING . "'", 'Default' => true],
305
        'date'            => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
306
        'hits'            => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
307
        'rating'          => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true],
308
        'votes'           => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
309
        'comments'        => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
310
        'license'         => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
311
        'mirror'          => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
312
        'price'           => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true],
313
        'paypalemail'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
314
        'features'        => ['Type' => 'text NULL', 'Default' => false],
315
        'requirements'    => ['Type' => 'text NULL', 'Default' => false],
316
        'homepagetitle'   => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
317
        'forumid'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
318
        'limitations'     => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true],
319
        'versiontypes'    => ['Type' => "varchar(255) NOT NULL default 'None'", 'Default' => true],
320
        'dhistory'        => ['Type' => 'text NOT NULL', 'Default' => false],
321
        'published'       => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
322
        'expired'         => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
323
        'updated'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
324
        'offline'         => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
325
        'summary'         => ['Type' => 'text NULL', 'Default' => false],
326
        'description'     => ['Type' => 'text NULL', 'Default' => false],
327
        // ???
328
        'formulize_idreq' => ['Type' => "int(5) NOT NULL default '0'", 'Default' => true],
329
        // added 3.23
330
        'screenshots'     => ['Type' => 'text NULL', 'Default' => true],
331
        'dohtml'          => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
332
        'dosmiley'        => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
333
        'doxcode'         => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
334
        'doimage'         => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
335
        'dobr'            => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
336
    ];
337
    //$renamed_fields = array(
338
    //    "old_name" => "new_name"
339
    //);
340
    echo "<br><span style='font-weight: bold;'>Checking Modified Downloads table</span><br>";
341
    $modificationHandler = $helper->getHandler('Modification');
342
    $mod_table           = new Wfdownloads\DbupdaterTable('wfdownloads_mod');
343
    $fields              = get_table_info($modificationHandler->table, $mod_fields);
344
    // check for renamed fields
345
    //rename_fields($mod_table, $renamed_fields, $fields, $mod_fields);
346
    // check for updated fields
347
    update_table($mod_fields, $fields, $mod_table);
348
    if ($dbupdater->updateTable($mod_table)) {
349
        echo 'Modified Downloads table updated <br>';
350
    }
351
    unset($fields);
352
}
353
354
// =========================================================================================
355
// This function updates permissions to Wfdownloads 3.23 permissions
356
// add 'WFUpCatPerm' permission where is set 'WFDownCatPerm' permission
357
// =========================================================================================
358
/**
359
 * @param \XoopsModule $module
360
 */
361
function update_permissions_to_323(XoopsModule $module)
362
{
363
    /** @var \XoopsGroupPermHandler $grouppermHandler */
364
    $grouppermHandler = xoops_getHandler('groupperm');
365
    /** @var Wfdownloads\CategoryHandler $categoriesHandler */
366
    $categoriesHandler = $helper->getHandler('Category', $module->dirname());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
367
368
    $cids = $categoriesHandler->getIds();
369
    if (count($cids) > 0) {
370
        echo "<br><span style='font-weight: bold;'>Adding upload permissions to categories</span><br>";
371
        foreach ($cids as $cid) {
372
            $down_groups_ids = $grouppermHandler->getGroupIds('WFDownCatPerm', $cid, $module->mid());
373
            foreach ($down_groups_ids as $down_group_id) {
374
                //$grouppermHandler->deleteByModule($module->mid(), 'WFUpCatPerm', $cid);
375
                $grouppermHandler->addRight('WFUpCatPerm', $cid, $down_group_id, $module->mid());
376
            }
377
        }
378
    } else {
379
        echo "<br><span style='font-weight: bold;'>No categories, no permissions</span><br>";
380
    }
381
}
382
383
// =========================================================================================
384
// This function updates any existing table of a 2.x version to the format used
385
// in the release of Wfdownloads 3.00
386
// =========================================================================================
387
/**
388
 * @param $module
389
 */
390
function update_tables_to_322($module)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed. ( Ignorable by Annotation )

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

390
function update_tables_to_322(/** @scrutinizer ignore-unused */ $module)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
391
{
392
    $dbupdater = new Wfdownloads\Dbupdater();
393
394
    // create wfdownloads_meta table
395
    if (!Utility::tableExists('wfdownloads_meta')) {
396
        $table = new Wfdownloads\DbupdaterTable('wfdownloads_meta');
397
        $table->setStructure(
398
            "CREATE TABLE %s (
399
                metakey VARCHAR(50) NOT NULL DEFAULT '',
400
                metavalue VARCHAR(255) NOT NULL DEFAULT '',
401
                PRIMARY KEY (metakey))
402
                ENGINE=MyISAM;"
403
        );
404
        $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2)));
405
        if ($dbupdater->updateTable($table)) {
406
            echo 'wfdownloads_meta table created<br>';
407
        }
408
    }
409
410
    // create wfdownloads_mirror table
411
    if (!Utility::tableExists('wfdownloads_mirrors')) {
412
        $table = new Wfdownloads\DbupdaterTable('wfdownloads_mirrors');
413
        $table->setStructure(
414
            "CREATE TABLE %s (
415
                mirror_id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
416
                lid INT(11) NOT NULL DEFAULT '0',
417
                title VARCHAR(255) NOT NULL DEFAULT '',
418
                homeurl VARCHAR(100) NOT NULL DEFAULT '',
419
                location VARCHAR(255) NOT NULL DEFAULT '',
420
                continent VARCHAR(255) NOT NULL DEFAULT '',
421
                downurl VARCHAR(255) NOT NULL DEFAULT '',
422
                submit INT(11) NOT NULL DEFAULT '0',
423
                date INT(11) NOT NULL DEFAULT '0',
424
                uid INT(10) NOT NULL DEFAULT '0',
425
                PRIMARY KEY  (mirror_id),
426
                KEY categoryid (lid))
427
                ENGINE=MyISAM;"
428
        );
429
        if ($dbupdater->updateTable($table)) {
430
            echo 'wfdownloads_mirrors table created<br>';
431
        }
432
    }
433
434
    // create wfdownloads_ip_log table
435
    if (!Utility::tableExists('wfdownloads_ip_log')) {
436
        $table = new Wfdownloads\DbupdaterTable('wfdownloads_ip_log');
437
        $table->setStructure(
438
            "CREATE TABLE %s (
439
                ip_logid INT(11) NOT NULL AUTO_INCREMENT,
440
                lid INT(11) NOT NULL DEFAULT '0',
441
                uid INT(11) NOT NULL DEFAULT '0',
442
                date INT(11) NOT NULL DEFAULT '0',
443
                ip_address VARCHAR(20) NOT NULL DEFAULT '',
444
                PRIMARY KEY  (ip_logid)
445
                ENGINE=MyISAM;"
446
        );
447
        if ($dbupdater->updateTable($table)) {
448
            echo 'wfdownloads_mirrors table created<br>';
449
        }
450
    }
451
452
    // update wfdownloads_downloads table
453
    $download_fields = [
454
        'lid'             => ['Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false],
455
        'cid'             => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true],
456
        'title'           => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
457
        'url'             => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
458
        'filename'        => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true],
459
        'filetype'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
460
        'homepage'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
461
        'version'         => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true],
462
        'size'            => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true],
463
        'platform'        => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true],
464
        'screenshot'      => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
465
        'screenshot2'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
466
        'screenshot3'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
467
        'screenshot4'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
468
        'submitter'       => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
469
        'publisher'       => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
470
        'status'          => ['Type' => "tinyint(2) NOT NULL default '" . _WFDOWNLOADS_STATUS_WAITING . "'", 'Default' => true],
471
        'date'            => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
472
        'hits'            => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
473
        'rating'          => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true],
474
        'votes'           => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
475
        'comments'        => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
476
        'license'         => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
477
        'mirror'          => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
478
        'price'           => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true],
479
        'paypalemail'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
480
        'features'        => ['Type' => 'text NULL', 'Default' => false],
481
        'requirements'    => ['Type' => 'text NULL', 'Default' => false],
482
        'homepagetitle'   => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
483
        'forumid'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
484
        'limitations'     => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true],
485
        'versiontypes'    => ['Type' => "varchar(255) NOT NULL default 'None'", 'Default' => true],
486
        'dhistory'        => ['Type' => 'text NULL', 'Default' => false],
487
        'published'       => ['Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true],
488
        'expired'         => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
489
        'updated'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
490
        'offline'         => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
491
        'description'     => ['Type' => 'text NULL', 'Default' => false],
492
        'ipaddress'       => ['Type' => "varchar(120) NOT NULL default '0'", 'Default' => true],
493
        'notifypub'       => ['Type' => "int(1) NOT NULL default '0'", 'Default' => true],
494
        'summary'         => ['Type' => 'text NULL', 'Default' => false],
495
        'formulize_idreq' => ['Type' => "int(5) NOT NULL default '0'", 'Default' => true],
496
    ];
497
    $renamed_fields  = [
498
        'logourl' => 'screenshot',
499
    ];
500
    echo "<br><span style='font-weight: bold;'>Checking Download table</span><br>";
501
    $downloadHandler = $helper->getHandler('Download');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
502
    $download_table  = new Wfdownloads\DbupdaterTable('wfdownloads_downloads');
503
    $fields          = get_table_info($downloadHandler->table, $download_fields);
504
    // check for renamed fields
505
    rename_fields($download_table, $renamed_fields, $fields, $download_fields);
506
    update_table($download_fields, $fields, $download_table);
507
    if ($dbupdater->updateTable($download_table)) {
508
        echo 'Downloads table updated<br>';
509
    }
510
    unset($fields);
511
512
    // update wfdownloads_mod table
513
    $mod_fields     = [
514
        'requestid' => ['Type' => 'int(11) NOT NULL auto_increment', 'Default' => false],
515
516
        'modifysubmitter' => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
517
        'requestdate'     => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
518
519
        'lid'             => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
520
        'cid'             => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true],
521
        'title'           => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
522
        'url'             => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
523
        'filename'        => ['Type' => "varchar(150) NOT NULL default ''", 'Default' => true],
524
        'filetype'        => ['Type' => "varchar(100) NOT NULL default ''", 'Default' => true],
525
        'homepage'        => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
526
        'version'         => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true],
527
        'size'            => ['Type' => "int(8) NOT NULL default '0'", 'Default' => true],
528
        'platform'        => ['Type' => "varchar(50) NOT NULL default ''", 'Default' => true],
529
        'screenshot'      => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
530
        'screenshot2'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
531
        'screenshot3'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
532
        'screenshot4'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
533
        'submitter'       => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
534
        'publisher'       => ['Type' => 'text NULL', 'Default' => false],
535
        'status'          => ['Type' => "tinyint(2) NOT NULL default '" . _WFDOWNLOADS_STATUS_WAITING . "'", 'Default' => true],
536
        'date'            => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
537
        'hits'            => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
538
        'rating'          => ['Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true],
539
        'votes'           => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
540
        'comments'        => ['Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true],
541
        'license'         => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
542
        'mirror'          => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
543
        'price'           => ['Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true],
544
        'paypalemail'     => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
545
        'features'        => ['Type' => 'text NULL', 'Default' => false],
546
        'requirements'    => ['Type' => 'text NULL', 'Default' => false],
547
        'homepagetitle'   => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
548
        'forumid'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
549
        'limitations'     => ['Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true],
550
        'versiontypes'    => ['Type' => "varchar(255) NOT NULL default 'None'", 'Default' => true],
551
        'dhistory'        => ['Type' => 'text NULL', 'Default' => false],
552
        'published'       => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
553
        'expired'         => ['Type' => "int(10) NOT NULL default '0'", 'Default' => true],
554
        'updated'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
555
        'offline'         => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
556
        'summary'         => ['Type' => 'text NULL', 'Default' => false],
557
        'description'     => ['Type' => 'text NULL', 'Default' => false],
558
        // ???
559
        'formulize_idreq' => ['Type' => "int(5) NOT NULL default '0'", 'Default' => true],
560
    ];
561
    $renamed_fields = [
562
        'logourl' => 'screenshot',
563
    ];
564
    echo "<br><span style='font-weight: bold;'>Checking Modified Downloads table</span><br>";
565
    $modificationHandler = $helper->getHandler('Modification');
566
    $mod_table           = new Wfdownloads\DbupdaterTable('wfdownloads_mod');
567
    $fields              = get_table_info($modificationHandler->table, $mod_fields);
568
    rename_fields($mod_table, $renamed_fields, $fields, $mod_fields);
569
    update_table($mod_fields, $fields, $mod_table);
570
    if ($dbupdater->updateTable($mod_table)) {
571
        echo 'Modified Downloads table updated <br>';
572
    }
573
    unset($fields);
574
575
    // update wfdownloads_cat table
576
    $cat_fields = [
577
        'cid'           => ['Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false],
578
        'pid'           => ['Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true],
579
        'title'         => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
580
        'imgurl'        => ['Type' => "varchar(255) NOT NULL default ''", 'Default' => true],
581
        'description'   => ['Type' => 'text NULL', 'Default' => true],
582
        'total'         => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
583
        'summary'       => ['Type' => 'text NULL', 'Default' => false],
584
        'spotlighttop'  => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
585
        'spotlighthis'  => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
586
        'dohtml'        => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
587
        'dosmiley'      => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
588
        'doxcode'       => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
589
        'doimage'       => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
590
        'dobr'          => ['Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true],
591
        'weight'        => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
592
        'formulize_fid' => ['Type' => "int(5) NOT NULL default '0'", 'Default' => true],
593
    ];
594
    echo "<br><span style='font-weight: bold;'>Checking Category table</span><br>";
595
    $categoriesHandler = $helper->getHandler('Category');
596
    $cat_table         = new Wfdownloads\DbupdaterTable('wfdownloads_cat');
597
    $fields            = get_table_info($categoriesHandler->table, $cat_fields);
598
    update_table($cat_fields, $fields, $cat_table);
599
    if ($dbupdater->updateTable($cat_table)) {
600
        echo 'Category table updated<br>';
601
    }
602
    unset($fields);
603
604
    // update wfdownloads_broken table
605
    $broken_fields = [
606
        'reportid'     => ['Type' => 'int(5) NOT NULL auto_increment', 'Default' => false],
607
        'lid'          => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
608
        'sender'       => ['Type' => "int(11) NOT NULL default '0'", 'Default' => true],
609
        'ip'           => ['Type' => "varchar(20) NOT NULL default ''", 'Default' => true],
610
        'date'         => ['Type' => "varchar(11) NOT NULL default '0'", 'Default' => true],
611
        'confirmed'    => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
612
        'acknowledged' => ['Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true],
613
    ];
614
    echo "<br><span style='font-weight: bold;'>Checking Broken Report table</span><br>";
615
    $brokenHandler = $helper->getHandler('Report');
616
    $broken_table  = new Wfdownloads\DbupdaterTable('wfdownloads_broken');
617
    $fields        = get_table_info($brokenHandler->table, $broken_fields);
618
    update_table($broken_fields, $fields, $broken_table);
619
    if ($dbupdater->updateTable($broken_table)) {
620
        echo 'Broken Reports table updated<br>';
621
    }
622
    unset($fields);
623
}
624
625
// =========================================================================================
626
// we are going to change the names for the fields like nohtml, nosmilies, noxcode, noimage, nobreak in
627
// the wfdownloads_cat table into dohtml, dosmilies and so on.  Therefore the logic will change
628
// 0=yes  1=no and the currently stored value need to be changed accordingly
629
// =========================================================================================
630
/**
631
 * @return array|bool
632
 */
633
function invert_nohtm_dohtml_values()
634
{
635
    $ret               = [];
636
    $categoriesHandler = $helper->getHandler('Category');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
637
    $result            = $GLOBALS['xoopsDB']->query('SHOW COLUMNS FROM ' . $categoriesHandler->table);
638
    while (false !== ($existing_field = $GLOBALS['xoopsDB']->fetchArray($result))) {
639
        $fields[$existing_field['Field']] = $existing_field['Type'];
640
    }
641
    if (array_key_exists('nohtml', $fields)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fields does not seem to be defined for all execution paths leading up to this point.
Loading history...
642
        $dbupdater = new Wfdownloads\Dbupdater();
643
        //Invert column values
644
        // alter options in wfdownloads_cat
645
        $table = new Wfdownloads\DbupdaterTable('wfdownloads_cat');
646
        $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'");
647
        $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'");
648
        $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'");
649
        $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'");
650
        $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'");
651
652
        //inverting values no=1 <=> do=0
653
        // have to store teporarly as value = 2 to
654
        // avoid putting everithing to same value
655
        // if you change 1 to 0, then 0 to one,
656
        // every value will be 1, follow me?
657
        $table->addUpdatedWhere('dohtml', 2, '=1');
658
        $table->addUpdatedWhere('dohtml', 1, '=0');
659
        $table->addUpdatedWhere('dohtml', 0, '=2');
660
661
        $table->addUpdatedWhere('dosmiley', 2, '=1');
662
        $table->addUpdatedWhere('dosmiley', 1, '=0');
663
        $table->addUpdatedWhere('dosmiley', 0, '=2');
664
665
        $table->addUpdatedWhere('doxcode', 2, '=1');
666
        $table->addUpdatedWhere('doxcode', 1, '=0');
667
        $table->addUpdatedWhere('doxcode', 0, '=2');
668
669
        $table->addUpdatedWhere('doimage', 2, '=1');
670
        $table->addUpdatedWhere('doimage', 1, '=0');
671
        $table->addUpdatedWhere('doimage', 0, '=2');
672
        $ret = $dbupdater->updateTable($table);
673
    }
674
675
    return $ret;
676
}
677
678
/**
679
 * Updates a table by comparing correct fields with existing ones
680
 *
681
 * @param array                      $new_fields
682
 * @param array                      $existing_fields
683
 * @param Wfdownloads\DbupdaterTable $table
684
 */
685
function update_table($new_fields, $existing_fields, Wfdownloads\DbupdaterTable $table)
686
{
687
    foreach ($new_fields as $field => $fieldinfo) {
688
        $type = $fieldinfo['Type'];
689
        if (!array_key_exists($field, $existing_fields)) {
690
            //Add field as it is missing
691
            $table->addNewField($field, $type);
692
            //$GLOBALS['xoopsDB']->query("ALTER TABLE " . $table . " ADD " . $field . " " . $type);
693
            //echo $field . "(" . $type . ") <FONT COLOR='##22DD51'>Added</FONT><br>";
694
        } elseif ($existing_fields[$field] != $type) {
695
            $table->addAlteredField($field, $field . ' ' . $type);
696
            // check $fields[$field]['type'] for things like "int(10) unsigned"
697
            //$GLOBALS['xoopsDB']->query("ALTER TABLE " . $table . " CHANGE " . $field . " " . $field . " " . $type);
698
            //echo $field . " <FONT COLOR='#FF6600'>Changed to</FONT> " . $type . "<br>";
699
        }
700
        //echo $field . " <FONT COLOR='#0033FF'>Uptodate</FONT><br>";
701
    }
702
}
703
704
/**
705
 * Get column information for a table - we'll need to send along an array of fields to determine
706
 * whether the "Default" index value should be appended
707
 *
708
 * @param string $table
709
 * @param array  $default_fields
710
 *
711
 * @return array
712
 */
713
function get_table_info($table, $default_fields)
714
{
715
    $result = $GLOBALS['xoopsDB']->query('SHOW COLUMNS FROM ' . $table);
716
    while (false !== ($existing_field = $GLOBALS['xoopsDB']->fetchArray($result))) {
717
        $fields[$existing_field['Field']] = $existing_field['Type'];
718
        if ('YES' !== $existing_field['Null']) {
719
            $fields[$existing_field['Field']] .= ' NOT NULL';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fields does not seem to be defined for all execution paths leading up to this point.
Loading history...
720
        }
721
        if ($existing_field['Extra']) {
722
            $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
723
        }
724
        if ($default_fields[$existing_field['Field']]['Default']) {
725
            $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
726
        }
727
    }
728
729
    return $fields;
730
}
731
732
/**
733
 * Renames fields in a table and updates the existing fields array to reflect it.
734
 *
735
 * @param Wfdownloads\DbupdaterTable $table
736
 * @param array                      $renamed_fields
737
 * @param array                      $fields
738
 * @param array                      $new_fields
739
 */
740
function rename_fields(Wfdownloads\DbupdaterTable $table, $renamed_fields, &$fields, $new_fields)
741
{
742
    foreach (array_keys($fields) as $field) {
743
        if (array_key_exists($field, $renamed_fields)) {
744
            $new_field_name = $renamed_fields[$field];
745
            $new_field_type = $new_fields[$new_field_name]['Type'];
746
            $table->addAltered($field, $new_field_name . ' ' . $new_field_type);
0 ignored issues
show
Bug introduced by
The method addAltered() does not exist on XoopsModules\Wfdownloads\DbupdaterTable. Did you maybe mean addAlteredField()? ( Ignorable by Annotation )

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

746
            $table->/** @scrutinizer ignore-call */ 
747
                    addAltered($field, $new_field_name . ' ' . $new_field_type);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
747
            //$GLOBALS['xoopsDB']->query("ALTER TABLE " . $table . " CHANGE " . $field . " " . $new_field_name . " " . $new_field_type);
748
            //echo $field." Renamed to ". $new_field_name . "<br>";
749
            $fields[$new_field_name] = $new_field_type;
750
        }
751
    }
752
    //return $fields;
753
}
754