Hi!
To migrate comments, categories and their associations to entries, you will need some sort of glue code. The ID of a category and an entry will change when you insert it to your new database.
To achieve what you want, let's say your hosted environment has the tables serendipity_entries and serendipity_category. Your old environment has those tables which you later need:
* s9y_entries
* s9y_entrycat
* s9y_category
* s9y_comments
* s9y_entryproperties
So, first make a SQL dump of your s9y_* tables. If they are called "serendipity_" as well, you need to use a text editor on your SQL dump and replace "`serendipity_" with "`s9y_" to rename the tables properly. Then import that SQL dump to your host, so that you have the serendipity_* and s9y_* tables in the same database.
Then you can use a PHP script like this, which you put as "migrate.php" into your serendipity directory, and it should look something like this:
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
$old_data = serendipity_db_query("SELECT * from " . $table);
// 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
serendipity_db_query("INSERT INTO $table2 (" . implode(', ', $keys) . ") VALUES (" . implode(', ', $values) . ")");
// Store new ID, we need that later!
$newid = serendipity_db_insert_id();
$assoc[$assocval] = $newid;
}
}
// 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']);
I could not test this code here, so be sure to make a backup of all DB tables! Do not run this script more than once, because it would generate duplicates. If it fails, first reimport the backup, and only then run the import again.
I'm quite sure it should work, though.
Regards,
Garvin