Issues (411)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/import.php (3 issues)

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 Xmf\Module\Admin;
23
use Xmf\Request;
24
use XoopsModules\Wfdownloads\{
25
    DownloadHandler,
26
    Helper,
27
    Utility
28
};
29
/** @var Helper $helper */
30
/** @var Utility $utility */
31
/** @var DownloadHandler $downloadsHandler */
32
33
$currentFile = basename(__FILE__);
34
require_once __DIR__ . '/admin_header.php';
35
36
// Check directories
37
if (!is_dir($helper->getConfig('uploaddir'))) {
38
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_UPLOADDIRNOTEXISTS);
39
}
40
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir'))) {
41
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_MAINIMAGEDIRNOTEXISTS);
42
}
43
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots'))) {
44
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_SCREENSHOTSDIRNOTEXISTS);
45
}
46
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'))) {
47
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_CATIMAGEDIRNOTEXISTS);
48
}
49
50
$op = Request::getString('op', 'import.menu');
51
switch ($op) {
52
    case 'import.MyDownloads':
53
        $ok = Request::getBool('ok', false, 'POST');
54
        if (true === $ok) {
55
            // Import data from MyDownloads
56
            import_mydownloads_to_wfdownloads();
57
            // Downloads imported
58
            redirect_header($currentFile, 1, _AM_WFDOWNLOADS_IMPORT_IMPORT_OK);
59
        } else {
60
            Utility::getCpHeader();
61
            xoops_confirm(['op' => 'import.MyDownloads', 'ok' => true], $currentFile, _AM_WFDOWNLOADS_IMPORT_RUSURE);
62
            xoops_cp_footer();
63
        }
64
        break;
65
    case 'import.PD-Downloads':
66
        $ok = Request::getBool('ok', false, 'POST');
67
        if (true === $ok) {
68
            // Import data from PD-Downloads
69
            import_pddownloads_to_wfdownloads();
70
            echo _AM_WFDOWNLOADS_IMPORT_IMPORT_OK;
71
            xoops_cp_footer();
72
            // Downloads imported
73
            //redirect_header($currentFile, 1, _AM_WFDOWNLOADS_IMPORT_IMPORT_OK);
74
        } else {
75
            Utility::getCpHeader();
76
            xoops_confirm(['op' => 'import.PD-Downloads', 'ok' => true], $currentFile, _AM_WFDOWNLOADS_IMPORT_RUSURE);
77
            xoops_cp_footer();
78
        }
79
        break;
80
    case 'import.wmpownloads':
81
        $ok = Request::getBool('ok', false, 'POST');
82
        if (true === $ok) {
83
            // Import data from wmpownloads
84
            import_wmpdownloads_to_wfdownloads();
85
            echo _AM_WFDOWNLOADS_IMPORT_IMPORT_OK;
86
            xoops_cp_footer();
87
            // Downloads imported
88
            //redirect_header($currentFile, 1, _AM_WFDOWNLOADS_IMPORT_IMPORT_OK);
89
        } else {
90
            Utility::getCpHeader();
91
            xoops_confirm(['op' => 'import.wmpownloads', 'ok' => true], $currentFile, _AM_WFDOWNLOADS_IMPORT_RUSURE);
92
            xoops_cp_footer();
93
        }
94
        break;
95
    case 'import.wfd322':
96
        $ok = Request::getBool('ok', false, 'POST');
97
        if (true === $ok) {
98
            // Import data from wfd322
99
            Utility::getCpHeader();
100
            import_wfd_to_wfdownloads();
101
            echo _AM_WFDOWNLOADS_IMPORT_IMPORT_OK;
102
            xoops_cp_footer();
103
            // Downloads imported
104
            //redirect_header($currentFile, 1, _AM_WFDOWNLOADS_IMPORT_IMPORT_OK);
105
        } else {
106
            Utility::getCpHeader();
107
            xoops_confirm(['op' => 'import.wfd322', 'ok' => true], $currentFile, _AM_WFDOWNLOADS_IMPORT_RUSURE);
108
            xoops_cp_footer();
109
        }
110
        break;
111
    case 'import.TDMDownloads':
112
        $ok = Request::getBool('ok', false, 'POST');
113
        if (true === $ok) {
114
            // Import data from wfd322
115
            Utility::getCpHeader();
116
            import_tdmdownloads_to_wfdownloads();
117
            echo _AM_WFDOWNLOADS_IMPORT_IMPORT_OK;
118
            xoops_cp_footer();
119
            // Downloads imported
120
            //redirect_header($currentFile, 1, _AM_WFDOWNLOADS_IMPORT_IMPORT_OK);
121
        } else {
122
            Utility::getCpHeader();
123
            xoops_confirm(['op' => 'import.TDMDownloads', 'ok' => true], $currentFile, _AM_WFDOWNLOADS_IMPORT_RUSURE);
124
            xoops_cp_footer();
125
        }
126
        break;
127
    case 'import.menu':
128
    default:
129
        Utility::getCpHeader();
130
        $adminObject = Admin::getInstance();
131
        $adminObject->displayNavigation($currentFile);
132
133
        echo '<fieldset><legend>' . _AM_WFDOWNLOADS_IMPORT_INFORMATION . "</legend>\n";
134
        echo '<div>' . _AM_WFDOWNLOADS_IMPORT_INFORMATION_TEXT . "</div>\n";
135
        echo "</fieldset>\n";
136
137
        //ask what to do
138
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
139
140
        $form = new XoopsThemeForm(_AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'form', $_SERVER['REQUEST_URI']);
141
        // Avoid module to import form itself
142
        // Is wf-downloads installed?
143
        if ($helper->getModule()->dirname() !== 'wf' . 'downloads') {
144
            $got_options = false;
145
            if (Utility::checkModule('wf' . 'downloads')) { // don't modify, is for cloning
146
                $moduleVersion = round(Utility::checkModule('wf' . 'downloads') / 100, 2); // don't modify, is for cloning
147
                $button        = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_WFD . '<br>' . $moduleVersion, 'wmp_button', _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'submit');
148
                $button->setExtra("onclick='document.forms.form.op.value=\"import.wfd322\"'");
149
                $form->addElement($button);
150
                unset($button);
151
            } else {
152
                $label = new XoopsFormLabel(_AM_WFDOWNLOADS_IMPORT_WFD, _AM_WFDOWNLOADS_IMPORT_WFD_NOTFOUND);
153
                $form->addElement($label);
154
                unset($label);
155
            }
156
        }
157
        //Is MyDownloads installed?
158
        $got_options = false;
