Class: Migrator::Wikis::MigrateFromDb

Inherits:
Object
  • Object
show all
Defined in:
lib/tractive/migrator/wikis/migrate_from_db.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MigrateFromDb

Returns a new instance of MigrateFromDb.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tractive/migrator/wikis/migrate_from_db.rb', line 8

def initialize(args)
  $logger.debug("OPTIONS = #{args}")

  @config = args[:cfg]
  @options = args[:opts]
  @authors_map = @config["users"].to_h

  @tracticketbaseurl    = @config["trac"]["ticketbaseurl"]
  @git_repo             = @config["github"]["repo"]
  @changeset_base_url   = @config["trac"]["changeset_base_url"] || ""
  @revmap_path          = @config["revmap_path"]
  @attachments_hashed   = @config.dig("wiki", "attachments", "hashed")

  @wiki_attachments_url = @options["attachment-base-url"] || @config.dig("wiki", "attachments", "url") || ""
  @repo_path            = @options["repo-path"] || ""
  @home_page_name       = @options["home-page-name"]
  @wiki_extensions      = @options["wiki-extensions"]
  @source_folders       = @options["source-folders"]

  @attachment_options   = {
    hashed: @attachments_hashed
  }

  verify_options
  verify_locations

  @twf_to_markdown = Migrator::Converter::TwfToMarkdown.new(
    @tracticketbaseurl,
    @attachment_options,
    @changeset_base_url,
    @wiki_attachments_url,
    @revmap_path,
    git_repo: @git_repo,
    home_page_name: @home_page_name,
    wiki_extensions: @wiki_extensions,
    source_folders: @source_folders
  )
end

Instance Method Details

#migrate_wikisObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tractive/migrator/wikis/migrate_from_db.rb', line 47

def migrate_wikis
  $logger.info("Processing the wiki...")

  Dir.chdir(@options["repo-path"]) do
    # For every version of every file in the wiki...
    Tractive::Wiki.for_migration.each do |wiki|
      next if skip_file(wiki[:name])

      comment = if wiki[:comment].nil? || wiki[:comment].empty?
                  "Initial load of version #{wiki[:version]} of trac-file #{wiki[:name]}"
                else
                  wiki[:comment].gsub('"', '\"')
                end

      file_name = filename_for_wiki(wiki)

      $logger.info("Working with file [#{file_name}]")
      $logger.debug("Object: #{wiki}")

      wiki_markdown_text = @twf_to_markdown.convert(wiki[:text], id: wiki[:name])
      wiki_markdown_text += wiki_attachments(wiki)

      # Create file with content
      File.open(file_name, "w") do |f|
        f.puts(wiki_markdown_text)
      end

      # git-add it
      unless execute_command("git add #{file_name}").success?
        $logger.error("ERROR at git-add #{file_name}!!!")
        exit(1)
      end

      author = generate_author(wiki[:author])

      # git-commit it
      commit_command = "git commit --allow-empty -m \"#{comment}\" --author \"#{author}\" --date \"#{wiki[:fixeddate]}\""
      unless execute_command(commit_command).success?
        $logger.error("ERROR at git-commit #{file_name}!!!")
        exit(1)
      end
    end
  end
end