Project

General

Profile

Help me find in the Ruby code when the task is updated

Added by Artiom Shurupov about 7 years ago

I'm not Ruby's programmer. For a week now I have been trying to make a complete migration from the MantisBT system.
Almost all the mistakes were corrected. But there was one problem - the dates for updated_on issue are not copied. Rather, they are somewhere re-recorded again. And I can not find this place!
Here is the link to the original code: source:/trunk/lib/tasks/migrate_from_mantis.rake@16685#L305
There are many modifications, but here is the specific moment:

      # Bugs
      print "Migrating bugs" 
      Issue.destroy_all
      issues_map = {}
      keep_bug_ids = (Issue.count == 0)
      MantisBug.find_each(:batch_size => 200) do |bug|
        next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
        i = Issue.new :project_id => projects_map[bug.project_id],
                      :subject => encode(bug.summary),
                      :description => encode(bug.bug_text.full_description),
                      :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
                      :created_on => bug.date_submitted,
                      :updated_on => bug.last_updated
        i.author = User.find_by_id(users_map[bug.reporter_id])
        i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
        i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
        i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
        i.status = STATUS_MAPPING[bug.status] || i.status
        i.id = bug.id if keep_bug_ids
        next unless i.save
        issues_map[bug.id] = i.id
        print '.'
        STDOUT.flush

Line 315 and 316 do not work (:created_on => bug.date_submitted, and :updated_on => bug.last_updated.) Comment on.
After line
next unless i.save
insert:
i.created_on = Time.at(bug.date_submitted).to_datetime
It work!
insert next line:
i.updated_on = Time.at(bug.last_updated).to_datetime
It work only next iteration. To the line 358 (source:trunk/lib/tasks/migrate_from_mantis.rake@16685#L358)

In DataBase save DateNow instead last_updated

Please, help!


Replies (4)

RE: Help me find in the Ruby code when the task is updated - Added by Mischa The Evil about 7 years ago

This is yet another problem (see previous thread: Migrate from Mantis - rake aborted). This is a more tough one though. MantisBT "migrated away from DATETIME fields to integer timestamps for timezone usage" with 1.2.01 and up. We've found another breaking change that makes the import/migration rake task in this case in-compatible with MantisBT 1.2.0 and up for sure.

1 source: release-announcement, MantisBT 1.2.0 Released.

RE: Help me find in the Ruby code when the task is updated - Added by Artiom Shurupov about 7 years ago

I solved the problem like this:
  • created a new field (via phpMyAdmin) updated_on_New (copy of updated_on)
  • Changed the code like this:
    # Bugs
          print "Migrating bugs" 
          Issue.destroy_all
          issues_map = {}
          keep_bug_ids = (Issue.count == 0)
          MantisBug.find_each(:batch_size => 200) do |bug|
            next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
            i = Issue.new :project_id => projects_map[bug.project_id],
                          :subject => encode(bug.summary),
                          :description => encode(bug.bug_text.full_description),
                          :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY
            i.author = User.find_by_id(users_map[bug.reporter_id])
            i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
            i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
            i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
            i.status = STATUS_MAPPING[bug.status] || i.status
            i.id = bug.id if keep_bug_ids
            next unless i.save
    i.created_on = Time.at(bug.date_submitted).to_datetime
    i.updated_on_New = Time.at(bug.last_updated).to_datetime
    i.closed_on = Time.at(bug.last_updated).to_datetime
            issues_map[bug.id] = i.id
            print '.'
            STDOUT.flush
    
  • After migration, deleted the old field of updated_on
  • Rename updated_on_New to updated_on
  • Profit! :)

RE: Help me find in the Ruby code when the task is updated - Added by Artiom Shurupov about 7 years ago

There are several problems that I solved on my own. I do not think they are perfect, but they work.
1. Project identifier. If my project is called "СССР", and the other "СШАП", then the "СССР" will win, because it was the first in the list for migration. Its identifier is "----". The СШАП also has a ----, and it does not migrate.

def identifier
    read_attribute(:name).downcase.gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
end

I did this:
# Projects
      print "Migrating projects" 
      Project.destroy_all
      projects_map = {}
      versions_map = {}
      categories_map = {}
      MantisProject.all.each do |project|
        p = Project.new :name => encode(project.name),
                        :description => encode(project.description)
        p.identifier = "mantis_proj" + rand(10000).to_s
        next unless p.save
        projects_map[project.id] = p.id
        p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
        p.trackers << TRACKER_BUG unless p.trackers.include?(TRACKER_BUG)
        p.trackers << TRACKER_FEATURE unless p.trackers.include?(TRACKER_FEATURE)
        print '.'

2. Part of the corrections is taken from: https://github.com/rogatec/mantis-to-redmine/blob/master/migrate_from_mantis.rake
This is correct project categories and project hierarchies.
3. I corrected the line with the author of the files
# Bug files
        bug.bug_files.each do |file|
          a = Attachment.new :created_on => Time.at(file.date_added).to_datetime
          a.file = file
          a.author = User.find_by_id(users_map[file.user_id])
          a.container = i
          a.save
        end

4. After the interruption (by error or cancel) of the code execution, the database has to be cleaned manually. Here is the problem in error Project.destroy_all
Problem with e-mail error of the administrator is solved as in the code: https://github.com/rogatec/mantis-to-redmine/blob/master/migrate_from_mantis.rake
admin_user = "admin" 
user_admin = User.find_by_login(admin_user)
EmailAddress.delete_all "user_id <> #{user_admin.id}" 
User.delete_all "login <> 'admin'" 

"That's All I Have To Say About That" Forrest Gump(c)

RE: Help me find in the Ruby code when the task is updated - Added by Mischa The Evil about 7 years ago

Artiom Shurupov wrote:

I solved the problem like this:
[...]
  • Profit! :)

Nice that it worked out well. As the same as with the other issue, this has been part of several other issues and patches already: #13407, #14969, #18496, #18984.
Be aware, that other things might be broken too. Just check your data carefully, these scripts don't seem supported for newer upstream releases these days.

    (1-4/4)