import data from s9y

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

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

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']);
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Rei
Regular
Posts: 30
Joined: Tue Jan 01, 2008 11:13 am
Location: Malaysia

Post by Rei »

Hi Garvin, there is improvement, but with some errors still. ;)

Successfully imported the _entries, _comments and _category.
NOTE: although the id of _comments table have been rearranged started from #1, but the entry_id in the new _comments table never update to the new id. [it remain the same as the old _comments table]
SELECT * from serendipity_entries
1
INSERTED entry into s9y_entries (3 / / )
NEW ID: 1
:
:
1
INSERTED entry into s9y_entries (431 / / )
NEW ID: 319
Done importing table serendipity_entries
SELECT * from serendipity_comments
1
INSERTED entry into s9y_comments (166 / / )
NEW ID: 1
:
:
1
INSERTED entry into s9y_comments (176 / / )
NEW ID: 172
Done importing table serendipity_comments
SELECT * from serendipity_category
1
INSERTED entry into s9y_category (7 / / )
NEW ID: 1
1
INSERTED entry into s9y_category (17 / / )
NEW ID: 2
1
INSERTED entry into s9y_category (19 / / )
NEW ID: 3
1
INSERTED entry into s9y_category (21 / / )
NEW ID: 4
1
INSERTED entry into s9y_category (36 / / )
NEW ID: 5
1
INSERTED entry into s9y_category (37 / / )
NEW ID: 6
1
INSERTED entry into s9y_category (35 / / )
NEW ID: 7
1
INSERTED entry into s9y_category (33 / / )
NEW ID: 8
1
INSERTED entry into s9y_category (34 / / )
NEW ID: 9
Done importing table serendipity_category
Then, _entryproperties has the following error.
SELECT * from serendipity_entryproperties
1
INSERTED entry into s9y_entryproperties (250 / / )
NEW ID: 0
INSERT INTO s9y_entryproperties (`property`, `value`) VALUES ('ep_access', 'member')
/ Duplicate entry '0-ep_access' for key 1
:
:
INSERTED entry into s9y_entryproperties (250 / / )
NEW ID: 0
INSERT INTO s9y_entryproperties (`property`, `value`) VALUES ('ep_cache_body', 'Spending whole day editing the trip\'s photos and finally get the slide shows VCD done.
\r\nHowever, need to check if it works.')
/ Duplicate entry '0-ep_cache_body' for key 1
:
:
INSERT INTO s9y_entryproperties (`property`, `value`) VALUES ('ep_cache_extended', 'Chart #34
\r\nChart II should be:
\r\nRows 12-24.
\r\nRep rows.')
/ Duplicate entry '0-ep_cache_extended' for key 1
And, problems for _entrycat too. [the VALUES ('old category id')]
SELECT * from serendipity_entrycat
1
INSERTED entry into s9y_entrycat (3 / / )
NEW ID: 0
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('21')
/ Duplicate entry '0-21' for key 1
:
:
/ Duplicate entry '0-21' for key 1
INSERTED entry into s9y_entrycat (67 / / )
NEW ID: 0
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('17')
/ Duplicate entry '0-17' for key 1
INSERTED entry into s9y_entrycat (68 / / )
NEW ID: 0
1
INSERTED entry into s9y_entrycat (136 / / )
NEW ID: 0
1
INSERTED entry into s9y_entrycat (136 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('9')
/ Duplicate entry '0-9' for key 1
INSERTED entry into s9y_entrycat (408 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('33')
/ Duplicate entry '0-33' for key 1
INSERTED entry into s9y_entrycat (417 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('7')
/ Duplicate entry '0-7' for key 1
INSERTED entry into s9y_entrycat (428 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('19')
/ Duplicate entry '0-19' for key 1
INSERTED entry into s9y_entrycat (430 / / )
NEW ID: 0
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('34')
/ Duplicate entry '0-34' for key 1
INSERTED entry into s9y_entrycat (431 / / )
NEW ID: 0
1
INSERTED entry into s9y_entrycat (432 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('36')
/ Duplicate entry '0-36' for key 1
INSERTED entry into s9y_entrycat (454 / / )
NEW ID: 0
1
INSERTED entry into s9y_entrycat (455 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('37')
/ Duplicate entry '0-37' for key 1
INSERTED entry into s9y_entrycat (464 / / )
NEW ID: 0
:
:
INSERT INTO s9y_entrycat (`categoryid`) VALUES ('35')
/ Duplicate entry '0-35' for key 1
INSERTED entry into s9y_entrycat (467 / / )
NEW ID: 0
Done importing table serendipity_entrycat
The above results was getting by having a new installation of s9y (for testing purpose) since I encountered the following problem - running the migrate.php would not let me have all the id start from #1 even though i deleted the existing data of the s9y_entries, s9y_category etc. through phpMyAdmin.
That is due to the creation of one posts and 4 categories (to play ard the configuration and template) after installing the s9y (hosted). i.e. if I have created 4 categories before and even I have deleted the data in phpMyAdmin, running migrate.php would only let me have the category id started from #5 onwards.
s9y 1.2.1 & 1.3.1 - bulletproof v1.2 - Safari3.0.4 & 3.1.2
linux - php5.2.6 - mysql5.0.51a
[openssl extension - no / magic_quotes_gpc - on / allow_url_fopen - off / post_max_size - 8m / imagemagick binary - not found]
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Hm, it seems developing that script without having actual data was not really a good idea.

The problem seems to be that like for the entryproperties query, the IDs are missing in the "values" range. Basically the script should fix all ID's that were "1" before to "5" then.

I'll try to create some test dump after this weekend. I'm sure we're 95% there already. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Rei
Regular
Posts: 30
Joined: Tue Jan 01, 2008 11:13 am
Location: Malaysia

Post by Rei »

Hi Garvin,

I finally imported the data by going through a few import export process.

Firstly, i export the other blogwares data to MT format, made necessary changes manually, then import to s9y. (Took quite a lot of time. Lucky i only have a few hundreds of entries. :D)
After checking through and confirm the data is correctly associated with each others, i then export the sql dump of 4 tables (_entries, _comments, _entrycat and _category table) from my local machine and import them to the hosted environment.

I ignore the _entryproperties table because there seems nothing inside.
(I installed the "extended properties for entries" plugin but i never enable caching of entries.)
Would i face any problem by doing this way?


If you would like to try to complete the scripts when you free & feel like doing it, i will help in test run.
s9y 1.2.1 & 1.3.1 - bulletproof v1.2 - Safari3.0.4 & 3.1.2
linux - php5.2.6 - mysql5.0.51a
[openssl extension - no / magic_quotes_gpc - on / allow_url_fopen - off / post_max_size - 8m / imagemagick binary - not found]
Post Reply