Project

General

Profile

Defect #39437 » 0002-moves-create_parent_issue_journal-to-after_commit.patch

Jens Krämer, 2023-11-01 08:30

View differences:

app/models/issue.rb
119 119
  after_save :reschedule_following_issues, :update_nested_set_attributes,
120 120
             :update_parent_attributes, :delete_selected_attachments, :create_journal
121 121
  # Should be after_create but would be called before previous after_save callbacks
122
  after_save :after_create_from_copy, :create_parent_issue_journal
123
  after_destroy :update_parent_attributes, :create_parent_issue_journal
122
  after_save :after_create_from_copy
123
  after_destroy :update_parent_attributes
124 124
  # add_auto_watcher needs to run before sending notifications, thus it needs
125 125
  # to be added after send_notification (after_ callbacks are run in inverse order)
126 126
  # https://api.rubyonrails.org/v5.2.3/classes/ActiveSupport/Callbacks/ClassMethods.html#method-i-set_callback
127 127
  after_create_commit :send_notification
128 128
  after_create_commit :add_auto_watcher
129
  after_commit :create_parent_issue_journal
129 130

  
130 131
  # Returns a SQL conditions string used to find all issues visible by the specified user
131 132
  def self.visible_condition(user, options={})
......
2027 2028
        [nil, parent_id]
2028 2029
      end
2029 2030

  
2030
    if old_parent_id.present? && old_parent_issue = Issue.visible.find_by_id(old_parent_id)
2031
      old_parent_issue.init_journal(User.current)
2032
      old_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', child_id, nil)
2033
      old_parent_issue.save
2031
    if old_parent_id.present?
2032
      Issue.transaction do
2033
        if old_parent_issue = Issue.visible.lock.find_by_id(old_parent_id)
2034
          old_parent_issue.init_journal(User.current)
2035
          old_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', child_id, nil)
2036
          old_parent_issue.save
2037
        end
2038
      end
2034 2039
    end
2035
    if new_parent_id.present? && new_parent_issue = Issue.visible.find_by_id(new_parent_id)
2036
      new_parent_issue.init_journal(User.current)
2037
      new_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', nil, child_id)
2038
      new_parent_issue.save
2040

  
2041
    if new_parent_id.present?
2042
      Issue.transaction do
2043
        if new_parent_issue = Issue.visible.lock.find_by_id(new_parent_id)
2044
          new_parent_issue.init_journal(User.current)
2045
          new_parent_issue.current_journal.__send__(:add_attribute_detail, 'child_id', nil, child_id)
2046
          new_parent_issue.save
2047
        end
2048
      end
2039 2049
    end
2040 2050
  end
2041 2051

  
(4-4/4)