Created
August 10, 2017 05:05
-
-
Save stknohg/0ce7a55675258a5d119528732f70fb3e to your computer and use it in GitHub Desktop.
Redmine 3.4.2でrake redmine:migrate_from_tracをエラー無く動作させるためのパッチ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ./migrate_from_trac.rake.orig 2017-08-03 16:07:49.723977200 +0900 | |
+++ ./migrate_from_trac.rake 2017-08-10 13:49:36.119965400 +0900 | |
@@ -118,7 +118,7 @@ namespace :redmine do | |
class TracAttachment < ActiveRecord::Base | |
self.table_name = :attachment | |
- set_inheritance_column :none | |
+ self.inheritance_column = :none | |
def time; Time.at(read_attribute(:time)) end | |
@@ -163,14 +163,14 @@ namespace :redmine do | |
class TracTicket < ActiveRecord::Base | |
self.table_name = :ticket | |
- set_inheritance_column :none | |
+ self.inheritance_column = :none | |
# ticket changes: only migrate status changes and comments | |
has_many :ticket_changes, :class_name => "TracTicketChange", :foreign_key => :ticket | |
has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket | |
def attachments | |
- TracMigrate::TracAttachment.all(:conditions => ["type = 'ticket' AND id = ?", self.id.to_s]) | |
+ TracMigrate::TracAttachment.where("type = 'ticket' AND id = :id", id: self.id.to_s) | |
end | |
def ticket_type | |
@@ -210,7 +210,7 @@ namespace :redmine do | |
class TracWikiPage < ActiveRecord::Base | |
self.table_name = :wiki | |
- set_primary_key :name | |
+ self.primary_key = 'name' | |
def self.columns | |
# Hides readonly Trac field to prevent clash with AR readonly? method (Rails 2.0) | |
@@ -218,7 +218,7 @@ namespace :redmine do | |
end | |
def attachments | |
- TracMigrate::TracAttachment.all(:conditions => ["type = 'wiki' AND id = ?", self.id.to_s]) | |
+ TracMigrate::TracAttachment.where("type = 'wiki' AND id = :id", id: self.id.to_s) | |
end | |
def time; Time.at(read_attribute(:time)) end | |
@@ -419,7 +419,7 @@ namespace :redmine do | |
p.save | |
v = Version.new :project => @target_project, | |
- :name => encode(milestone.name[0, limit_for(Version, 'name')]), | |
+ :name => encode(milestone.name), | |
:description => nil, | |
:wiki_page_title => milestone.name.to_s, | |
:effective_date => milestone.completed | |
@@ -469,7 +469,7 @@ namespace :redmine do | |
print '.' | |
STDOUT.flush | |
i = Issue.new :project => @target_project, | |
- :subject => encode(ticket.summary[0, limit_for(Issue, 'subject')]), | |
+ :subject => encode(ticket.summary), | |
:description => convert_wiki_text(encode(ticket.description)), | |
:priority => PRIORITY_MAPPING[ticket.priority] || DEFAULT_PRIORITY, | |
:created_on => ticket.time | |
@@ -595,10 +595,10 @@ namespace :redmine do | |
puts "Components: #{migrated_components}/#{TracComponent.count}" | |
puts "Milestones: #{migrated_milestones}/#{TracMilestone.count}" | |
puts "Tickets: #{migrated_tickets}/#{TracTicket.count}" | |
- puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count(:conditions => {:type => 'ticket'}).to_s | |
+ puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.where(type: 'ticket').count().to_s | |
puts "Custom values: #{migrated_custom_values}/#{TracTicketCustom.count}" | |
puts "Wiki edits: #{migrated_wiki_edits}/#{wiki_edit_count}" | |
- puts "Wiki files: #{migrated_wiki_attachments}/" + TracAttachment.count(:conditions => {:type => 'wiki'}).to_s | |
+ puts "Wiki files: #{migrated_wiki_attachments}/" + TracAttachment.where(type: 'wiki').count().to_s | |
end | |
def self.limit_for(klass, attribute) |
はじめまして。 > @stknohg
こちらのパッチをベースにTrac 1.0 (Trac-1.0.3 EPEL RPM) から Redmine 3.4.13に移行する目星がつきました。
ところで、ブログ記事の画面キャプチャは、
Wiki files: 0/3
でしたが、添付ファイルの移行はできましたか?(って何年も前の話ですが)
本パッチをベースにタイムスタンプ対応をいれましたが、
Ticket files: 0/N
Wiki files: 0/N
だったので別のパッチを統合しattachementsも移行できました。
感謝とご報告まで。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
このパッチについて
これはRedmine 3.4.2において、
rake redmine:migrate_from_trac
コマンドを実行した際にエラーになるのを解消するためのパッチとなります。RedmineMigrateが新しいバージョンのRails、特にActiveRecordの変化に対応できていなかった部分を修正しています。
対象バージョン
Redmine 3.4.2
やっていること
古いAtiveRecordの機能を呼んでエラーとなっているところをエラー無く動作する様に直しています。
単純にエラーを出ない様にしているだけなので、新しいバージョンのTracには対応していません。
(RedmineMigrate自体がTrac 0.11~0.12向けの様なので...)
適用方法
[Redmineのインストール先]/lib/tasks/migrate_from_trac.rake
に対してPatchコマンドなどでこのパッチを適用します。適用例)
patch -u ./migrate_from_trac.rake < ./migrate_from_trac-redmine.3.4.2.diff
補足
Trac 0.12が移行対象の場合はこちらのパッチも適用しておくと良いでしょう。