convert textpattern to radiant
This is a quick-n-dirty, poor-mans solution to a migration from TextPattern to Radiant CMS. It doesn’t work perfect, it is some manual work, but it did the trick for me, and that’s all I needed. Observe:
First of all, get your data from the textpattern database, and import it in the Radiant CMS database. I used a simple mysqldump command for this, and loaded it back.
db-server $ mysqldump database textpattern > dumpfile.mysql ...(copy)... devel-server $ mysql -u root site_development < dumpfile.mysql
A small note: I quickly loaded the dump in my editor and converted all the fieldnames to lower case before loading it back in the radiant database. You might want to do this also.
Lazy as I am, I quickly altered the table name to be plural, so Rails/Radiant wouldn't complain:
mysql> rename table textpattern to textpatterns;
Then I fired up Textmate and made this little script:
class Textpattern < ActiveRecord:Base; end u = User.find :first Textpattern.find(:all, :conditions => {:section => 'article'}).each do |textpattern| p = Page.new({ "virtual"=>false, "class_name"=>'Page', "slug"=>textpattern.url_title.downcase.strip.gsub(/\s+/,'-'), "updated_at"=>textpattern.lastmod, "title"=>textpattern.title, "created_by"=>u, "breadcrumb"=>textpattern.title, "lock_version"=>0, "enable_comments"=>0, "updated_by"=>u, "comments_count"=>0, "published_at"=>textpattern.posted, "status_id"=>100, "position"=>1, "layout_id"=>nil, "parent_id"=>87, "created_at"=>textpattern.lastmod}) do |newpage| newpage.parts.create({"name"=>"body", "filter_id"=>"Textile", "content"=>textpattern.body}) newpage.parts.create({"name"=>"summary", "filter_id"=>"Textile", "content"=>textpattern.excerpt}) end p.save! end
The first line will add a model for the Textpattern table we added, so we can use the ActiveRecord magic to access this table. The second line will load the first user it can find (I only had one, so no problems there).
From then on, we just get all the Textpatterns articles we want (a specific section in this case), and with each of these, I create a new page in radiant, and add pageparts to them, with good defaults.
Once done (and bugfixed), I simply copy-pasted this in a script/console session in my radiant-project. Done.
The defaults were stolen from a page I quickly created and published in Radiant, under the correct section. You need to pay attention to the “parent_id” for the Page-creation (get it from the database, or from the url when hovering it in the admin section), and the “name” for the PagePart creation sections.
Last work is to drop the added table from your database.
As I told you, quick-n-dirty, and nothing I’m really proud of, but I needed it fast, and I’ve published it here as it might help other people.
Tags: convert, radiant, radiant cms, rails, ruby, textpattern