|
From: <luc...@us...> - 2013-10-05 16:39:42
|
Revision: 12136
http://sourceforge.net/p/xoops/svn/12136
Author: luciorota
Date: 2013-10-05 16:39:39 +0000 (Sat, 05 Oct 2013)
Log Message:
-----------
created import procedure from original wfdownloads 3.23 module to cloned module
Modified Paths:
--------------
XoopsModules/wfdownloads/trunk/wfdownloads/admin/import.php
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/admin/import.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/admin/import.php 2013-10-05 13:47:28 UTC (rev 12135)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/admin/import.php 2013-10-05 16:39:39 UTC (rev 12136)
@@ -118,8 +118,8 @@
// Is wf-downloads installed?
if ($wfdownloads->getModule()->dirname() != "wf"."downloads") {
$got_options = false;
- if (wfdownloads_checkModule('wf'.'downloads')) {
- $moduleVersion = round(wfdownloads_checkModule('wf'.'downloads') / 100, 2);
+ if (wfdownloads_checkModule('wf'.'downloads')) { // don't modify, is for cloning
+ $moduleVersion = round(wfdownloads_checkModule('wf'.'downloads') / 100, 2); // don't modify, is for cloning
$button = new XoopsFormButton(_AM_WFDOWNLOADS_IMPORT_WFD . '<br />' . $moduleVersion, "wmp_button", _AM_WFDOWNLOADS_IMPORT_BUTTON_IMPORT, "submit");
$button->setExtra("onclick='document.forms.form.op.value=\"import.wfd322\"'");
$form->addElement($button);
@@ -205,100 +205,162 @@
function import_wfd_to_wfdownloads()
{
global $xoopsDB;
+ $module_handler =& xoops_gethandler('module');
+ // Get source module/config
+ $wfdDirname = 'wf'.'downloads'; // don't modify, is for cloning
+ $wfdModule = $module_handler->getByDirname($wfdDirname);
+ if (empty($wfdModuleConfig)) {
+ $config_handler = xoops_gethandler("config");
+ $wfdModuleConfig = $config_handler->getConfigsByCat(0, $wfdModule->mid());
+ }
+ $wfdCategoriesHandler = xoops_getModuleHandler('category', $wfdDirname);
+ $wfdDownloadsHandler = xoops_getModuleHandler('download', $wfdDirname);
+ // Get destination module/handlers/configs
+ $wfdownloads = WfdownloadsWfdownloads::getInstance();
+
+ echo "<br /><b>Copying Files</b><br />";
+ // Copy categories images/thumbnails
+ if (!wfdownloads_copyDir(XOOPS_ROOT_PATH . '/' . $wfdModuleConfig['catimage'], XOOPS_ROOT_PATH . '/' . $wfdownloads->getConfig('catimage'))) {
+ return false;
+ }
+ echo "Copied categories images and thumbnails<br />";
+ // Copy screenshots images/thumbnails
+ if (!wfdownloads_copyDir(XOOPS_ROOT_PATH . '/' . $wfdModuleConfig['screenshots'], XOOPS_ROOT_PATH . '/' . $wfdownloads->getConfig('screenshots'))) {
+ return false;
+ }
+ echo "Copied downloads screenshots and thumbnails<br />";
+ // Copy files
+ if (!wfdownloads_copyDir($wfdModuleConfig['uploaddir'], $wfdownloads->getConfig('uploaddir'))) {
+ return false;
+ }
+ echo "Copied files<br />";
+
echo "<br /><b>Importing Data</b><br />";
$destination = array(
"cat" => $xoopsDB->prefix("wfdownloads_cat"),
"downloads" => $xoopsDB->prefix("wfdownloads_downloads"),
+ "mirrors" => $xoopsDB->prefix("wfdownloads_mirrors"),
+ "reviews" => $xoopsDB->prefix("wfdownloads_reviews"),
"broken" => $xoopsDB->prefix("wfdownloads_broken"),
"mod" => $xoopsDB->prefix("wfdownloads_mod"),
"votes" => $xoopsDB->prefix("wfdownloads_votedata"));
$source = array(
- "cat" => $xoopsDB ->prefix("wf"."downloads_cat"),
- "downloads" => $xoopsDB->prefix("wf"."downloads_downloads"),
- "broken" => $xoopsDB->prefix("wf"."downloads_broken"),
- "mod" => $xoopsDB->prefix("wf"."downloads_mod"),
- "votes" => $xoopsDB->prefix("wf"."downloads_votedata"));
+ "cat" => $xoopsDB ->prefix("wf"."downloads_cat"), // don't modify, is for cloning
+ "downloads" => $xoopsDB->prefix("wf"."downloads_downloads"), // don't modify, is for cloning
+ "mirrors" => $xoopsDB->prefix("wf"."downloads_mirrors"), // don't modify, is for cloning
+ "reviews" => $xoopsDB->prefix("wf"."downloads_reviews"), // don't modify, is for cloning
+ "broken" => $xoopsDB->prefix("wf"."downloads_broken"), // don't modify, is for cloning
+ "mod" => $xoopsDB->prefix("wf"."downloads_mod"), // don't modify, is for cloning
+ "votes" => $xoopsDB->prefix("wf"."downloads_votedata")); // don't modify, is for cloning
//Add temporary field to category table
- $xoopsDB->query("ALTER TABLE " . $destination['cat'] . " ADD `old_cid` int NOT NULL default 0");
- $xoopsDB->query("ALTER TABLE " . $destination['cat'] . " ADD `old_pid` int NOT NULL default 0");
-
+ $xoopsDB->query("ALTER TABLE {$destination['cat']} ADD `old_cid` int NOT NULL default 0");
+ $xoopsDB->query("ALTER TABLE {$destination['cat']} ADD `old_pid` int NOT NULL default 0");
//Add temporary fields to downloads table
- $xoopsDB->query("ALTER TABLE " . $destination['downloads'] . " ADD `old_lid` int NOT NULL default 0");
- $xoopsDB->query("ALTER TABLE " . $destination['downloads'] . " ADD `old_cid` int NOT NULL default 0");
+ $xoopsDB->query("ALTER TABLE {$destination['downloads']} ADD `old_lid` int NOT NULL default 0");
+ $xoopsDB->query("ALTER TABLE {$destination['downloads']} ADD `old_cid` int NOT NULL default 0");
+ //Get latest mirror ID to determine which records will need an updated lid value afterwards
+ $result = $xoopsDB->query("SELECT MAX(mirror_id) FROM {$destination['mirrors']}");
+ list($max_mirrorid) = $xoopsDB->fetchRow($result);
+ //Get latest review ID to determine which records will need an updated lid value afterwards
+ $result = $xoopsDB->query("SELECT MAX(review_id) FROM {$destination['reviews']}");
+ list($max_reviewid) = $xoopsDB->fetchRow($result);
//Get latest mod request ID to determine which records will need an updated lid value afterwards
- $result = $xoopsDB->query("SELECT MAX(requestid) FROM " . $destination['mod']);
+ $result = $xoopsDB->query("SELECT MAX(requestid) FROM {$destination['mod']}");
list($max_requestid) = $xoopsDB->fetchRow($result);
//Get latest report ID to determine, which records will need an updated lid value afterwards
- $result = $xoopsDB->query("SELECT MAX(reportid) FROM " . $destination['broken']);
+ $result = $xoopsDB->query("SELECT MAX(reportid) FROM {$destination['broken']}");
list($max_reportid) = $xoopsDB->fetchRow($result);
//Get latest vote ID to determine which records will need an updated lid value afterwards
- $result = $xoopsDB->query("SELECT MAX(ratingid) FROM " . $destination['votes']);
+ $result = $xoopsDB->query("SELECT MAX(ratingid) FROM {$destination['votes']}");
list($max_ratingid) = $xoopsDB->fetchRow($result);
//Import data into category table
- $sql = "INSERT INTO " . $destination['cat'] . " (";
- $sql.= "`old_cid`, `old_pid`, `title`, `imgurl`, `summary`";
- $sql.= ") SELECT ";
- $sql.= "`cid`, `pid`, `title`, `imgurl`, `summary`";
- $sql.= "FROM " . $source['cat'];
+ $sql = "INSERT INTO {$destination['cat']} (";
+ $sql.= " `old_cid`, `old_pid`, `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`, `formulize_fid`";
+ $sql.= " ) SELECT ";
+ $sql.= " `cid`, `pid`, `title`, `imgurl`, `description`, `total`, `summary`, `spotlighttop`, `spotlighthis`, `dohtml`, `dosmiley`, `doxcode`, `doimage`, `dobr`, `weight`, `formulize_fid`";
+ $sql.= " FROM {$source['cat']}";
$xoopsDB->query($sql);
- echo "Imported " . $xoopsDB->getAffectedRows() . " categories into " . $destination['cat'] . "<br />";
+ echo "Imported {$xoopsDB->getAffectedRows()} categories into {$destination['cat']}<br />";
//Import data into downloads table
- $xoopsDB->query("
- INSERT INTO " . $destination['downloads'] . " (
- `cid`, `old_lid`, `old_cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `screenshot2`, `screenshot3`, `screenshot4`, `submitter`, `status`, `published`, `hits`, `rating`, `votes`, `comments`, `features`, `requirements`, `dhistory`, `summary`, `description`)
- SELECT
- 0, `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `screenshot2`, `screenshot3`, `screenshot4`, `submitter`, `status`, `published`, `hits`, `rating`, `votes`, `comments`, `features`, `requirements`, `dhistory`, `summary`, `description`
- FROM " . $source['downloads']);
- echo "Imported " . $xoopsDB->getAffectedRows() . " downloads into " . $destination['downloads'] . "<br />";
+ $sql = "INSERT INTO {$destination['downloads']} (";
+ $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`";
+ $sql.= " ) SELECT ";
+ $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`";
+ $sql.= " FROM {$source['downloads']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} downloads into {$destination['downloads']}<br />";
+
+ //Import data into mirrors table
+ $sql = "INSERT INTO {$destination['mirrors']} (";
+ $sql.= " `lid`, `title`, `homeurl`, `location`, `continent`, `downurl`, `submit`, `date`, `uid`";
+ $sql.= " ) SELECT";
+ $sql.= " `lid`, `title`, `homeurl`, `location`, `continent`, `downurl`, `submit`, `date`, `uid`";
+ $sql.= " FROM {$source['mirrors']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} mirrors into {$destination['mirrors']}<br />";
+ //Import data into reviews table
+ $sql = "INSERT INTO {$destination['reviews']} (";
+ $sql.= " `lid`, `title`, `review`, `submit`, `date`, `uid`, `rate`";
+ $sql.= " ) SELECT";
+ $sql.= " `lid`, `title`, `review`, `submit`, `date`, `uid`, `rate`";
+ $sql.= " FROM {$source['reviews']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} reviews into {$destination['reviews']}<br />";
//Import data into brokens table
- $xoopsDB->query("
- INSERT INTO " . $destination['broken'] . " (
- `lid`, `sender`, `ip`)
- SELECT
- `lid`, `sender`, `ip`
- FROM " . $source['broken']);
- echo "Imported " . $xoopsDB->getAffectedRows()." broken reports into " . $destination['broken'] . "<br />";
+ $sql = "INSERT INTO {$destination['broken']} (";
+ $sql.= " `lid`, `sender`, `ip`";
+ $sql.= " ) SELECT";
+ $sql.= " `lid`, `sender`, `ip`";
+ $sql.= " FROM {$source['broken']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} broken reports into {$destination['broken']}<br />";
//Import data into votedata table
- $xoopsDB->query("
- INSERT INTO " . $destination['votes'] . " (
- `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`)
- SELECT
- `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`
- FROM " . $source['votes']);
- echo "Imported " . $xoopsDB->getAffectedRows()." votes into " . $destination['votes'] . "<br />";
+ $sql = "INSERT INTO {$destination['votes']} (";
+ $sql.= " `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`";
+ $sql.= " ) SELECT";
+ $sql.= " `lid`, `ratinguser`, `rating`, `ratinghostname`, `ratingtimestamp`";
+ $sql.= " FROM {$source['votes']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} votes into {$destination['votes']}<br />";
//Import data into mod request table
- $xoopsDB->query("
- INSERT INTO " . $destination['mod'] . " (
- `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`)
- SELECT
- `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`
- FROM " . $source['mod']);
- echo "Imported " . $xoopsDB->getAffectedRows() . " modification requests into " . $destination['mod'] . "<br />";
+ $sql = "INSERT INTO {$destination['mod']} (";
+ $sql.= " `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`)";
+ $sql.= " SELECT";
+ $sql.= " `lid`, `cid`, `title`, `url`, `homepage`, `version`, `size`, `platform`, `screenshot`, `description`, `modifysubmitter`, `features`, `requirements`, `publisher`, `dhistory`, `summary`";
+ $sql.= " FROM {$source['mod']}";
+ $xoopsDB->query($sql);
+ echo "Imported {$xoopsDB->getAffectedRows()} modification requests into {$destination['mod']}<br />";
- //Update category ID to new value
- $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");
- $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");
+ // Update category ID to new value
+ $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");
+ $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");
+ // Update lid values in mod table
if ($max_requestid) {
- $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");
- //Update lid values in mod table
- $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");
+ $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");
+ $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");
}
+ // Update lid values in mirrors table
+ if ($max_mirrorid) {
+ $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");
+ }
+ // Update lid values in reviews table
+ if ($max_reviewid) {
+ $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");
+ }
+ // Update lid values in votedata table
if ($max_ratingid) {
- //Update lid values in votedata table
- $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");
+ $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");
}
+ // Update lid values in broken table
if ($max_reportid) {
- //Update lid values in brokens table
- $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");
+ $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");
}
- //Update description
- //$xoopsDB->query("UPDATE " . $destination['downloads'] . " d, " . $source['text'] . " t SET d.description=t.description WHERE t.lid=d.old_lid");
//Remove temporary fields
$xoopsDB->query("ALTER TABLE ." . $destination['cat'] . " DROP `old_cid`");
|