Started on cms page import
* created rake tasks * still needed: cleanups, more tests and docs
This commit is contained in:
parent
dacd503d8f
commit
e1c60163e4
|
@ -5,7 +5,8 @@ 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(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
|
||||
|
@ -22,12 +23,13 @@ namespace :wordpress do
|
|||
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||
dump.posts(only_published).each(&:to_refinery)
|
||||
|
||||
Refinery::WordPress::Post.create_blog_page_if_necessary
|
||||
|
||||
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
|
||||
|
@ -35,4 +37,45 @@ namespace :wordpress do
|
|||
Rake::Task["wordpress:import_blog"].invoke(params[:file_name])
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
|
||||
desc "import cms data from a Refinery::WordPress XML dump"
|
||||
task :import_pages, :file_name do |task, params|
|
||||
Rake::Task["environment"].invoke
|
||||
dump = Refinery::WordPress::Dump.new(params[:file_name])
|
||||
|
||||
only_published = ENV['ONLY_PUBLISHED'] == 'true' ? true : false
|
||||
dump.pages(only_published).each(&:to_refinery)
|
||||
|
||||
# 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
|
||||
|
||||
Refinery::WordPress::Post.create_blog_page_if_necessary
|
||||
|
||||
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 Refinery::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
|
||||
end
|
||||
|
|
|
@ -19,10 +19,13 @@ module Refinery
|
|||
end
|
||||
end
|
||||
|
||||
def pages
|
||||
doc.xpath("//item[wp:post_type = 'page']").collect do |page|
|
||||
def pages(only_published=false)
|
||||
pages = doc.xpath("//item[wp:post_type = 'page']").collect do |page|
|
||||
Page.new(page)
|
||||
end
|
||||
|
||||
pages = pages.select(&:published?) if only_published
|
||||
pages
|
||||
end
|
||||
|
||||
def posts(only_published=false)
|
||||
|
|
|
@ -36,7 +36,6 @@ module Refinery
|
|||
# [ruby]p "Hello World"[/ruby]
|
||||
# -> <pre class="brush: ruby">p "Hello world"</pre>
|
||||
formatted.gsub!(/\[(\w+)\](.+?)\[\/\1\]/m, '<pre class="brush: \1">\2</pre>')
|
||||
#formatted.gsub!(/\[\/\w+\]/, '</pre>')
|
||||
|
||||
# remove all tags inside <pre> that simple_format created
|
||||
# TODO: replace simple_format with a method, that ignores pre-tags
|
||||
|
@ -60,7 +59,8 @@ module Refinery
|
|||
end
|
||||
|
||||
def parent_id
|
||||
node.xpath("wp:post_parent").text.to_i
|
||||
dump_id = node.xpath("wp:post_parent").text.to_i
|
||||
dump_id == 0 ? nil : dump_id
|
||||
end
|
||||
|
||||
def status
|
||||
|
@ -80,8 +80,8 @@ module Refinery
|
|||
end
|
||||
|
||||
def to_refinery
|
||||
page = ::Page.create!(:title => title, :created_at => post_date,
|
||||
:draft => draft?, :parent_id => parent_id)
|
||||
page = ::Page.create!(:id => post_id, :title => title,
|
||||
:created_at => post_date, :draft => draft?)
|
||||
|
||||
page.parts.create(:title => 'Body', :body => content_formatted)
|
||||
page
|
||||
|
@ -95,7 +95,6 @@ module Refinery
|
|||
|
||||
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
||||
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
|
||||
#text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
||||
text.insert 0, start_tag
|
||||
|
||||
text.html_safe.safe_concat("</p>")
|
||||
|
|
|
@ -61,6 +61,25 @@ module Refinery
|
|||
|
||||
post
|
||||
end
|
||||
|
||||
def self.create_blog_page_if_necessary
|
||||
# refinerycms wants a page at /blog, so let's make sure there is one
|
||||
# taken from the original db seeds from refinery-blog
|
||||
unless ::Page.where("link_url = ?", '/blog').exists?
|
||||
page = ::Page.create(
|
||||
:title => "Blog",
|
||||
:link_url => "/blog",
|
||||
:deletable => false,
|
||||
:position => ((::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
||||
:menu_match => "^/blogs?(\/|\/.+?|)$"
|
||||
)
|
||||
|
||||
::Page.default_parts.each do |default_page_part|
|
||||
page.parts.create(:title => default_page_part, :body => nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user