I want to switch from Guestbook to FBSS on my site but I didn't want to lose the existing entries so I compared the tables and figured out the SQL to convert them. This is only tested on my small number of entries (386) so I don't know how it performs if you have thousands.
This converts the main guestbook entries. It keeps the same ID as the originals. If that's not important to you, you can get rid of the sid part and let it auto increment.
INSERT INTO facebook_status (sid, uid, pid, status, status_time)
SELECT id AS sid,
recipient AS uid,
author AS pid,
message AS status,
created AS status_time
FROM guestbook;
This converts the comments. It's not perfect but it's better than losing them completely. It assumes that you are directing the comment to the author of the original entry and adds a smidge to the timestamp so it comes after the original. It does not keep the original ID as that belongs to the master entry. So all the comments will come at the end of the table as far as ID sequence goes.
INSERT INTO facebook_status (uid, pid, status, status_time)
SELECT author AS uid,
commentauthor AS pid,
comment AS status,
created + 100 AS status_time
FROM guestbook
WHERE comment != '';
Michelle
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | guestbook_facebook_status.tar_.gz | 1.01 KB | unknownterritory |
| #19 | facebook_status_guestbook.tar_.gz | 1008 bytes | icecreamyou |
| #17 | facebook_status_guestbook.tar_.gz | 944 bytes | icecreamyou |
| #16 | facebook_status_guestbook.tar_.gz | 867 bytes | icecreamyou |
Comments
Comment #1
icecreamyou commentedI'm going to postpone this until after the full 2.0 release, but this will definitely be useful.
Comment #2
icecreamyou commentedI'd like to get the Status ID sequential in the import, and also have the poster ID and owner ID correct. Is there any way you could test this query to see if it will work? (Obviously make sure to replace the curly braces with table prefixes.)
Otherwise, the data will probably have to be transferred to a temporary table first:
Comment #3
michelleSorry for the delay. Just tried it and I get:
line 9 is ") AS x"
Michelle
Comment #4
icecreamyou commentedWell, can you try it without the "AS x"/"AS y" then? Been awhile since I wrote queries with UNION and I forgot the temporary tables don't use aliases.
Thanks
Comment #5
michelleDoesn't look like it likes the union at all. Possibly it's SQLYog that's choking on it. When I'm a bit more awake, I'll try running it from code instead of using the GUI.
Michelle
Comment #6
icecreamyou commentedTry running just the UNION part:
If that runs okay, try this:
Comment #7
michelleOk, that works except it produces a lot of rows with NULL.
Michelle
Comment #8
icecreamyou commentedStrange. Can you try UNION ALL instead of UNION? I think the NULLs could be SQL trying to combine rows.
Comment #9
michelleNope, same problem. Could we add a where status not null to it?
Michelle
Comment #10
icecreamyou commentedThat might do it, although the NULL values are probably a result of the UNION rather than being copied out of {guestbook}.
Having NULL values is not a huge problem, because we could always just run a second query to delete them. However, my concern is that the NULL values are an indication that not all of the data got copied. If you can confirm that you have the right amount of records after the NULL records are deleted, that would be helpful.
Comment #11
michelleYeah, the NULLs are coming from the UNION. I thought maybe the where could be added onto the INSERT part. My SQL is horribly rusty, I'm afraid. Might have to UNION them into a temp table, then SELECT from there where not NULL.
There are 387 rows in the guestbook table. 13 of them have comments. So that should be 400 rows in facebook_status.
The query in #8 gets 774 rows, 400 of which have an empty status. That leaves 374 rows with valid data.
Something isn't adding up here. :(
Michelle
Comment #12
icecreamyou commentedHmm. It could be done with a temporary table, or without UNION it could be done in 4 queries (CREATE a temporary table, INSERT guestbook entries and then comments, DROP the temporary table). Speed is a factor here though, because this process could easily time out on very large sites. Do you get the same mismatch of row counts using just UNION instead of UNION ALL?
Comment #13
michelleOk, I took some time to really look at the query instead of blindly copying and pasting and I realized the problem. The query is assuming that every guestbook entry has a comment on it. This query works:
It will lose all anonymous comments, though. I don't know what you want to do about those. AFAIK, FBSS doesn't allow anonymous commenting. I didn't allow it on my site, either, so it doesn't affect me but it's something you'll want to consider if this is going to have a wider use.
Michelle
Comment #14
icecreamyou commentedGood to know. I didn't think about the fact that Guestbook supports anonymous posts. FBSS doesn't because the concepts don't apply cleanly to anonymous users since they're all represented by a single user account. I don't really have a problem with throwing those away, but that means both parts of the query should check for author <> 0.
I guess this means I can start working on actually including this feature then.
Comment #15
michelleAh, yeah, that's true. I forgot that both of them could be anonymous.
Great, glad we got something working. :)
Thanks,
Michelle
Comment #16
icecreamyou commentedThe attached module should perform the conversion. It consists of just a .info and .install file and depends on both FBSS and Guestbook. When enabled, it performs the conversion and then disables itself.
Testing is, of course, much appreciated.
Comment #17
icecreamyou commentedWhoops, looks like a .module file is required for Drupal to make the module appear at admin/build/modules.
Comment #18
michelleFYI - I didn't get to this last night. Had some critical problems that took me all the way until I crashed at 12:30am. Still have this tab open, though, and will get to it soon.
Michelle
Comment #19
icecreamyou commentedAlright, final version. Linking to this in the documentation instead of including it in the module per Michelle's suggestion in IRC.
Comment #21
kakajoe commentedWow the dynamic duo strike again !! thanks GOD, GOD they sent u both...waiting for the next break thru....
Comment #22
igorik commentedHi
Could you please add (optional) support for Facebook like statuses comments module?
than all replies on guestbook messages could convert as comments...
thanks
Igor
Comment #23
icecreamyou commentedIMHO all replies on guestbook messages should be converted as status messages to other users rather than status comments, which is something I've been meaning to do for awhile. It doesn't make a lot of sense to use FBSSC right now, because it doesn't work at all in most browsers.
Comment #24
icecreamyou commentedEr, actually, #23 is what the module already does.
Re: #22, again, FBSSC doesn't actually work at the moment, so there's no point importing anything into it.
Comment #25
yngens commentedWhat is the best pathway for converting from Guestbook to FBSS? I see IceCreamYou mentions that FBSSC does not work at the moment. Does that mean we can't convert from Guestbook for now? What is last C stands for in FBSSC - comments or conversion? Confusing abbreviations...
Comment #26
icecreamyou commentedUse the module attached in #19 to convert from Guestbook to FBSS. As you can see on the FBSSC project page, the "C" stands for "comments." When I said FBSSC didn't work, that was nearly 8 months ago -- it does work now, although you should use the dev version.
Comment #27
unknownterritory commentedThe module attached to #19 doesn't seem to work anymore. FBSS itself has changed meanwhile and its table column names changed as well. I've updated the module and it worked for me. I'm uploading it hoping that it might save time to someone else.
Note: the module doesn't disable itself anymore. It must be disabled manually. Otherwise, it works as previously described.