159
        if (Utility::checkModule('mydownloads')) {
160
            $moduleVersion = round(Utility::checkModule('mydownloads') / 100, 2);
161
            $button        = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_MYDOWNLOADS . '<br>' . $moduleVersion, 'myd_button', _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'submit');
162
            $button->setExtra("onclick='document.forms.form.op.value=\"import.MyDownloads\"'");
163
            $form->addElement($button);
164
            unset($button);
165
        } else {
166
            $label = new XoopsFormLabel(_AM_WFDOWNLOADS_IMPORT_MYDOWNLOADS, _AM_WFDOWNLOADS_IMPORT_MYDOWNLOADS_NOTFOUND);
167
            $form->addElement($label);
168
            unset($label);
169
        }
170
        //Is PD-Downloads installed?
171
        $got_options = false;
172
        if (Utility::checkModule('PDdownloads')) {
173
            $moduleVersion = round(Utility::checkModule('PDdownloads') / 100, 2);
174
            $button        = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_PDDOWNLOADS . '<br>' . $moduleVersion, 'pd_button', _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'submit');
175
            $button->setExtra("onclick='document.forms.form.op.value=\"import.PD-Downloads\"'");
176
            $form->addElement($button);
177
            unset($button);
178
        } else {
179
            $label = new XoopsFormLabel(_AM_WFDOWNLOADS_IMPORT_PDDOWNLOADS, _AM_WFDOWNLOADS_IMPORT_PDDOWNLOADS_NOTFOUND);
180
            $form->addElement($label);
181
            unset($label);
182
        }
183
        //Is wmpownloads installed?
184
        $got_options = false;
185
        if (Utility::checkModule('wmpdownloads')) {
186
            $moduleVersion = round(Utility::checkModule('wmpdownloads') / 100, 2);
187
            $button        = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_WMPOWNLOADS . '<br>' . $moduleVersion, 'wmp_button', _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'submit');
188
            $button->setExtra("onclick='document.forms.form.op.value=\"import.wmpownloads\"'");
189
            $form->addElement($button);
190
            unset($button);
191
        } else {
192
            $label = new XoopsFormLabel(_AM_WFDOWNLOADS_IMPORT_WMPOWNLOADS, _AM_WFDOWNLOADS_IMPORT_WMPOWNLOADS_NOTFOUND);
193
            $form->addElement($label);
194
            unset($label);
195
        }
196
        //Is TDMDownloads installed?
197
        $got_options = false;
198
        if (Utility::checkModule('tdmdownloads')) {
199
            $moduleVersion = round(Utility::checkModule('tdmdownloads') / 100, 2);
200
            $button        = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_TDMDOWNLOADS . '<br>' . $moduleVersion, 'wmp_button', _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, 'submit');
201
            $button->setExtra("onclick='document.forms.form.op.value=\"import.TDMDownloads\"'");
202
            $form->addElement($button);
203
            unset($button);
204
        } else {
205
            $label = new XoopsFormLabel(_AM_WFDOWNLOADS_IMPORT_TDMDOWNLOADS, _AM_WFDOWNLOADS_IMPORT_TDMDOWNLOADS_NOTFOUND);
206
            $form->addElement($label);
207
            unset($label);
208
        }
209
210
        $form->addElement(new XoopsFormHidden('op', 0));
211
        $form->display();
212
        require_once __DIR__ . '/admin_footer.php';
213
        break;
214
}
215
216
// ========================================================
217
// Conversion file for any version before WF-Downloads 3
218
// ========================================================
219
// This file contains 3 functions to do necessary updates either when
220
// converting from mydownloads to Wfdownloads or upgrading any
221
// 2.x version of Wfdownloads to version 3.
222
//
223
// Starting with WF-Downloads 3.00 we will have a different procedure
224
// since version information will be stored in the database of Wfdownloads
225
//
226
//      function import_wfd_to_wfdownloads
227
//         This one is needed to import data from WF-Downloads
228
//
229
//      function import_mydownloads_to_wfdownloads
230
//         This one is needed to import data from MyDownloads
231
//
232
//      function import_pddownloads_to_wfdownloads
233
//         This one is needed to import data from PDdownloads
234
//
235
//      function import_wmpdownloads_to_wfdownloads
236
//         This one is needed to import data from wmpdownloads
237
//
238
//      function import_tdmdownloads_to_wfdownloads
239
//         This one is needed to import data from TDMDownloads
240
//
241
// =========================================================================================
242
// This function imports data from WF-Downloads
243
// =========================================================================================
244
/**
245
 * @throws \Exception
246
 */
