Skip to content

Commit d1b9cc8

Browse files
author
Tom Copeland
committed
Implemented document migration. Fixed module enabling for documents.
1 parent f6fa498 commit d1b9cc8

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.rdoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Some notes on the differences between the GForge and the Redmine object models:
5555
* The GForge <tt>artifact_group_list</tt> table gets mapped into rows in the Redmine <tt>projects_trackers</tt> table (<tt>projects</tt> HABTM <tt>trackers</tt>). Redmine <tt>trackers</tt> are not per <tt>project</tt>; they are shared for the whole system. The current migration only provisions rows in the <tt>projects_trackers</tt> table as they are needed - e.g., a <tt>project</tt> won't get a "Bug" <tt>tracker</tt> unless there's a GForge <tt>artifact</tt> in a "Bug" GForge <tt>artifact_group_list</tt> in this project. If there's a GForge <tt>artifact_group_list</tt> with an unexpected name (e.g., "Tom's Issues") those get mapped into the "Bug" <tt>tracker</tt>.
5656
* GForge <tt>artifacts</tt> have only three statuses (open/closed/deleted) whereas Redmine issues have six possible <tt>IssueStatus</tt> settings, so I just map them over to the <tt>IssueStatus</tt> with the same name. GForge <tt>artifacts</tt> have five priority levels; these map onto Redmine's five standard <tt>IssueCategory</tt> values. GForge base64 encodes artifact files; Redmine stores the metadata as an <tt>Attachment</tt> and stores the data in the <tt>RAILS_ROOT/files</tt> directory.
5757
* The GForge forum system handles nested message threads whereas Redmine forum threads are flat (details at http://www.redmine.org/boards/1/topics/15509). So there's some lost information there, but, meh.
58+
* GForge documents had an option to store a URL as a document. I just convert these into a file containing only the URL.
5859

5960

6061
=== GForge table to Redmine table mapping
@@ -67,7 +68,7 @@ Some notes on the differences between the GForge and the Redmine object models:
6768
artifact_message journals
6869
artifact_monitor watchers
6970
artifact_status enumerations
70-
doc_data
71+
doc_data documents
7172
doc_groups document_categories
7273
filemodule_monitor
7374
forum messages

lib/tasks/gforge_models.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,31 @@ class GForgeDocument < GForgeTable
148148
# 5 | private
149149
set_table_name "doc_data"
150150
belongs_to :group, :class_name => "GForgeGroup", :foreign_key => 'group_id'
151+
belongs_to :user, :class_name => "GForgeUser", :foreign_key => 'created_by'
151152
belongs_to :document_group, :class_name => "GForgeDocumentGroup", :foreign_key => 'doc_group'
152153
named_scope :not_deleted, :conditions => "stateid != 2"
154+
def convert_to_redmine_document_in(document_category)
155+
document = document_category.project.documents.create!(:category => document_category, :title => title, :description => description, :created_on => Time.at(updatedate))
156+
if filetype == "URL"
157+
file = ActionController::UploadedTempfile.new(filename.gsub(/[^a-z]/, ""))
158+
file.binmode
159+
file.write(filename)
160+
file.original_path = filename.gsub(/[^a-z]/, "")
161+
file.rewind
162+
else
163+
# refactor this into a create_uploaded_temp_file_from(self)
164+
file = ActionController::UploadedTempfile.new(filename)
165+
file.binmode
166+
file.write(extract_content)
167+
file.original_path = filename
168+
file.rewind
169+
end
170+
attachment = document.attachments.create!(:description => description, :created_on => Time.at(updatedate), :author => create_or_fetch_user(user), :file => file)
171+
document
172+
end
173+
def extract_content
174+
Base64.decode64(data)
175+
end
153176
end
154177

155178
class GForgeArtifactMonitor < GForgeTable

lib/tasks/migrate_from_gforge.rake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace :redmine do
6262
)
6363
project.enabled_modules.create!(:name => "issue_tracking") if gforge_group.use_tracker
6464
project.enabled_modules.create!(:name => "boards") if gforge_group.use_forum
65-
project.enabled_modules.create!(:name => "document") if gforge_group.use_docman
65+
project.enabled_modules.create!(:name => "documents") if gforge_group.use_docman
6666
gforge_group.user_group.each do |user_group|
6767
user = create_or_fetch_user(user_group.user)
6868
if user_group.group_admin?
@@ -76,6 +76,11 @@ namespace :redmine do
7676
document_category = showing_migrated_ids(project) do
7777
document_group.convert_to_redmine_document_category_on(project)
7878
end
79+
document_group.documents.each do |gforge_document|
80+
gforge_document = showing_migrated_ids(document_category) do
81+
gforge_document.convert_to_redmine_document_in(document_category)
82+
end
83+
end
7984
end
8085
gforge_group.artifact_group_lists.each do |artifact_group_list|
8186
project.trackers << Tracker.find_by_name(artifact_group_list.corresponding_redmine_tracker_name) unless project.trackers.find_by_name(artifact_group_list.corresponding_redmine_tracker_name)

0 commit comments

Comments
 (0)