Changing attachment to use paperclip
This commit is contained in:
@@ -5,8 +5,7 @@ namespace :wordpress do
|
||||
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|
|
||||
%w(posts post_translations taggings tags).each do |table_name|
|
||||
p "Truncating #{table_name} ..."
|
||||
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||
end
|
||||
@@ -16,18 +15,23 @@ namespace :wordpress do
|
||||
desc "import blog data from a WordPressImport XML dump"
|
||||
task :import_blog, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
p "Loading XML from #{params[:file_name]} ..."
|
||||
dump = WordPressImport::Dump.new(params[:file_name])
|
||||
|
||||
dump.authors.each(&:to_refinery)
|
||||
p "Importing #{dump.authors.count} authors ..."
|
||||
dump.authors.each(&:to_rails)
|
||||
|
||||
# by default, import all; unless $ONLY_PUBLISHED = "true"
|
||||
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||
dump.posts(only_published).each(&:to_refinery)
|
||||
p "Importing #{dump.posts(only_published).count} posts ..."
|
||||
|
||||
if only_published
|
||||
p "(only published posts)"
|
||||
else
|
||||
p "(export ONLY_PUBLISHED=true to import only published posts)"
|
||||
end
|
||||
|
||||
WordPressImport::Post.create_blog_page_if_necessary
|
||||
|
||||
ENV["MODEL"] = 'BlogPost'
|
||||
Rake::Task["friendly_id:redo_slugs"].invoke
|
||||
ENV.delete("MODEL")
|
||||
dump.posts(only_published).each(&:to_rails)
|
||||
end
|
||||
|
||||
desc "reset blog tables and then import blog data from a WordPressImport XML dump"
|
||||
@@ -38,53 +42,53 @@ namespace :wordpress do
|
||||
end
|
||||
|
||||
|
||||
desc "Reset the cms relevant tables for a clean import"
|
||||
task :reset_pages do
|
||||
Rake::Task["environment"].invoke
|
||||
# desc "Reset the cms relevant tables for a clean import"
|
||||
# task :reset_pages do
|
||||
# Rake::Task["environment"].invoke
|
||||
|
||||
%w(page_part_translations page_translations page_parts pages).each do |table_name|
|
||||
p "Truncating #{table_name} ..."
|
||||
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||
end
|
||||
end
|
||||
# %w(page_part_translations page_translations page_parts pages).each do |table_name|
|
||||
# p "Truncating #{table_name} ..."
|
||||
# ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||
# end
|
||||
# end
|
||||
|
||||
desc "import cms data from a WordPress XML dump"
|
||||
task :import_pages, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
dump = WordPressImport::Dump.new(params[:file_name])
|
||||
# desc "import cms data from a WordPress XML dump"
|
||||
# task :import_pages, :file_name do |task, params|
|
||||
# Rake::Task["environment"].invoke
|
||||
# dump = WordPressImport::Dump.new(params[:file_name])
|
||||
|
||||
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||
dump.pages(only_published).each(&:to_refinery)
|
||||
# only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||
# dump.pages(only_published).each(&:to_rails)
|
||||
|
||||
# After all pages are persisted we can now create the parent - child
|
||||
# relationships. This is necessary, as WordPress doesn't dump the pages in
|
||||
# a correct order.
|
||||
dump.pages(only_published).each do |dump_page|
|
||||
page = ::Page.find(dump_page.post_id)
|
||||
page.parent_id = dump_page.parent_id
|
||||
page.save!
|
||||
end
|
||||
# # After all pages are persisted we can now create the parent - child
|
||||
# # relationships. This is necessary, as WordPress doesn't dump the pages in
|
||||
# # a correct order.
|
||||
# dump.pages(only_published).each do |dump_page|
|
||||
# page = ::Page.find(dump_page.post_id)
|
||||
# page.parent_id = dump_page.parent_id
|
||||
# page.save!
|
||||
# end
|
||||
|
||||
WordPressImport::Post.create_blog_page_if_necessary
|
||||
# WordPressImport::Post.create_blog_page_if_necessary
|
||||
|
||||
ENV["MODEL"] = 'Page'
|
||||
Rake::Task["friendly_id:redo_slugs"].invoke
|
||||
ENV.delete("MODEL")
|
||||
end
|
||||
# ENV["MODEL"] = 'Page'
|
||||
# Rake::Task["friendly_id:redo_slugs"].invoke
|
||||
# ENV.delete("MODEL")
|
||||
# end
|
||||
|
||||
desc "reset cms tables and then import cms data from a WordPress XML dump"
|
||||
task :reset_and_import_pages, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
Rake::Task["wordpress:reset_pages"].invoke
|
||||
Rake::Task["wordpress:import_pages"].invoke(params[:file_name])
|
||||
end
|
||||
# desc "reset cms tables and then import cms data from a WordPress XML dump"
|
||||
# task :reset_and_import_pages, :file_name do |task, params|
|
||||
# Rake::Task["environment"].invoke
|
||||
# Rake::Task["wordpress:reset_pages"].invoke
|
||||
# Rake::Task["wordpress:import_pages"].invoke(params[:file_name])
|
||||
# end
|
||||
|
||||
|
||||
desc "Reset the media relevant tables for a clean import"
|
||||
task :reset_media do
|
||||
Rake::Task["environment"].invoke
|
||||
|
||||
%w(images resources).each do |table_name|
|
||||
%w(rich_rich_files).each do |table_name|
|
||||
p "Truncating #{table_name} ..."
|
||||
ActiveRecord::Base.connection.execute "DELETE FROM #{table_name}"
|
||||
end
|
||||
@@ -95,13 +99,14 @@ namespace :wordpress do
|
||||
Rake::Task["environment"].invoke
|
||||
dump = WordPressImport::Dump.new(params[:file_name])
|
||||
|
||||
attachments = dump.attachments.each(&:to_refinery)
|
||||
p "Importing #{dump.attachments.each_slice(25).first.count} attachments ..."
|
||||
attachments = dump.attachments.each_slice(25).first.each(&:to_rails)
|
||||
p "Errors were encountered: #{$ATTACHMENT_EXCEPTIONS.inspect}" unless $ATTACHMENT_EXCEPTIONS.blank?
|
||||
|
||||
# parse all created BlogPost and Page bodys and replace the old wordpress media uls
|
||||
# parse all created Post and Page bodys and replace the old wordpress media urls
|
||||
# with the newly created ones
|
||||
attachments.each do |attachment|
|
||||
attachment.replace_url
|
||||
end
|
||||
p "Replacing attachment URLs found in posts/pages ..."
|
||||
attachments.each(&:replace_url)
|
||||
end
|
||||
|
||||
desc "reset media tables and then import media data from a WordPress XML dump"
|
||||
@@ -115,7 +120,16 @@ namespace :wordpress do
|
||||
task :full_import, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
Rake::Task["wordpress:reset_and_import_blog"].invoke(params[:file_name])
|
||||
Rake::Task["wordpress:reset_and_import_pages"].invoke(params[:file_name])
|
||||
Rake::Task["wordpress:reset_import_and_replace_media"].invoke(params[:file_name])
|
||||
#Rake::Task["wordpress:reset_and_import_pages"].invoke(params[:file_name])
|
||||
#Rake::Task["wordpress:reset_import_and_replace_media"].invoke(params[:file_name])
|
||||
Rake::Task["wordpress:import_and_replace_media"].invoke(params[:file_name])
|
||||
end
|
||||
|
||||
|
||||
desc "Local First master import (no resets)"
|
||||
task :lfa_import, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
Rake::Task["wordpress:import_blog"].invoke(params[:file_name])
|
||||
Rake::Task["wordpress:import_and_replace_media"].invoke(params[:file_name])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user