Project

General

Profile

Patch #13407 ยป migrate_from_mantis.patch

Mathew Eis, 2013-03-09 00:19

View differences:

lib/tasks/migrate_from_mantis.rake (working copy)
88 88

  
89 89
      def firstname
90 90
        @firstname = realname.blank? ? username : realname.split.first[0..29]
91
        @firstname.gsub!(/[^\w\s\'\-]/i, '')
91 92
        @firstname
92 93
      end
93 94

  
94 95
      def lastname
95 96
        @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29]
97
        @lastname.gsub!(/[^\w\s\'\-]/i, '')
96 98
        @lastname = '-' if @lastname.blank?
97 99
        @lastname
98 100
      end
......
118 120
      has_many :news, :class_name => "MantisNews", :foreign_key => :project_id
119 121
      has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
120 122

  
123
      def name
124
        read_attribute(:name)[0..29]
125
      end
126

  
121 127
      def identifier
122
        read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
128
        read_attribute(:name).underscore[0..19].gsub(/[^a-z0-9\-]/, '-')
123 129
      end
124 130
    end
125 131

  
132
    class MantisProjectHierarchy < ActiveRecord::Base
133
      self.table_name = :mantis_project_hierarchy_table;
134
    end
135

  
126 136
    class MantisVersion < ActiveRecord::Base
127 137
      self.table_name = :mantis_project_version_table
128 138

  
......
136 146
    end
137 147

  
138 148
    class MantisCategory < ActiveRecord::Base
139
      self.table_name = :mantis_project_category_table
149
      self.table_name = :mantis_category_table
140 150
    end
141 151

  
142 152
    class MantisProjectUser < ActiveRecord::Base
......
222 232
      end
223 233

  
224 234
      def name
225
        read_attribute(:name)[0..29]
235
        read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-')
226 236
      end
227 237
    end
228 238

  
......
248 258
                     :last_login_on => user.last_visit
249 259
        u.login = user.username
250 260
        u.password = 'mantis'
251
        u.status = User::STATUS_LOCKED if user.enabled != 1
261
        u.status = User::STATUS_ACTIVE if user.enabled == true
262
        u.status = User::STATUS_LOCKED if user.enabled != true
252 263
        u.admin = true if user.access_level == 90
253 264
        next unless u.save!
254 265
        users_migrated += 1
......
259 270

  
260 271
      # Projects
261 272
      print "Migrating projects"
262
      Project.destroy_all
273
      Project.destroy_all(:parent_id => nil)
263 274
      projects_map = {}
264 275
      versions_map = {}
265 276
      categories_map = {}
......
286 297
        project.versions.each do |version|
287 298
          v = Version.new :name => encode(version.version),
288 299
                          :description => encode(version.description),
289
                          :effective_date => (version.date_order ? version.date_order.to_date : nil)
300
                          :effective_date => Time.at(version.date_order).to_date
290 301
          v.project = p
291 302
          v.save
292 303
          versions_map[version.id] = v.id
......
294 305

  
295 306
        # Project categories
296 307
        project.categories.each do |category|
297
          g = IssueCategory.new :name => category.category[0,30]
308
          g = IssueCategory.new :name => category.name[0,30]
298 309
          g.project = p
299 310
          g.save
300
          categories_map[category.category] = g.id
311
          categories_map[category.id] = g.id
301 312
        end
302 313
      end
303 314
      puts
304 315

  
316
      # Project Hierarchy
317
      print "Migrating project hierarchy..."
318
      MantisProjectHierarchy.find(:all).each do |entry|
319
        p = Project.find_by_id(projects_map[entry.child_id])
320
        p.set_parent!(projects_map[entry.parent_id])
321
      end
322
      puts
323

  
305 324
      # Bugs
306 325
      print "Migrating bugs"
307 326
      Issue.destroy_all
......
313 332
                      :subject => encode(bug.summary),
314 333
                      :description => encode(bug.bug_text.full_description),
315 334
                      :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
316
                      :created_on => bug.date_submitted,
317
                      :updated_on => bug.last_updated
335
                      :created_on => Time.at(bug.date_submitted),
336
                      :updated_on => Time.at(bug.last_updated)
318 337
        i.author = User.find_by_id(users_map[bug.reporter_id])
319
        i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
338
        i.category = IssueCategory.find_by_id(categories_map[bug.category_id]) unless bug.category_id.blank?
320 339
        i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
321 340
        i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
322 341
        i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
......
337 356
        bug.bug_notes.each do |note|
338 357
          next unless users_map[note.reporter_id]
339 358
          n = Journal.new :notes => encode(note.bug_note_text.note),
340
                          :created_on => note.date_submitted
359
                          :created_on => Time.at(note.date_submitted)
341 360
          n.user = User.find_by_id(users_map[note.reporter_id])
342 361
          n.journalized = i
343 362
          n.save
......
345 364

  
346 365
        # Bug files
347 366
        bug.bug_files.each do |file|
348
          a = Attachment.new :created_on => file.date_added
367
          a = Attachment.new :created_on => Time.at(file.date_added)
349 368
          a.file = file
350 369
          a.author = User.find :first
351 370
          a.container = i
......
357 376
          next unless users_map[monitor.user_id]
358 377
          i.add_watcher(User.find_by_id(users_map[monitor.user_id]))
359 378
        end
379

  
380
	# Fix updated time (setting some attribute breaks it)
381
        i.updated_on = Time.at(bug.last_updated)
360 382
      end
361 383

  
362 384
      # update issue id sequence if needed (postgresql)
......
384 406
        n = News.new :project_id => projects_map[news.project_id],
385 407
                     :title => encode(news.headline[0..59]),
386 408
                     :description => encode(news.body),
387
                     :created_on => news.date_posted
409
                     :created_on => Time.at(news.date_posted)
388 410
        n.author = User.find_by_id(users_map[news.poster_id])
389 411
        n.save
390 412
        print '.'
    (1-1/1)