wordpress-import/lib/tasks/wordpress.rake
Marc Remolt 29bc2534b6 It is now possible to ignore draft posts on import.
* refactored the code sent by SustainableWebsites
* made the ignore feature optional via ENV variable
* added docs
2011-06-03 11:35:11 +02:00

39 lines
1.2 KiB
Ruby

require 'wordpress'
namespace :wordpress do
desc "Reset the blog relevant tables for a clean import"
task :reset_blog do
Rake::Task["environment"].invoke
%w(taggings tags blog_comments blog_categories blog_categories_blog_posts blog_posts).each do |table_name|
p "Truncating #{table_name} ..."
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
end
end
desc "import blog data from a Refinery::WordPress XML dump"
task :import_blog, :file_name do |task, params|
Rake::Task["environment"].invoke
dump = Refinery::WordPress::Dump.new(params[:file_name])
dump.authors.each(&:to_refinery)
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
dump.posts(only_published).each(&:to_refinery)
ENV["MODEL"] = 'BlogPost'
Rake::Task["friendly_id:redo_slugs"].invoke
ENV.delete("MODEL")
end
desc "reset blog tables and then import blog data from a Refinery::WordPress XML dump"
task :reset_and_import_blog, :file_name do |task, params|
Rake::Task["environment"].invoke
Rake::Task["wordpress:reset_blog"].invoke
Rake::Task["wordpress:import_blog"].invoke(params[:file_name])
end
end