2011-06-01 19:11:57 +00:00
|
|
|
require 'wordpress'
|
|
|
|
|
|
|
|
namespace :wordpress do
|
|
|
|
desc "Reset the blog relevant tables for a clean import"
|
2011-06-02 12:41:31 +00:00
|
|
|
task :reset_blog do
|
2011-06-01 19:11:57 +00:00
|
|
|
Rake::Task["environment"].invoke
|
|
|
|
|
2011-06-02 19:32:58 +00:00
|
|
|
%w(taggings tags blog_comments blog_categories blog_categories_blog_posts blog_posts).each do |table_name|
|
2011-06-01 19:11:57 +00:00
|
|
|
p "Truncating #{table_name} ..."
|
2011-06-02 12:41:31 +00:00
|
|
|
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 14:22:50 +00:00
|
|
|
end
|
2011-06-02 12:41:31 +00:00
|
|
|
|
|
|
|
desc "import blog data from a Refinery::WordPress XML dump"
|
|
|
|
task :import_blog, :file_name do |task, params|
|
2011-06-01 19:11:57 +00:00
|
|
|
Rake::Task["environment"].invoke
|
2011-06-02 12:41:31 +00:00
|
|
|
dump = Refinery::WordPress::Dump.new(params[:file_name])
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
dump.authors.each(&:to_refinery)
|
2011-06-03 09:35:11 +00:00
|
|
|
|
|
|
|
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
|
|
|
dump.posts(only_published).each(&:to_refinery)
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 14:22:50 +00:00
|
|
|
ENV["MODEL"] = 'BlogPost'
|
|
|
|
Rake::Task["friendly_id:redo_slugs"].invoke
|
2011-06-03 09:35:11 +00:00
|
|
|
ENV.delete("MODEL")
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-06-02 14:22:50 +00:00
|
|
|
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])
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|