247
function import_wfd_to_wfdownloads()
248
{
249
    /** @var \XoopsModuleHandler $moduleHandler */
250
    $moduleHandler = xoops_getHandler('module');
251
    // Get destination module/handlers/configs
252
    $helper = Helper::getInstance();
253
254
    // Get source module/config
255
    $wfdDirname = 'wf' . 'downloads'; // don't modify, is for cloning
256
    $wfdModule  = $moduleHandler->getByDirname($wfdDirname);
257
    if (empty($wfdModuleConfig)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $wfdModuleConfig seems to never exist and therefore empty should always be true.
Loading history...
258
        /** @var \XoopsConfigHandler $configHandler */
259
        $configHandler   = xoops_getHandler('config');
260
        $wfdModuleConfig = $configHandler->getConfigsByCat(0, $wfdModule->mid());
261
    }
262
    $categoriesHandler = $helper->getHandler('Category');
0 ignored issues
show
The assignment to $categoriesHandler is dead and can be removed.
Loading history...
263
    $downloadsHandler = $helper->getHandler('Download');
264
265
    echo "<br><span style='font-weight: bold;'>Copying Files</span><br>";
266
267
    // Copy categories images/thumbnails
268
    if (!Utility::copyDir(XOOPS_ROOT_PATH . '/' . $wfdModuleConfig['catimage'], XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'))) {
269
        return false;
270
    }
271
    echo 'Copied categories images and thumbnails<br>';
272
273
    // Copy screenshots images/thumbnails
274
    if (!Utility::copyDir(XOOPS_ROOT_PATH . '/' . $wfdModuleConfig['screenshots'], XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots'))) {
275
        return false;
276
    }
277
    echo 'Copied downloads screenshots and thumbnails<br>';
278
279
    // Copy files
280
    $wfdDownloadObjs = $downloadsHandler->getObjects();
281
    $countCopied     = 0;
282
    $countNotCopied  = 0;
283
    foreach ($wfdDownloadObjs as $wfdDownloadObj) {
284
        if (Utility::copyFile($wfdModuleConfig['uploaddir'] . '/' . $wfdDownloadObj->getVar('filename'), $helper->getConfig('uploaddir') . '/' . $wfdDownloadObj->getVar('filename'))) {
285
            echo "<span style='color:green;'>" . $wfdModuleConfig['uploaddir'] . '/' . $wfdDownloadObj->getVar('filename') . ' copied</span><br>';
286
            ++$countCopied;
287
        } else {
288
            echo "<span style='color:red;'>ERROR copying:" . $wfdModuleConfig['uploaddir'] . '/' . $wfdDownloadObj->getVar('filename') . '</span><br>';
289
            ++$countNotCopied;
290
        }
291
    }
292
    echo 'Files copied: ' . $countCopied;
293
    echo '<br>';
294
    echo 'Files not copied: ' . $countNotCopied;
295
    echo '<br>';
296
    echo _AM_WFDOWNLOADS_IMPORT_IMPORTINGDATA;
297
    echo '<br>';
298
299
    $destination = [
300
        'cat'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_cat'),
301
        'downloads' => $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads'),
302
        'mirrors'   => $GLOBALS['xoopsDB']->prefix('wfdownloads_mirrors'),
303
        'reviews'   => $GLOBALS['xoopsDB']->prefix('wfdownloads_reviews'),
304
        'broken'    => $GLOBALS['xoopsDB']->prefix('wfdownloads_broken'),
305
        'mod'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_mod'),
306
        'votes'     => $GLOBALS['xoopsDB']->prefix('wfdownloads_votedata'),
307
    ];
308
309
    $source = [
310
        'cat'       => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_cat'), // don't modify, is for cloning
311
        'downloads' => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_downloads'), // don't modify, is for cloning
312
        'mirrors'   => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_mirrors'), // don't modify, is for cloning
313
        'reviews'   => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_reviews'), // don't modify, is for cloning
314
        'broken'    => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_broken'), // don't modify, is for cloning
315
        'mod'       => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_mod'), // don't modify, is for cloning
316
        'votes'     => $GLOBALS['xoopsDB']->prefix('wf' . 'downloads_votedata'),
317
    ]; // don't modify, is for cloning
318
319
    //Add temporary field to category table
320
    $GLOBALS['xoopsDB']->query("ALTER TABLE {$destination['cat']} ADD `old_cid` int NOT NULL default 0");
321
    $GLOBALS['xoopsDB']->query("ALTER TABLE {$destination['cat']} ADD `old_pid` int NOT NULL default 0");
322
    //Add temporary fields to downloads table
323
    $GLOBALS['xoopsDB']->query("ALTER TABLE {$destination['downloads']} ADD `old_lid` int NOT NULL default 0");
324
    $GLOBALS['xoopsDB']->query("ALTER TABLE {$destination['downloads']} ADD `old_cid` int NOT NULL default 0");
325
326
    //Get latest mirror ID to determine which records will need an updated lid value afterwards
327
    $result = $GLOBALS['xoopsDB']->query("SELECT MAX(mirror_id) FROM {$destination['mirrors']}");
328
    [$max_mirrorid] = $GLOBALS['xoopsDB']->fetchRow($result);
329
    //Get latest review ID to determine which records will need an updated lid value afterwards
330
    $result = $GLOBALS['xoopsDB']->query("SELECT MAX(review_id) FROM {$destination['reviews']}");
331
    [$max_reviewid] = $GLOBALS['xoopsDB']->fetchRow($result);
332
    //Get latest mod request ID to determine which records will need an updated lid value afterwards
333
    $result = $GLOBALS['xoopsDB']->query("SELECT MAX(requestid) FROM {$destination['mod']}");
334
    [$max_requestid] = $GLOBALS['xoopsDB']->fetchRow($result);
335
    //Get latest report ID to determine, which records will need an updated lid value afterwards
336
    $result = $GLOBALS['xoopsDB']->query("SELECT MAX(reportid) FROM {$destination['broken']}");
337
    [$max_reportid] = $GLOBALS['xoopsDB']->fetchRow($result);
338
    //Get latest vote ID to determine which records will need an updated lid value afterwards
339
    $result = $GLOBALS['xoopsDB']->query("SELECT MAX(ratingid) FROM {$destination['votes']}");
340
    [$max_ratingid] = $GLOBALS['xoopsDB']->fetchRow($result);
341
342
    //Import data into category table
343
    if (Utility::checkModule('wf' . 'downloads') >= 320) {
344
        $sql = "INSERT INTO {$destination['cat']} (";
345
        $sql .= ' `old_cid`, `old_pid`, `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`, `formulize_fid`';
346
        $sql .= ' ) SELECT ';
347
        $sql .= ' `cid`,     `pid`,     `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`, `formulize_fid`';
348
        $sql .= " FROM {$source['cat']}";
349
    } else {
350
        $sql = "INSERT INTO {$destination['cat']} (";
351
        $sql .= ' `old_cid`, `old_pid`, `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`';
352
        $sql .= ' ) SELECT ';
353
        $sql .= ' `cid`,     `pid`,     `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`';
354
        $sql .= " FROM {$source['cat']}";
355
    }
356
    $GLOBALS['xoopsDB']->query($sql);
357
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} categories into {$destination['cat']}<br>";
358
359
    //Import data into downloads table
360
    if (Utility::checkModule('wf' . 'downloads') >= 320) {
361
        $sql = "INSERT INTO {$destination['downloads']} (";
362
        $sql .= ' `cid`, `old_lid`, `old_cid`, `title`, `url`, `filename`, `filetype`, `homepage`, `version`, `size`, `platform`, `screenshot`, `screenshot2`, `screenshot3`, `screenshot4`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `license`, `mirror`, `price`, `paypalemail`, `features`, `requirements`, `homepagetitle`, `forumid`, `limitations`, `versiontypes`, `dhistory`, `published`, `expired`, `updated`, `offline`, `summary`, `description`, `ipaddress`, `notifypub`, `formulize_idreq`';
363
        $sql .= ' ) SELECT ';
364
        $sql .= ' 0,     `lid`,     `cid`,     `title`, `url`, `filename`, `filetype`, `homepage`, `version`, `size`, `platform`, `screenshot`, `screenshot2`, `screenshot3`, `screenshot4`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `license`, `mirror`, `price`, `paypalemail`, `features`, `requirements`, `homepagetitle`, `forumid`, `limitations`, `versiontypes`, `dhistory`, `published`, `expired`, `updated`, `offline`, `summary`, `description`, `ipaddress`, `notifypub`, `formulize_idreq`';
365
        $sql .= " FROM {$source['downloads']}";
366
    } else {
367
        $sql = "INSERT INTO {$destination['downloads']} (";
368
        $sql .= ' `cid`, `old_lid`, `old_cid`, `title`, `url`, `filename`, `filetype`, `homepage`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `license`, `mirror`, `price`, `paypalemail`, `features`, `requirements`, `homepagetitle`, `forumid`, `limitations`, `dhistory`, `published`, `expired`, `updated`, `offline`, `summary`, `description`, `ipaddress`, `notifypub`';
369
        $sql .= ' ) SELECT ';
370
        $sql .= ' 0,     `lid`,     `cid`,     `title`, `url`, `filename`, `filetype`, `homepage`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `license`, `mirror`, `price`, `paypalemail`, `features`, `requirements`, `homepagetitle`, `forumid`, `limitations`, `dhistory`, `published`, `expired`, `updated`, `offline`, `summary`, `description`, `ipaddress`, `notifypub`';
371
        $sql .= " FROM {$source['downloads']}";
372
    }
373
    $GLOBALS['xoopsDB']->query($sql);
374
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} downloads into {$destination['downloads']}<br>";
375
    // IN PROGRESS
376
    // IN PROGRESS IMPORT AND UPDATE SCREENSHOTS
377
    // IN PROGRESS
378
379
    //Import data into mirrors table
380
    $sql = "INSERT INTO {$destination['mirrors']} (";
381
    $sql .= ' `lid`, `title`, `homeurl`, `location`, `continent`, `downurl`, `submit`, `date`, `uid`';
382
    $sql .= ' ) SELECT';
383
    $sql .= ' `lid`, `title`, `homeurl`, `location`, `continent`, `downurl`, `submit`, `date`, `uid`';
384
    $sql .= " FROM {$source['mirrors']}";
385
    $GLOBALS['xoopsDB']->query($sql);
386
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} mirrors into {$destination['mirrors']}<br>";
387
388
    //Import data into reviews table
