Posted: Thu Jan 03, 2008 10:03 pm
Hi!
Ah dang, I see it. My mistake. Try this instead, I didn't specify the right serendipity_db_query() command:
http://nopaste.php-quake.net/13419
Regards,
Garvin
Ah dang, I see it. My mistake. Try this instead, I didn't specify the right serendipity_db_query() command:
http://nopaste.php-quake.net/13419
Code: Select all
<?php
// Include the s9y framework, so that we can access the same Database.
include 'serendipity_config.inc.php';
// Helper function to upload all table data into a new one, keep
// the IDs for later use.
function migrate($table, $table2, $unsetid, &$assoc, $assoc_key = false, $assoc_array = false, $assoc_key2 = false, $assoc_array2 = false) {
// Fetch old data
$q = "SELECT * from " . $table;
echo $q . "<br />\n";
$old_data = serendipity_db_query($q, false, 'assoc');
if (!is_array($old_data)) {
echo "Table contained no data.<br />\n";
return false;
}
// Iterate each data
foreach($old_data AS $idx => $data) {
// Unset keys that are not allowed in the new db
$assocval = $data[$unsetid];
unset($data[$unsetid]);
// Build SQL VALUES and KEY parts
$keys = array();
$values = array();
foreach($data AS $key => $val) {
$keys[] = "`" . $key . "`";
$values[] = "'" . serendipity_db_escape_string($val) . "'";
}
// See if we must fixup the ID before inserting!
if ($assoc_key) {
$data[$assoc_key] = $assoc_array[$assoc_key];
}
if ($assoc_key2) {
$data[$assoc_key2] = $assoc_array2[$assoc_key2];
}
// Insert into new table
$iq = "INSERT INTO $table2 (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ")";
$res = serendipity_db_query($iq);
echo $res . "<br />\n";
echo "INSERTED entry into $table2 (" . $assocval . " / " . $data[$assoc_key] . " / " . $data[$assoc_key2] . ")<br />\n";
// Store new ID, we need that later!
$newid = serendipity_db_insert_id();
echo "NEW ID: $newid<br />\n";
$assoc[$assocval] = $newid;
}
echo "Done importing table $table<br />\n";
}
// Store old entry ids, and old category ids here:
$assoc = array();
// Fetch all entries from the old DB, store their old and new IDs:
migrate('s9y_entries', 'serendipity_entries', 'id', $assoc['entries']);
migrate('s9y_entryproperties', 'serendipity_entryproperties', 'entryid', $assoc['entryproperties'], 'entryid', $assoc['entries']);
migrate('s9y_comments', 'serendipity_comments', 'id', $assoc['comments'], 'entry_id', $assoc['entries']);
migrate('s9y_category', 'serendipity_category', 'categoryid', $assoc['category']);
// Special case, because both ID values need to be fixed
migrate('s9y_entrycat', 'serendipity_entrycat', 'entryid', $assoc['entrycat'], 'entryid', $assoc['entries'], 'categoryid', $assoc['categoryid']);
Garvin