ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

migrate_from_trac.rake.diff

Mike Pestorich, 2011-11-25 06:01 am

Download (6.1 kB)

 
b/lib/tasks/migrate_from_trac.rake
91 91
        # If this attribute is set a milestone has a defined target timepoint
92 92
        def due
93 93
          if read_attribute(:due) && read_attribute(:due) > 0
94
            Time.at(read_attribute(:due)).to_date
94
            Time.at(read_attribute(:due)/1000000.0).to_date
95 95
          else
96 96
            nil
97 97
          end
......
99 99
        # This is the real timepoint at which the milestone has finished.
100 100
        def completed
101 101
          if read_attribute(:completed) && read_attribute(:completed) > 0
102
            Time.at(read_attribute(:completed)).to_date
102
            Time.at(read_attribute(:completed)/1000000.0).to_date
103 103
          else
104 104
            nil
105 105
          end
......
119 119
        set_table_name :attachment
120 120
        set_inheritance_column :none
121 121

  
122
        def time; Time.at(read_attribute(:time)) end
122
        def time; Time.at(read_attribute(:time)/1000000.0) end
123 123

  
124 124
        def original_filename
125 125
          filename
......
161 161
        set_inheritance_column :none
162 162

  
163 163
        # ticket changes: only migrate status changes and comments
164
        has_many :changes, :class_name => "TracTicketChange", :foreign_key => :ticket
165
        has_many :attachments, :class_name => "TracAttachment",
164
        has_many :changes, :class_name => "TracMigrate::TracTicketChange", :foreign_key => :ticket
165
        has_many :attachments, :class_name => "TracMigrate::TracAttachment",
166 166
                               :finder_sql => "SELECT DISTINCT attachment.* FROM #{TracMigrate::TracAttachment.table_name}" +
167 167
                                              " WHERE #{TracMigrate::TracAttachment.table_name}.type = 'ticket'" +
168 168
                                              ' AND #{TracMigrate::TracAttachment.table_name}.id = \'#{TracMigrate::TracAttachment.connection.quote_string(id.to_s)}\''
169
        has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket
169
        has_many :customs, :class_name => "TracMigrate::TracTicketCustom", :foreign_key => :ticket
170 170

  
171 171
        def ticket_type
172 172
          read_attribute(:type)
......
180 180
          read_attribute(:description).blank? ? summary : read_attribute(:description)
181 181
        end
182 182

  
183
        def time; Time.at(read_attribute(:time)) end
184
        def changetime; Time.at(read_attribute(:changetime)) end
183
        def time; Time.at(read_attribute(:time)/1000000.0) end
184
        def changetime; Time.at(read_attribute(:changetime)/1000000.0) end
185 185
      end
186 186

  
187 187
      class TracTicketChange < ActiveRecord::Base
188 188
        set_table_name :ticket_change
189 189

  
190
        def time; Time.at(read_attribute(:time)) end
190
        def time; Time.at(read_attribute(:time)/1000000.0) end
191 191
      end
192 192

  
193 193
      TRAC_WIKI_PAGES = %w(InterMapTxt InterTrac InterWiki RecentChanges SandBox TracAccessibility TracAdmin TracBackup TracBrowser TracCgi TracChangeset \
......
202 202
        set_table_name :wiki
203 203
        set_primary_key :name
204 204

  
205
        has_many :attachments, :class_name => "TracAttachment",
205
        has_many :attachments, :class_name => "TracMigrate::TracAttachment",
206 206
                               :finder_sql => "SELECT DISTINCT attachment.* FROM #{TracMigrate::TracAttachment.table_name}" +
207 207
                                      " WHERE #{TracMigrate::TracAttachment.table_name}.type = 'wiki'" +
208 208
                                      ' AND #{TracMigrate::TracAttachment.table_name}.id = \'#{TracMigrate::TracAttachment.connection.quote_string(id.to_s)}\''
......
212 212
          super.select {|column| column.name.to_s != 'readonly'}
213 213
        end
214 214

  
215
        def time; Time.at(read_attribute(:time)) end
215
        def time; Time.at(read_attribute(:time)/1000000.0) end
216 216
      end
217 217

  
218 218
      class TracPermission < ActiveRecord::Base
......
487 487
              comment_change = changeset.select {|change| change.field == 'comment'}.first
488 488

  
489 489
              n = Journal.new :notes => (comment_change ? convert_wiki_text(encode(comment_change.newvalue)) : ''),
490
                              :created_on => time
490
                              :created_at => time
491 491
              n.user = find_or_create_user(changeset.first.author)
492 492
              n.journalized = i
493 493
              if status_change &&
494 494
                   STATUS_MAPPING[status_change.oldvalue] &&
495 495
                   STATUS_MAPPING[status_change.newvalue] &&
496 496
                   (STATUS_MAPPING[status_change.oldvalue] != STATUS_MAPPING[status_change.newvalue])
497
                n.details << JournalDetail.new(:property => 'attr',
498
                                               :prop_key => 'status_id',
499
                                               :old_value => STATUS_MAPPING[status_change.oldvalue].id,
500
                                               :value => STATUS_MAPPING[status_change.newvalue].id)
497
                n.changes.merge({
498
                               'status_id' => [
499
                                               STATUS_MAPPING[status_change.oldvalue].id,
500
                                               STATUS_MAPPING[status_change.newvalue].id]
501
                })
501 502
              end
502 503
              if resolution_change
503
                n.details << JournalDetail.new(:property => 'cf',
504
                                               :prop_key => custom_field_map['resolution'].id,
505
                                               :old_value => resolution_change.oldvalue,
506
                                               :value => resolution_change.newvalue)
504
                n.changes.merge({
505
                               custom_field_map['resolution'].id => [
506
                                               resolution_change.oldvalue,
507
                                               resolution_change.newvalue
508
                               ]
509
                })
507 510
              end
508 511
              n.save unless n.details.empty? && n.notes.blank?
509 512
          end