PDA


View Full Version : Importing from another platform


ManagerJosh
09-05-2007, 04:41 AM
I'd like to move all my files off my old platform to Dynamics. However I've been banging my head on how to accomplish this. I have a whole mess of custom fields, downloads, etc. to move over.

Is there any formatting or SQL structure guides, etc. I can follow to rig up an acceptable database to populate Dynamic's DB?

Brian
09-05-2007, 01:04 PM
I've just posted a vBlogetin import script here (http://www.vbadvanced.com/forum/showthread.php?t=24136). Maybe you could use that as a base for yours?

ManagerJosh
09-05-2007, 01:44 PM
It's definitely a start. But what about actual attachment files?

Brian
09-06-2007, 10:17 AM
Here's the attachment section from my vB forum import script. It still needs to be updated since it was created for the beta versions, so some of the table names and such may be different. A quick find/replace on blog/dyna should take care of most of that though.

// ##### Attachments

// Load the $vba_image class
require_once(DIR . '/includes/vba_blog_class_image.php');

$vba_image =& new vba_blog_image();
$vba_image->_vb =& $vbulletin;

$attachentryids = array();
$getattach = $db->query_read("
SELECT attachment.*, thread.threadid
FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (attachment.postid = thread.firstpostid)
WHERE forumid = $forumid
ORDER BY attachmentid
LIMIT " . ($pagedata['minlimit'] - 1) . ", $perpage
");
while ($attach = $db->fetch_array($getattach))
{
$postcount++;

if ($postcount == 1)
{
$attachquery = '
INSERT INTO ' . TABLE_PREFIX . 'adv_blog_attachments
(entryid, filename, userid, dateline, views, filesize, hasthumb, valid, extension)
VALUES
';
}

$attach['filename'] = substr($attach['filename'], 0, (strlen($attach['filename']) - (strlen($attach['extension']) + 1)));

$attachquery .= "(
$attach[threadid],
'" . $db->escape_string($attach['filename']) . "',
$attach[userid],
$attach[dateline],
$attach[counter],
$attach[filesize],
" . iif($attach['thumbnail_filesize'], 1, 0) . ",
$attach[visible],
'$attach[extension]'
), ";

$folderpath = '/' . $vba_image->fetch_upload_folders($attach['userid']) . '/';

copy(
$vbulletin->options['attachpath'] . $folderpath . $attach['attachmentid'] . '.attach',
$vbulletin->adv_blog_opts['blog_attachpath'] . $folderpath . $attach['filename'] . '_' . $attach['dateline'] . '.' . $attach['extension']
);

if ($attach['thumbnail_filesize'])
{
copy(
$vbulletin->options['attachpath'] . $folderpath . $attach['attachmentid'] . '.thumb',
$vbulletin->adv_blog_opts['blog_attachpath'] . $folderpath . $attach['filename'] . '_' . $attach['dateline'] . '_thumb.' . $attach['extension']
);
}

// Make sure we're not inserting more than 200 at one time
if ($postcount == 200)
{
$postcount = 0;
$db->query_write(substr($attachquery, 0, (strlen($attachquery) - 2)));
}

$attachentryids[$attach['threadid']]++;
}

if ($postcount)
{
$postcount = 0;
$db->query_write(substr($attachquery, 0, (strlen($attachquery) - 2)));
}

if (!empty($attachentryids))
{
$attachcounts = array();

// Reformat the array so we can just do a few updates depending on the count
foreach ($attachentryids AS $entryid => $attachcount)
{
$attachcounts[$attachcount][] = $entryid;
}

if (!empty($attachcounts))
{
foreach ($attachcounts AS $attcount => $attentries)
{
$db->query_write("UPDATE " . TABLE_PREFIX . "adv_blog_entries SET hasattach = $attcount WHERE entryid IN(" . implode(', ', $attentries) . ")");
}
}
}

ManagerJosh
09-06-2007, 11:45 AM
Meah. The problem with mine is that my files are actually flatfiles, and not stored in the database.

Brian
09-06-2007, 02:06 PM
The code I posted is for attachments stored in the file system. The copy() functions there are what copies the files over to your vBa Dynamics folder. Even if your files are not stored in the database or there's no tables with info about them, I would assume that they have to have some type of system to mark which entry they belong to, right?

ManagerJosh
09-06-2007, 10:24 PM
Let me PM you a link to a SQL copy of the database structure. Maybe you can take a look and see what I am trying to accomplish. I'm also trying to import all the data from the fields into respective custom fields in Dynamics.

Brian
09-07-2007, 01:45 PM
Any idea what part of that data determines whether an entry has an attachment/file/whatever-they-call-it associated with it? And what the naming structure for their attachments is like?

For the custom fields, it looks like you would need to select the data from the 'ezdatabase_3_field' table and insert mostly the same values into the 'adv_dyna_cfields' table. The 'type' may be different for some (ex: longtext), but they seem to be similar enough.
It looks like the 'ezdatabase_3_main' table is altered each time a custom field is added, so you would need to grab the data from that table and insert it into the 'adv_dyna_cfields_entries' table. Their structure is obviously a bit different, so you would need to make sure that the column names are changed so that the fields are being inserted something like this:
1text -> field1
3longtext -> field3
7radio -> field7

ManagerJosh
09-07-2007, 06:59 PM
all files are stored into an /uploads/ folder

Brian
09-08-2007, 03:58 PM
Is there some type of naming structure to them? Like including the 'id' in the filename? Or how does the script associate the right attachment with the right entry?

ManagerJosh
09-08-2007, 10:57 PM
AFAIK, it uses various things to control files

File Name
Item ID
Database ID
Field Number
Field Type

You can see the entire system live right now at http://www.worldsims.org/modules.php?name=Database&p=getcat&db_id=3&cat_id=1