1. Ebrahim Mohammadi
  2. redmine_merge_redmine

Commits

Mohammad Ebrahim Mohammadi Panah  committed 2965838

Fixed migration of wiki pages with deep hierarchies using a recursive solution

  • Participants
  • Parent commits 0ba6bd9
  • Branches default

Comments (0)

Files changed (1)

File app/models/source_wiki_page.rb

View file
  • Ignore whitespace
   set_table_name :wiki_pages
 
   def self.migrate
-    all(:order => 'parent_id ASC').each do |source_wiki_page|
-
-      wiki_page = WikiPage.create!(source_wiki_page.attributes) do |wp|
-        wp.wiki = Wiki.find(RedmineMerge::Mapper.get_new_wiki_id(source_wiki_page.wiki_id))
-        wp.parent = WikiPage.find(RedmineMerge::Mapper.get_new_wiki_page_id(source_wiki_page.parent_id)) if source_wiki_page.parent_id
-      end
-
-      RedmineMerge::Mapper.add_wiki_page(source_wiki_page.id, wiki_page.id)
+    all.each do |source_wiki_page|
+      recursive_migrate source_wiki_page.id
     end
   end
+
+  def self.recursive_migrate(source_wiki_page_id)
+    # Return if already migrated
+    if new_id = RedmineMerge::Mapper.get_new_wiki_page_id(source_wiki_page_id)
+		return new_id
+	end
+
+    source_wiki_page = SourceWikiPage.find(source_wiki_page_id)
+    wiki_page = WikiPage.create(source_wiki_page.attributes)
+    wiki_page.wiki = Wiki.find(RedmineMerge::Mapper.get_new_wiki_id(source_wiki_page.wiki_id))
+    wiki_page.parent = WikiPage.find(recursive_migrate(source_wiki_page.parent_id)) if source_wiki_page.parent_id?
+    wiki_page.save()
+
+    RedmineMerge::Mapper.add_wiki_page(source_wiki_page.id, wiki_page.id)
+
+    return wiki_page.id
+  end
 end