Import entries from plain text-file based blog into S9Y, p

Having trouble installing serendipity?
Post Reply
JavaSys
Posts: 3
Joined: Wed Jan 01, 2014 1:42 pm

Import entries from plain text-file based blog into S9Y, p

Post by JavaSys » Wed Jan 01, 2014 2:01 pm

Hello! (by the way - Happy New Year of 2014 :mrgreen:)

I am trying to migrate away from an ancient version of a plain-text file based blog (SimplePHPblog) -- into the nice shiny new Serendipity blog.

So, I have all these static-format coded plain-text files, one per blog entry, spanning 7 years of blogging.

I am fairly techy and have some basic skills with both PHP and SQLite3.

What is the easiest way to import all the many entries from the plain-text files into S9Y, please?

Are there generic importers I can use as a basis - or do I have to start from scratch (Note RSS is not available)

Is there any PHP code or implementation documentation that would act as a guide or starting point - or even better, a generic CSV file or similar S9Y importer available, please?

All ideas welcomed (even, if need be, "Don't" do it!) - there are alternatives to S9Y, I just liked the look of Serendipity, and as the blog is used daily it's good to work with pleasant software :D

Kind regards for any help!
-J-

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Import entries from plain text-file based blog into S9Y,

Post by Timbalu » Wed Jan 01, 2014 2:59 pm

Hi

I'm afraid there doesn't seem to be an importer... in 2005 there was a Sourceforge Feature Request, which was never answered. And here in the forum it says: http://board.s9y.org/viewtopic.php?f=1&t=12085

Maybe you can write one yourself, rewriting a 'nearby one' of our current importers, see https://github.com/s9y/Serendipity/tree ... /importers (There is a generic one - but I don't have experiences with it.)

The other solution could be to use wordpress as an intermediate agent first (which has an importer for SimplePHPblog, I think) and then re-import from Wordpress. (This last step is very important! :mrgreen: )

Maybe you could make another step inbetween and switch to Flattpress before, which may hit better mirgration slots(?) http://flatpress.org/vanilla2/discussio ... gration/p1
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian

JavaSys
Posts: 3
Joined: Wed Jan 01, 2014 1:42 pm

Re: Import entries from plain text-file based blog into S9Y,

Post by JavaSys » Wed Jan 01, 2014 3:17 pm

Many thanks Ian for your kind guidance - I'll look into each of your suggestions and see which looks easiest :D

The 'via Wordpress' if it can handle the import already sounds good, so I'll look there first.

Again, thanks for your swift and helpful reply, appreciated.
-J-

JavaSys
Posts: 3
Joined: Wed Jan 01, 2014 1:42 pm

Re: Import entries from plain text-file based blog into S9Y,

Post by JavaSys » Wed Jan 08, 2014 5:49 pm

In case anyone else wishes to follow this saga, an update on how it was successfully achieved.

Step 1 - create a new Serendipity blog to receive the old simplePHPblog entries
Step 2 - create all the users and categories to be used for the new blog entries, and a dummy single entry in each category by each author to gain the detals necessary for the conversion, below.
Step 3 - using mysqldump, create a complete export of the new blog MySQL database

Step 4 - using the simplePHPblog PHP source code gather just the few functions needed to traverse all the year/month directories reading every blog entry into memory

Step 5 - add to those few PHP functions two newly written PHP functions:
a) entry_convert_to_s9y() - to convert every simplePHPblog blog entry into a suitably formatted S9Y MySQL "INSERT" statement and
b) category_convert_to_s9y() - to create a suitably formatted MySQL "INSERT" statement for the entries associated S9Y category

The resultant (single) PHP file thus reads all the simplePHPblog entries (in my case all 2574 entries spanning the years 2007 to 2013) and writes out two new MySQL files, one containing a MySQL "INSERT" statement for the blog entry, ie this:

Code: Select all

INSERT INTO `serendipity_entries` (`id`,`title`, `timestamp`, `body`, `comments`,`trackbacks`,`extended`,`exflag`,`author`,`authorid`,`isdraft`,`allow_comments`,`last_modified`,`moderate_comments`) VALUES( $id, $title, ...etc...
and the associated category MySQL INSTERT statement, ie like this:

Code: Select all

 INSERT INTO `serendipity_entrycat` (`entryid`, `categoryid`) VALUES( $entry, $cid );
Step 6 - Running the conversion PHP file as a command-line utility creates the files containing all the entries with an associated category entry too.

Step 7 - manually edit the MySQL export file (created in step 3, above) replacing the two tables serendipity_entries and serendipity_entrycat with the contents of the two files from step 6.

Step 8 - re-import the MySQL file fro step 7, and confirm everything is consistent and working

Step 9 - congratulations now enjoy using the blog complete with all the old entries from 2007-2013 too.

So, many thanks for the hints, it forced me to actually read the code used by both the SimplePHPblog software and the various Serendipity importer options provided - and work out the above sequence, which was entirely successful and not too painful at all.

Finally, thanks for the Serendipity Blog software - wish I'd known about it years ago! :D

Attached for what it's worth, is the complete, single PHP file I used for the conversion - don't be too critical of the code - it was and will remain a one-off hack! :oops:
Attachments

[The extension php has been deactivated and can no longer be displayed.]


User avatar
garvinhicking
Core Developer
Posts: 30014
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Import entries from plain text-file based blog into S9Y,

Post by garvinhicking » Thu Jan 09, 2014 3:17 pm

Great, so many thanks for sharing. It definitely sounds more complicated than it is, so anybody reading this should surely be able to reproduce. :-)
# 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/

Post Reply