summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 20:48:21 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-10 20:48:21 +0300
commit0415566b3796f500e7f694a0aee4882752d150c1 (patch)
treea4e5ae3bca16a41d99a62098bd3beb30566df0ad /lib
parent86e368a8af35fb0f09369630a226c80dc16ae5ec (diff)
downloadgitlab-ce-0415566b3796f500e7f694a0aee4882752d150c1.tar.gz
Remove wiki migrator. We dont need it any more. Users should migrate to 5.0 first
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/migrate/migrate_wiki.rake42
-rw-r--r--lib/wiki_to_gollum_migrator.rb124
2 files changed, 0 insertions, 166 deletions
diff --git a/lib/tasks/migrate/migrate_wiki.rake b/lib/tasks/migrate/migrate_wiki.rake
deleted file mode 100644
index 5d9881e45db..00000000000
--- a/lib/tasks/migrate/migrate_wiki.rake
+++ /dev/null
@@ -1,42 +0,0 @@
-namespace :gitlab do
- namespace :wiki do
-
- # This task will migrate all of the existing Wiki
- # content stored in your database into the new
- # Gollum Wiki system. A new repository named
- # namespace/project.wiki.git will be created for
- # each project that currently has Wiki pages in
- # the database.
- #
- # Notes:
- # * The existing Wiki content will remain in your
- # database in-tact.
- desc "GITLAB | Migrate Wiki content from database to Gollum repositories."
- task :migrate => :environment 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
deleted file mode 100644
index ed6a1700631..00000000000
--- a/lib/wiki_to_gollum_migrator.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-class WikiToGollumMigrator
-
- attr_reader :projects
-
- def initialize
- @projects = []
-
- Project.find_in_batches(batch_size: 50) do |batch|
- batch.each { |p| @projects << p if p.wikis.any? }
- end
- end
-
- def migrate!
- projects.each do |project|
- log "\nMigrating Wiki for '#{project.path_with_namespace}'"
- wiki = create_gollum_repo(project)
- create_pages project, wiki
- log "Project '#{project.path_with_namespace}' migrated. " + "[OK]".green
- 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
-
- pages.each do |page|
- create_page_and_revisions(project, page)
- end
- end
-
- def create_page_and_revisions(project, page)
- # Grab all revisions of the page
- revisions = project.wikis.where(slug: page.slug).ordered.all
-
- # Remove the first revision created from the array
- # and use it to create the Gollum page. Each successive revision
- # will then be applied to the new Gollum page as an update.
- first_rev = revisions.pop
-
- wiki = GollumWiki.new(project, page.user)
- wiki_page = WikiPage.new(wiki)
-
- 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
-
- # Reverse the revisions to create them in the correct
- # chronological order.
- create_revisions(project, wiki_page, revisions.reverse)
- else
- log " Failed to create page '#{wiki_page.title}' " + "[FAILED]".red
- end
- end
-
- def create_revisions(project, page, revisions)
- log " Creating revisions..."
- revisions.each do |revision|
- # 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, project)
-
- content = attributes[:content]
-
- if wiki_page.update(content)
- log " Created revision " + "[OK]".green
- else
- log " Failed to create revision " + "[FAILED]".red
- end
- end
- end
-
- 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 slug.downcase == "index"
- attributes[:title] = "home" unless home_already_exists?(project)
- end
-
- attributes
- end
-
- def home_already_exists?(project)
- project.wikis.where(slug: 'home').any? || project.wikis.where(slug: 'Home').any?
- end
-
- def log(message)
- puts message
- end
-
-end