2011-06-01 19:11:57 +00:00
|
|
|
require 'nokogiri'
|
|
|
|
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 12:41:31 +00:00
|
|
|
%w(taggings tags blog_comments blog_categories 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
|
|
|
|
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)
|
|
|
|
dump.posts.each(&:to_refinery)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
|
|
|
|
desc "Import data from a Refinery::WordPress XML dump"
|
|
|
|
task :import, :file_name do |task, params|
|
|
|
|
Rake::Task["environment"].invoke
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "New import (testing)"
|
|
|
|
task :new_import, :file_name do |task, params|
|
|
|
|
Rake::Task["environment"].invoke
|
|
|
|
|
|
|
|
file_name = File.absolute_path(params[:file_name])
|
|
|
|
unless File.file?(file_name) && File.readable?(file_name)
|
|
|
|
raise "Given file '#{file_name}' no file or not readable."
|
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
dump = Refinery::WordPress::Dump.new(file_name)
|
2011-06-01 19:11:57 +00:00
|
|
|
p dump.authors
|
|
|
|
p dump.pages
|
|
|
|
dump.posts.each do |post|
|
|
|
|
p post.title
|
|
|
|
p post.categories
|
|
|
|
p post.tags
|
|
|
|
p post.creator
|
|
|
|
#p post.content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
desc "Import data from a Refinery::WordPress XML dump into a clean database (reset first)"
|
2011-06-01 19:11:57 +00:00
|
|
|
task :import_clean, :file_name do |task, params|
|
|
|
|
Rake::Task["wordpress:reset"].invoke
|
|
|
|
Rake::Task["wordpress:import"].invoke(params[:file_name])
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|