389
    if (Utility::checkModule('wf' . 'downloads') >= 320) {
390
        $sql = "INSERT INTO {$destination['reviews']} (";
391
        $sql .= ' `lid`, `title`, `review`, `submit`, `date`, `uid`, `rate`';
392
        $sql .= ' ) SELECT';
393
        $sql .= ' `lid`, `title`, `review`, `submit`, `date`, `uid`, `rate`';
394
        $sql .= " FROM {$source['reviews']}";
395
    } else {
396
        $sql = "INSERT INTO {$destination['reviews']} (";
397
        $sql .= ' `lid`, `title`, `review`, `submit`, `date`, `uid`';
398
        $sql .= ' ) SELECT';
399
        $sql .= ' `lid`, `title`, `review`, `submit`, `date`, `uid`';
400
        $sql .= " FROM {$source['reviews']}";
401
    }
402
    $GLOBALS['xoopsDB']->query($sql);
403
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} reviews into {$destination['reviews']}<br>";
404
405
    //Import data into brokens table
406
    $sql = "INSERT INTO {$destination['broken']} (";
407
    $sql .= ' `lid`, `sender`, `date`, `ip`';
408
    $sql .= ' ) SELECT';
409
    $sql .= ' `lid`, `sender`, `date`, `ip`';
410
    $sql .= " FROM {$source['broken']}";
411
    $GLOBALS['xoopsDB']->query($sql);
412
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} broken reports into {$destination['broken']}<br>";
413
414
    //Import data into votedata table
415
    $sql = "INSERT INTO {$destination['votes']} (";
416
    $sql .= ' `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`';
417
    $sql .= ' ) SELECT';
418
    $sql .= ' `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`';
419
    $sql .= " FROM {$source['votes']}";
420
    $GLOBALS['xoopsDB']->query($sql);
421
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} votes into {$destination['votes']}<br>";
422
423
    //Import data into mod request table
424
    $sql = "INSERT INTO {$destination['mod']} (";
425
    $sql .= ' `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`)';
426
    $sql .= ' SELECT';
427
    $sql .= ' `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`';
428
    $sql .= " FROM {$source['mod']}";
429
    $GLOBALS['xoopsDB']->query($sql);
430
    echo "Imported {$GLOBALS['xoopsDB']->getAffectedRows()} modification requests into {$destination['mod']}<br>";
431
432
    // Update category ID to new value
433
    $GLOBALS['xoopsDB']->query("UPDATE {$destination['downloads']} d, {$destination['cat']} c SET d.cid=c.cid WHERE d.old_cid=c.old_cid AND d.old_cid != 0");
434
    $GLOBALS['xoopsDB']->query("UPDATE {$destination['cat']} c1, {$destination['cat']} c2 SET c1.pid=c2.cid WHERE c1.old_pid=c2.old_cid AND c1.old_pid != 0");
435
    // Update lid values in mod table
436
    if ($max_requestid) {
437
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['mod']} m, {$destination['cat']} c SET m.cid=c.cid WHERE m.requestid > {$max_requestid} AND c.old_cid=m.cid");
438
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['mod']} m, {$destination['downloads']} d SET m.lid=d.lid WHERE m.requestid > {$max_requestid} AND m.lid=d.old_lid");
439
    }
440
    // Update lid values in mirrors table
441
    if ($max_mirrorid) {
442
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['mirrors']} v, {$destination['downloads']} d SET v.lid=d.lid WHERE v.mirror_id > {$max_mirrorid} AND v.lid=d.old_lid");
443
    }
444
    // Update lid values in reviews table
445
    if ($max_reviewid) {
446
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['reviews']} v, {$destination['downloads']} d SET v.lid=d.lid WHERE v.review_id > {$max_reviewid} AND v.lid=d.old_lid");
447
    }
448
    // Update lid values in votedata table
449
    if ($max_ratingid) {
450
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['votes']} v, {$destination['downloads']} d SET v.lid=d.lid WHERE v.ratingid > {$max_ratingid} AND v.lid=d.old_lid");
451
    }
452
    // Update lid values in broken table
453
    if ($max_reportid) {
454
        $GLOBALS['xoopsDB']->query("UPDATE {$destination['broken']} b, {$destination['downloads']} d SET b.lid=d.lid WHERE b.reportid > {$max_reportid} AND b.lid=d.old_lid");
455
    }
456
457
    //Remove temporary fields
458
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' DROP `old_cid`');
459
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' DROP `old_pid`');
460
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['downloads'] . ' DROP `old_cid`');
461
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['downloads'] . ' DROP `old_lid`');
462
463
    return null;
