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

Comments

icecreamyou’s picture

Status: Active » Postponed

I'm going to postpone this until after the full 2.0 release, but this will definitely be useful.

icecreamyou’s picture

I'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.)

INSERT INTO {facebook_status} (uid, pid, status, status_time)
SELECT (
    (SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    ) AS x
    UNION
    (SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook}
    ) AS y
);

Otherwise, the data will probably have to be transferred to a temporary table first:

INSERT INTO {facebook_status_temp} (uid, pid, status, status_time)
SELECT
    recipient as uid,
    author as pid,
    message as status,
    created as status_time
FROM {guestbook};

INSERT INTO {facebook_status_temp} (uid, pid, status, status_time)
SELECT
    author as uid,
    commentauthor AS pid,
   comment AS status,
   created + 100 AS status_time
FROM {guestbook}
WHERE comment != '';

INSERT INTO {facebook_status} SELECT * FROM {facebook_status_temp};
michelle’s picture

Sorry for the delay. Just tried it and I get:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS x
    UNION
    (SELECT
        author AS uid,
        commentauthor AS pid,
' at line 9

line 9 is ") AS x"

Michelle

icecreamyou’s picture

Well, 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.

INSERT INTO {facebook_status} (uid, pid, status, status_time)
SELECT (
    (SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    )
    UNION
    (SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook}
    )
);

Thanks

michelle’s picture

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
    (SELECT
        author AS uid,
        commentauthor AS pid,
        c' at line 10

Doesn'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

icecreamyou’s picture

Try running just the UNION part:

    (SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    )
    UNION
    (SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook}
    )

If that runs okay, try this:

INSERT INTO {facebook_status} (uid, pid, status, status_time)
    SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    UNION
    SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook};
michelle’s picture

Ok, that works except it produces a lot of rows with NULL.

Michelle

icecreamyou’s picture

Strange. Can you try UNION ALL instead of UNION? I think the NULLs could be SQL trying to combine rows.

INSERT INTO {facebook_status} (uid, pid, status, status_time)
    SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    UNION ALL
    SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook};
michelle’s picture

Nope, same problem. Could we add a where status not null to it?

Michelle

icecreamyou’s picture

That might do it, although the NULL values are probably a result of the UNION rather than being copied out of {guestbook}.

INSERT INTO {facebook_status} (uid, pid, status, status_time)
    SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM {guestbook}
    WHERE status IS NOT NULL
    UNION ALL
    SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM {guestbook}
    WHERE status IS NOT NULL;

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.

michelle’s picture

Yeah, 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

icecreamyou’s picture

Hmm. 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?

michelle’s picture

Ok, 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:

INSERT INTO facebook_status (uid, pid, status, status_time)   
  SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM guestbook
    UNION ALL
    SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time 
    FROM guestbook
    WHERE commentauthor > 0;

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

icecreamyou’s picture

Status: Postponed » Active

Good 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.

INSERT INTO facebook_status (uid, pid, status, status_time)  
  SELECT
        recipient AS uid,
        author AS pid,
        message AS status,
        created AS status_time
    FROM guestbook
    WHERE author <> 0
    UNION ALL
    SELECT
        author AS uid,
        commentauthor AS pid,
        comment AS status,
        created + 100 AS status_time
    FROM guestbook
    WHERE commentauthor <> 0;

I guess this means I can start working on actually including this feature then.

michelle’s picture

Ah, yeah, that's true. I forgot that both of them could be anonymous.

Great, glad we got something working. :)

Thanks,

Michelle

icecreamyou’s picture

Status: Active » Needs review
StatusFileSize
new867 bytes

The 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.

icecreamyou’s picture

StatusFileSize
new944 bytes

Whoops, looks like a .module file is required for Drupal to make the module appear at admin/build/modules.

michelle’s picture

FYI - 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

icecreamyou’s picture

Status: Needs review » Fixed
StatusFileSize
new1008 bytes

Alright, final version. Linking to this in the documentation instead of including it in the module per Michelle's suggestion in IRC.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kakajoe’s picture

Wow the dynamic duo strike again !! thanks GOD, GOD they sent u both...waiting for the next break thru....

igorik’s picture

Status: Closed (fixed) » Active

Hi

Could you please add (optional) support for Facebook like statuses comments module?
than all replies on guestbook messages could convert as comments...

thanks
Igor

icecreamyou’s picture

IMHO 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.

icecreamyou’s picture

Status: Active » Closed (fixed)

Er, 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.

yngens’s picture

What 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...

icecreamyou’s picture

Use 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.

unknownterritory’s picture

Version: 6.x-2.x-dev » 6.x-3.1
StatusFileSize
new1.01 KB

The 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.