diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-17 04:48:27 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-03-17 04:48:27 -0700 |
commit | a96e0ec57ef6ae129a1adb54e5b9b67d8ffb04b3 (patch) | |
tree | 6cf64c471f4573c1b181f528e3c98fc3866103ab /lib | |
parent | c367cc5ca66c0d59c0e5228ed1724023ea6ad06e (diff) | |
parent | 330fe4162eea06dbcf2cd498fe35436163093e40 (diff) | |
download | gitlab-ce-a96e0ec57ef6ae129a1adb54e5b9b67d8ffb04b3.tar.gz |
Merge pull request #3240 from DanKnox/fix_wiki_migrator
Fix Wiki migration task and add more test coverage.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tasks/gitlab/migrate_wiki.rake | 22 | ||||
-rw-r--r-- | lib/wiki_to_gollum_migrator.rb | 33 |
2 files changed, 49 insertions, 6 deletions
diff --git a/lib/tasks/gitlab/migrate_wiki.rake b/lib/tasks/gitlab/migrate_wiki.rake index 9b2f34c6b19..5d9881e45db 100644 --- a/lib/tasks/gitlab/migrate_wiki.rake +++ b/lib/tasks/gitlab/migrate_wiki.rake @@ -16,5 +16,27 @@ namespace :gitlab do wiki_migrator = WikiToGollumMigrator.new wiki_migrator.migrate! end + + # This task will destroy all of the Wiki repos + # that the Wiki migration task created. Run this + # to clean up your environment if you experienced + # problems during the original migration. After + # executing this task, you can attempt the original + # migration again. + # + # Notes: + # * This will not affect Wikis that have been created + # as Gollum Wikis only. It will only remove the wikis + # for the repositories that have old Wiki data in the + # dataabase. + # * If you have any repositories already named + # namespace/project.wiki that you do not wish + # to be removed you may want to perform a manual + # cleanup instead. + desc "GITLAB | Remove the Wiki repositories created by the `gitlab:wiki:migrate` task." + task :rollback => :environment do + wiki_migrator = WikiToGollumMigrator.new + wiki_migrator.rollback! + end end end diff --git a/lib/wiki_to_gollum_migrator.rb b/lib/wiki_to_gollum_migrator.rb index 6083533b7e2..ed6a1700631 100644 --- a/lib/wiki_to_gollum_migrator.rb +++ b/lib/wiki_to_gollum_migrator.rb @@ -19,12 +19,30 @@ class WikiToGollumMigrator end end + def rollback! + log "\nBeginning Wiki Migration Rollback..." + projects.each do |project| + destroy_gollum_repo project + end + log "\nWiki Rollback Complete." + end + private def create_gollum_repo(project) GollumWiki.new(project, nil).wiki end + def destroy_gollum_repo(project) + log " Removing Wiki repo for project: #{project.path_with_namespace}" + path = GollumWiki.new(project, nil).path_with_namespace + if Gitlab::Shell.new.remove_repository(path) + log " Wiki destroyed successfully. " + "[OK}".green + else + log " Problem destroying wiki. Please remove it manually. " + "[FAILED]".red + end + end + def create_pages(project, wiki) pages = project.wikis.group(:slug).all @@ -45,8 +63,9 @@ class WikiToGollumMigrator wiki = GollumWiki.new(project, page.user) wiki_page = WikiPage.new(wiki) - attributes = extract_attributes_from_page(first_rev) + attributes = extract_attributes_from_page(first_rev, project) + log " Creating page '#{first_rev.title}'..." if wiki_page.create(attributes) log " Created page '#{wiki_page.title}' " + "[OK]".green @@ -59,15 +78,15 @@ class WikiToGollumMigrator end def create_revisions(project, page, revisions) + log " Creating revisions..." revisions.each do |revision| - log " Creating revisions..." # Reinitialize a new GollumWiki instance for each page # and revision created so the correct User is shown in # the commit message. wiki = GollumWiki.new(project, revision.user) wiki_page = wiki.find_page(page.slug) - attributes = extract_attributes_from_page(revision) + attributes = extract_attributes_from_page(revision, project) content = attributes[:content] @@ -79,13 +98,15 @@ class WikiToGollumMigrator end end - def extract_attributes_from_page(page) + def extract_attributes_from_page(page, project) attributes = page.attributes .with_indifferent_access .slice(:title, :content) + slug = page.slug + # Change 'index' pages to 'home' pages to match Gollum standards - if attributes[:title].downcase == "index" + if slug.downcase == "index" attributes[:title] = "home" unless home_already_exists?(project) end @@ -93,7 +114,7 @@ class WikiToGollumMigrator end def home_already_exists?(project) - project.wikis.where(title: 'home').any? || project.wikis.where(title: 'Home').any? + project.wikis.where(slug: 'home').any? || project.wikis.where(slug: 'Home').any? end def log(message) |