464
}
465
466
// =========================================================================================
467
// This function imports data from mydownloads
468
// =========================================================================================
469
function import_wmpdownloads_to_wfdownloads()
470
{
471
    echo '<br>';
472
    echo _AM_WFDOWNLOADS_IMPORT_IMPORTINGDATA;
473
    echo '<br>';
474
475
    $destination = [
476
        'cat'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_cat'),
477
        'downloads' => $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads'),
478
        'broken'    => $GLOBALS['xoopsDB']->prefix('wfdownloads_broken'),
479
        'mod'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_mod'),
480
        'votes'     => $GLOBALS['xoopsDB']->prefix('wfdownloads_votedata'),
481
    ];
482
483
    $source = [
484
        'cat'       => $GLOBALS['xoopsDB']->prefix('wmpdownloads_cat'),
485
        'downloads' => $GLOBALS['xoopsDB']->prefix('wmpdownloads_downloads'),
486
        'broken'    => $GLOBALS['xoopsDB']->prefix('wmpdownloads_broken'),
487
        'mod'       => $GLOBALS['xoopsDB']->prefix('wmpdownloads_mod'),
488
        'votes'     => $GLOBALS['xoopsDB']->prefix('wmpdownloads_votedata'),
489
        'text'      => $GLOBALS['xoopsDB']->prefix('wmpdownloads_text'),
490
    ];
491
492
    //Add temporary field to category table
493
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_cid` INT NOT NULL DEFAULT 0');
494
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_pid` INT NOT NULL DEFAULT 0');
495
496
    //Add temporary fields to downloads table
497
    $GLOBALS['xoopsDB']->query(
498
        'ALTER TABLE ' . $destination['downloads'] . ' ADD `old_lid` INT NOT NULL DEFAULT 0,
499
                                                               ADD `old_cid` INT NOT NULL DEFAULT 0'
500
    );
501
502
    //Get latest mod request ID to determine which records will need an updated lid value afterwards
503
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(requestid) FROM ' . $destination['mod']);
504
    [$max_requestid] = $GLOBALS['xoopsDB']->fetchRow($result);
505
    //Get latest report ID to determine, which records will need an updated lid value afterwards
506
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(reportid) FROM ' . $destination['broken']);
507
    [$max_reportid] = $GLOBALS['xoopsDB']->fetchRow($result);
508
    //Get latest vote ID to determine which records will need an updated lid value afterwards
509
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(ratingid) FROM ' . $destination['votes']);
510
    [$max_ratingid] = $GLOBALS['xoopsDB']->fetchRow($result);
511
512
    //Import data into category table
513
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['cat'] . ' (`old_cid`, `old_pid`, `title`, `imgurl`, `summary`)' . " SELECT `cid`, `pid`, `title`, `imgurl`, ''" . ' FROM ' . $source['cat']);
514
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' categories into ' . $destination['cat'] . '<br>';
515
    //Import data into downloads table
516
    $GLOBALS['xoopsDB']->query(
517
        'INSERT'
518
        . ' INTO '
519
        . $destination['downloads']
520
        . ' (`cid`, `old_lid`, `old_cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `submitter`, `status`, `published`, `hits`, `rating`, `votes`, `comments`, `features`, `requirements`, `dhistory`, `summary`, `description`)'
521
        . " SELECT 0,`lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `submitter`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, '', '','','', ''"
522
        . ' FROM '
523
        . $source['downloads']
524
    );
525
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' downloads into ' . $destination['downloads'] . '<br>';
526
    //Import data into brokens table
527
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['broken'] . ' (`lid`, `sender`, `ip`)' . ' SELECT `lid`, `sender`, `ip`' . ' FROM ' . $source['broken']);
528
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' broken reports into ' . $destination['broken'] . '<br>';
529
    //Import data into votedata table
530
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['votes'] . ' (`lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`)' . 'SELECT `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`' . ' FROM ' . $source['votes']);
531
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' votes into ' . $destination['votes'] . '<br>';
532
    //Import data into mod request table
533
    $GLOBALS['xoopsDB']->query(
534
        'INSERT INTO '
535
        . $destination['mod']
536
        . ' (`lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`,`features`, `requirements`, `publisher`, `dhistory`, `summary`)'
537
        . " SELECT `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `description`, `modifysubmitter`,'','','','',''"
538
        . ' FROM '
539
        . $source['mod']
540
    );
541
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' modification requests into ' . $destination['mod'] . '<br>';
542
543
    //Update category ID to new value
544
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $destination['cat'] . ' c SET d.cid=c.cid' . ' WHERE d.old_cid=c.old_cid AND d.old_cid != 0');
545
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['cat'] . ' c1, ' . $destination['cat'] . ' c2 SET c1.pid=c2.cid' . ' WHERE c1.old_pid=c2.old_cid AND c1.old_pid != 0');
546
    if ($max_requestid) {
547
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['cat'] . ' c SET m.cid=c.cid' . ' WHERE m.requestid > ' . $max_requestid . ' AND c.old_cid=m.cid');
548
        //Update lid values in mod table
549
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['downloads'] . ' d SET m.lid=d.lid' . ' WHERE m.requestid > ' . $max_requestid . ' AND m.lid=d.old_lid');
550
    }
551
    if ($max_ratingid) {
552
        //Update lid values in votedata table
553
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['votes'] . ' v, ' . $destination['downloads'] . ' d SET v.lid=d.lid' . ' WHERE v.ratingid > ' . $max_ratingid . ' AND v.lid=d.old_lid');
554
    }
555
    if ($max_reportid) {
556
        //Update lid values in brokens table
557
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['broken'] . ' b, ' . $destination['downloads'] . ' d SET b.lid=d.lid' . ' WHERE b.reportid > ' . $max_reportid . ' AND b.lid=d.old_lid');
558
    }
559
    //Update description
560
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $source['text'] . ' t SET d.description=t.description' . ' WHERE t.lid=d.old_lid');
561
562
    //Remove temporary fields
563
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_cid`');
564
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_pid`');
565
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_cid`');
566
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_lid`');
567
}
568
569
// =========================================================================================
570
// This function imports data from pd-downloads
571
// =========================================================================================
572
function import_pddownloads_to_wfdownloads()
573
{
574
    echo '<br>';
575
    echo _AM_WFDOWNLOADS_IMPORT_IMPORTINGDATA;
576
    echo '<br>';
577
578
    $destination = [
579
        'cat'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_cat'),
580
        'downloads' => $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads'),
581
        'broken'    => $GLOBALS['xoopsDB']->prefix('wfdownloads_broken'),
582
        'mod'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_mod'),
583
        'votes'     => $GLOBALS['xoopsDB']->prefix('wfdownloads_votedata'),
584
    ];
585
586
    $source = [
587
        'cat'       => $GLOBALS['xoopsDB']->prefix('PDdownloads_cat'),
588
        'downloads' => $GLOBALS['xoopsDB']->prefix('PDdownloads_downloads'),
589
        'broken'    => $GLOBALS['xoopsDB']->prefix('PDdownloads_broken'),
590
        'mod'       => $GLOBALS['xoopsDB']->prefix('PDdownloads_mod'),
591
        'votes'     => $GLOBALS['xoopsDB']->prefix('PDdownloads_votedata'),
592
    ];
593
594
    //Add temporary field to category table
595
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_cid` INT NOT NULL DEFAULT 0');
596
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_pid` INT NOT NULL DEFAULT 0');
597
598
    //Add temporary fields to downloads table
599
    $GLOBALS['xoopsDB']->query(
600
        'ALTER TABLE ' . $destination['downloads'] . ' ADD `old_lid` INT NOT NULL DEFAULT 0,
601
                                                               ADD `old_cid` INT NOT NULL DEFAULT 0'
602
    );
603
604
    //Get latest mod request ID to determine which records will need an updated lid value afterwards
605
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(requestid) FROM ' . $destination['mod']);
606
    [$max_requestid] = $GLOBALS['xoopsDB']->fetchRow($result);
607
    //Get latest report ID to determine, which records will need an updated lid value afterwards
608
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(reportid) FROM ' . $destination['broken']);
609
    [$max_reportid] = $GLOBALS['xoopsDB']->fetchRow($result);
610
    //Get latest vote ID to determine which records will need an updated lid value afterwards
611
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(ratingid) FROM ' . $destination['votes']);
612
    [$max_ratingid] = $GLOBALS['xoopsDB']->fetchRow($result);
613
614
    //Import data into category table
615
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['cat'] . ' (`old_cid`, `old_pid`, `title`, `imgurl`, `description`, `total`, `weight`)' . ' SELECT `cid`, `pid`, `title`, `imgurl`, `description`, `total`, `weight`' . ' FROM ' . $source['cat']);
616
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' categories into ' . $destination['cat'] . '<br>';
617
    //Import data into downloads table
618
    $GLOBALS['xoopsDB']->query(
619
        'INSERT INTO '
620
        . $destination['downloads']
621
        . ' (`cid`, `old_lid`, `old_cid`, `title`, `url`, `homepage`, `homepagetitle`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `features`, `forumid`, `dhistory`, `published`, `expired`, `updated`, `offline`, `description`, `ipaddress`, `notifypub`)'
622
        . ' SELECT 0,`lid`, `cid`, `title`, `url`, `homepage`, `homepagetitle`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `features`, `forumid`, `dhistory`, `published`, `expired`, `updated`, `offline`, `description`, `ipaddress`, `notifypub`'
623
        . ' FROM '
624
        . $source['downloads']
625
    );
626
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' downloads into ' . $destination['downloads'] . '<br>';
627
    //Import data into brokens table
628
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['broken'] . ' (`reportid`, `lid`, `sender`, `ip`, `date`, `confirmed`, `acknowledged`)' . ' SELECT `reportid`, `lid`, `sender`, `ip`, `date`, `confirmed`, `acknowledged`' . ' FROM ' . $source['broken']);
629
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' broken reports into ' . $destination['broken'] . '<br>';
630
    //Import data into votedata table
631
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['votes'] . ' (`ratingid`, `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`)' . ' SELECT `ratingid`, `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`' . ' FROM ' . $source['votes']);
632
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' votes into ' . $destination['votes'] . '<br>';
633
    //Import data into mod request table
634
    $GLOBALS['xoopsDB']->query(
635
        'INSERT INTO '
636
        . $destination['mod']
637
        . ' (`lid`, `cid`, `title`, `url`, `homepage`, `homepagetitle`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `features`, `forumid`, `dhistory`, `published`, `expired`, `updated`, `offline`, `description`, `modifysubmitter`, `requestdate`)'
638
        . ' SELECT `lid`, `cid`, `title`, `url`, `homepage`, `homepagetitle`, `version`, `size`, `platform`, `screenshot`, `submitter`, `publisher`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, `features`, `forumid`, `dhistory`, `published`, `expired`, `updated`, `offline`, `description`, `modifysubmitter`, `requestdate`'
639
        . ' FROM '
640
        . $source['mod']
641
    );
642
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' modification requests into ' . $destination['mod'] . '<br>';
643
644
    //Update category ID to new value
645
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $destination['cat'] . ' c SET d.cid=c.cid' . ' WHERE d.old_cid=c.old_cid AND d.old_cid != 0');
646
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['cat'] . ' c1, ' . $destination['cat'] . ' c2 SET c1.pid=c2.cid' . ' WHERE c1.old_pid=c2.old_cid AND c1.old_pid != 0');
647
    if ($max_requestid) {
648
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['cat'] . ' c SET m.cid=c.cid' . ' WHERE m.requestid > ' . $max_requestid . ' AND c.old_cid=m.cid');
649
        //Update lid values in mod table
650
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['downloads'] . ' d SET m.lid=d.lid' . ' WHERE m.requestid > ' . $max_requestid . ' AND m.lid=d.old_lid');
651
    }
652
    if ($max_ratingid) {
653
        //Update lid values in votedata table
654
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['votes'] . ' v, ' . $destination['downloads'] . ' d SET v.lid=d.lid' . ' WHERE v.ratingid > ' . $max_ratingid . ' AND v.lid=d.old_lid');
655
    }
656
    if ($max_reportid) {
657
        //Update lid values in brokens table
658
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['broken'] . ' b, ' . $destination['downloads'] . ' d SET b.lid=d.lid' . ' WHERE b.reportid > ' . $max_reportid . ' AND b.lid=d.old_lid');
659
    }
660
661
    //Remove temporary fields
662
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_cid`');
663
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_pid`');
664
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_cid`');
665
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_lid`');
666
}
667
668
// =========================================================================================
669
// This function imports data from mydownloads
670
// =========================================================================================
671
function import_mydownloads_to_wfdownloads()
672
{
673
    echo '<br>';
674
    echo _AM_WFDOWNLOADS_IMPORT_IMPORTINGDATA;
675
    echo '<br>';
676
677
    $destination = [
678
        'cat'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_cat'),
679
        'downloads' => $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads'),
680
        'broken'    => $GLOBALS['xoopsDB']->prefix('wfdownloads_broken'),
681
        'mod'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_mod'),
682
        'votes'     => $GLOBALS['xoopsDB']->prefix('wfdownloads_votedata'),
683
    ];
684
685
    $source = [
686
        'cat'       => $GLOBALS['xoopsDB']->prefix('mydownloads_cat'),
687
        'downloads' => $GLOBALS['xoopsDB']->prefix('mydownloads_downloads'),
688
        'broken'    => $GLOBALS['xoopsDB']->prefix('mydownloads_broken'),
689
        'mod'       => $GLOBALS['xoopsDB']->prefix('mydownloads_mod'),
690
        'votes'     => $GLOBALS['xoopsDB']->prefix('mydownloads_votedata'),
691
        'text'      => $GLOBALS['xoopsDB']->prefix('mydownloads_text'),
692
    ];
693
694
    //Add temporary field to category table
695
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_cid` INT NOT NULL DEFAULT 0');
696
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_pid` INT NOT NULL DEFAULT 0');
697
698
    //Add temporary fields to downloads table
699
    $GLOBALS['xoopsDB']->query(
700
        'ALTER TABLE ' . $destination['downloads'] . ' ADD `old_lid` INT NOT NULL DEFAULT 0,
701
                                                               ADD `old_cid` INT NOT NULL DEFAULT 0'
702
    );
703
704
    //Get latest mod request ID to determine which records will need an updated lid value afterwards
705
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(requestid) FROM ' . $destination['mod']);
706
    [$max_requestid] = $GLOBALS['xoopsDB']->fetchRow($result);
707
    //Get latest report ID to determine, which records will need an updated lid value afterwards
708
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(reportid) FROM ' . $destination['broken']);
709
    [$max_reportid] = $GLOBALS['xoopsDB']->fetchRow($result);
710
    //Get latest vote ID to determine which records will need an updated lid value afterwards
711
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(ratingid) FROM ' . $destination['votes']);
712
    [$max_ratingid] = $GLOBALS['xoopsDB']->fetchRow($result);
713
714
    //Import data into category table
715
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['cat'] . ' (`old_cid`, `old_pid`, `title`, `imgurl`, `summary`)' . " SELECT `cid`, `pid`, `title`, `imgurl`, ''" . ' FROM ' . $source['cat']);
716
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' categories into ' . $destination['cat'] . '<br>';
717
    //Import data into downloads table
718
    $GLOBALS['xoopsDB']->query(
719
        'INSERT INTO '
720
        . $destination['downloads']
721
        . ' (`cid`, `old_lid`, `old_cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `submitter`, `status`, `published`, `hits`, `rating`, `votes`, `comments`, `features`, `requirements`, `dhistory`, `summary`, `description`)'
722
        . " SELECT 0,`lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `submitter`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, '', '','','', ''"
723
        . ' FROM '
724
        . $source['downloads']
725
    );
726
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' downloads into ' . $destination['downloads'] . '<br>';
727
    //Import data into brokens table
728
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['broken'] . ' (`lid`, `sender`, `ip`)' . ' SELECT `lid`, `sender`, `ip`' . ' FROM ' . $source['broken']);
729
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' broken reports into ' . $destination['broken'] . '<br>';
730
    //Import data into votedata table
731
    $GLOBALS['xoopsDB']->query('INSERT INTO ' . $destination['votes'] . ' (`lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`)' . ' SELECT `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`' . ' FROM ' . $source['votes']);
732
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' votes into ' . $destination['votes'] . '<br>';
733
    //Import data into mod request table
734
    $GLOBALS['xoopsDB']->query(
735
        'INSERT INTO '
736
        . $destination['mod']
737
        . ' (`lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`,`features`, `requirements`, `publisher`, `dhistory`, `summary`)'
738
        . " SELECT `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `description`, `modifysubmitter`,'','','','',''"
739
        . ' FROM '
740
        . $source['mod']
741
    );
742
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' modification requests into ' . $destination['mod'] . '<br>';
743
744
    //Update category ID to new value
745
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $destination['cat'] . ' c SET d.cid=c.cid' . ' WHERE d.old_cid=c.old_cid AND d.old_cid != 0');
746
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['cat'] . ' c1, ' . $destination['cat'] . ' c2 SET c1.pid=c2.cid' . ' WHERE c1.old_pid=c2.old_cid AND c1.old_pid != 0');
747
    if ($max_requestid) {
748
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['cat'] . ' c SET m.cid=c.cid' . ' WHERE m.requestid > ' . $max_requestid . ' AND c.old_cid=m.cid');
749
        //Update lid values in mod table
750
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['mod'] . ' m, ' . $destination['downloads'] . ' d SET m.lid=d.lid' . ' WHERE m.requestid > ' . $max_requestid . ' AND m.lid=d.old_lid');
751
    }
752
    if ($max_ratingid) {
753
        //Update lid values in votedata table
754
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['votes'] . ' v, ' . $destination['downloads'] . ' d SET v.lid=d.lid' . ' WHERE v.ratingid > ' . $max_ratingid . ' AND v.lid=d.old_lid');
755
    }
756
    if ($max_reportid) {
757
        //Update lid values in brokens table
758
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['broken'] . ' b, ' . $destination['downloads'] . ' d SET b.lid=d.lid' . ' WHERE b.reportid > ' . $max_reportid . ' AND b.lid=d.old_lid');
759
    }
760
    //Update description
761
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $source['text'] . ' t SET d.description=t.description' . ' WHERE t.lid=d.old_lid');
762
763
    //Remove temporary fields
764
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_cid`');
765
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_pid`');
766
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_cid`');
767
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_lid`');
768
}
769
770
// =========================================================================================
771
// This function imports data from TDMDownloads
772
// =========================================================================================
773
function import_tdmdownloads_to_wfdownloads()
774
{
775
    echo "<br><span style='font-weight: bold;'>Importing Data</span><br>";
776
    $destination = [
777
        'cat'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_cat'),
778
        'downloads' => $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads'),
779
        'broken'    => $GLOBALS['xoopsDB']->prefix('wfdownloads_broken'),
780
        'mod'       => $GLOBALS['xoopsDB']->prefix('wfdownloads_mod'),
781
        'votes'     => $GLOBALS['xoopsDB']->prefix('wfdownloads_votedata'),
782
    ];
783
784
    $source = [
785
        'cat'          => $GLOBALS['xoopsDB']->prefix('tdmdownloads_cat'),
786
        'downloads'    => $GLOBALS['xoopsDB']->prefix('tdmdownloads_downloads'),
787
        'broken'       => $GLOBALS['xoopsDB']->prefix('tdmdownloads_broken'),
788
        'mod'          => $GLOBALS['xoopsDB']->prefix('tdmdownloads_mod'),
789
        'votes'        => $GLOBALS['xoopsDB']->prefix('tdmdownloads_votedata'),
790
        'field'        => $GLOBALS['xoopsDB']->prefix('tdmdownloads_field'),
791
        'fielddata'    => $GLOBALS['xoopsDB']->prefix('tdmdownloads_fielddata'),
792
        'modfielddata' => $GLOBALS['xoopsDB']->prefix('tdmdownloads_modfielddata'),
793
        'downlimit'    => $GLOBALS['xoopsDB']->prefix('tdmdownloads_downlimit'),
794
    ];
795
796
    //Add temporary field to category table
797
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_cid` INT NOT NULL DEFAULT 0');
798
    $GLOBALS['xoopsDB']->query('ALTER TABLE ' . $destination['cat'] . ' ADD `old_pid` INT NOT NULL DEFAULT 0');
799
800
    //Add temporary fields to downloads table
801
    $GLOBALS['xoopsDB']->query(
802
        'ALTER TABLE ' . $destination['downloads'] . ' ADD `old_lid` INT NOT NULL DEFAULT 0,
803
                                                               ADD `old_cid` INT NOT NULL DEFAULT 0'
804
    );
805
806
    //Get latest mod request ID to determine which records will need an updated lid value afterwards
807
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(requestid) FROM ' . $destination['mod']);
808
    [$max_requestid] = $GLOBALS['xoopsDB']->fetchRow($result);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
809
    //Get latest report ID to determine, which records will need an updated lid value afterwards
810
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(reportid) FROM ' . $destination['broken']);
811
    [$max_reportid] = $GLOBALS['xoopsDB']->fetchRow($result);
812
    //Get latest vote ID to determine which records will need an updated lid value afterwards
813
    $result = $GLOBALS['xoopsDB']->query('SELECT MAX(ratingid) FROM ' . $destination['votes']);
814
    [$max_ratingid] = $GLOBALS['xoopsDB']->fetchRow($result);
815
816
    //Import data into category table
817
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['cat'] . ' (`old_cid`, `old_pid`, `title`, `imgurl`, `description`, `weight`, `dohtml`)' . ' SELECT `cat_cid`, `cat_pid`, `cat_title`, `cat_imgurl`, `cat_description_main`, `cat_weight`, 1' . ' FROM ' . $source['cat']);
818
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' categories into ' . $destination['cat'] . '<br>';
819
    //Import data into downloads table
820
    $GLOBALS['xoopsDB']->query(
821
        'INSERT'
822
        . ' INTO '
823
        . $destination['downloads']
824
        . ' (`cid`, `old_lid`, `old_cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `submitter`, `status`, `published`, `hits`, `rating`, `votes`, `comments`, `features`, `requirements`, `dhistory`, `summary`, `description`, `dohtml`)'
825
        . " SELECT 0, `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `submitter`, `status`, `date`, `hits`, `rating`, `votes`, `comments`, '', '', '', '', `description`, 1"
826
        . ' FROM '
827
        . $source['downloads']
828
    );
829
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' downloads into ' . $destination['downloads'] . '<br>';
830
    //Import data into brokens table
831
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['broken'] . ' (`lid`, `sender`, `ip`)' . ' SELECT `lid`, `sender`, `ip`' . ' FROM ' . $source['broken']);
832
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' broken reports into ' . $destination['broken'] . '<br>';
833
    //Import data into votedata table
834
    $GLOBALS['xoopsDB']->query('INSERT' . ' INTO ' . $destination['votes'] . ' (`lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`)' . ' SELECT `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`' . ' FROM ' . $source['votes']);
835
    echo 'Imported ' . $GLOBALS['xoopsDB']->getAffectedRows() . ' votes into ' . $destination['votes'] . '<br>';
836
    /*
837
                //Import data into mod request table
838
                $GLOBALS['xoopsDB']->query(
839
                    "INSERT INTO " . $destination['mod'] . " (`lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`,`features`, `requirements`, `publisher`, `dhistory`, `summary`)
840
                                 SELECT `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `logourl`, `description`, `modifysubmitter`,'','','','','' FROM "
841
                    . $source['mod']
842
                );
843
                echo "Imported " . $GLOBALS['xoopsDB']->getAffectedRows() . " modification requests into " . $destination['mod'] . "<br>";
844
    */
845
    //Update category ID to new value
846
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['downloads'] . ' d, ' . $destination['cat'] . ' c SET d.cid=c.cid' . ' WHERE d.old_cid=c.old_cid AND d.old_cid != 0');
847
    $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['cat'] . ' c1, ' . $destination['cat'] . ' c2 SET c1.pid=c2.cid' . ' WHERE c1.old_pid=c2.old_cid AND c1.old_pid != 0');
848
    /*
849
                if ($max_requestid) {
850
                    $GLOBALS['xoopsDB']->query(
851
                        "UPDATE " . $destination['mod'] . " m, " . $destination['cat'] . " c SET m.cid=c.cid"
852
                        . " WHERE m.requestid > " . $max_requestid
853
                        . " AND c.old_cid=m.cid"
854
                    );
855
                    //Update lid values in mod table
856
                    $GLOBALS['xoopsDB']->query(
857
                        "UPDATE " . $destination['mod'] . " m, " . $destination['downloads'] . " d SET m.lid=d.lid"
858
                        . " WHERE m.requestid > " . $max_requestid
859
                        . " AND m.lid=d.old_lid"
860
                    );
861
                }
862
    */
863
    if ($max_ratingid) {
864
        //Update lid values in votedata table
865
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['votes'] . ' v, ' . $destination['downloads'] . ' d SET v.lid=d.lid' . ' WHERE v.ratingid > ' . $max_ratingid . ' AND v.lid=d.old_lid');
866
    }
867
    if ($max_reportid) {
868
        //Update lid values in brokens table
869
        $GLOBALS['xoopsDB']->query('UPDATE ' . $destination['broken'] . ' b, ' . $destination['downloads'] . ' d SET b.lid=d.lid' . ' WHERE b.reportid > ' . $max_reportid . ' AND b.lid=d.old_lid');
870
    }
871
872
    //Remove temporary fields
873
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_cid`');
874
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['cat'] . ' DROP `old_pid`');
875
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_cid`');
876
    $GLOBALS['xoopsDB']->query('ALTER TABLE .' . $destination['downloads'] . ' DROP `old_lid`');
877
}
878