Merge pull request #7438 from tchak/fix-parent-revision-id
fix(procedure): fix wrong parents
This commit is contained in:
commit
1c940c700d
2 changed files with 37 additions and 7 deletions
|
@ -509,9 +509,11 @@ class Procedure < ApplicationRecord
|
||||||
procedure.service = self.service.clone_and_assign_to_administrateur(admin)
|
procedure.service = self.service.clone_and_assign_to_administrateur(admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
transaction do
|
||||||
procedure.save
|
procedure.save
|
||||||
|
|
||||||
move_new_children_to_new_parent_coordinate(procedure.draft_revision)
|
move_new_children_to_new_parent_coordinate(procedure.draft_revision)
|
||||||
|
end
|
||||||
|
|
||||||
if is_different_admin || from_library
|
if is_different_admin || from_library
|
||||||
procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
|
procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
|
||||||
|
@ -728,6 +730,7 @@ class Procedure < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_new_revision
|
def create_new_revision
|
||||||
|
transaction do
|
||||||
new_draft = draft_revision
|
new_draft = draft_revision
|
||||||
.deep_clone(include: [:revision_types_de_champ])
|
.deep_clone(include: [:revision_types_de_champ])
|
||||||
.tap(&:save!)
|
.tap(&:save!)
|
||||||
|
@ -736,6 +739,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
new_draft
|
new_draft
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def average_dossier_weight
|
def average_dossier_weight
|
||||||
if dossiers.termine.any?
|
if dossiers.termine.any?
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: move_new_children_to_new_parent_coordinate'
|
||||||
|
task move_new_children_to_new_parent_coordinate: :environment do
|
||||||
|
puts "Running deploy task 'move_new_children_to_new_parent_coordinate'"
|
||||||
|
|
||||||
|
children = ProcedureRevisionTypeDeChamp
|
||||||
|
.includes(parent: :type_de_champ)
|
||||||
|
.where.not(parent_id: nil)
|
||||||
|
.filter { |child| child.revision_id != child.parent.revision_id }
|
||||||
|
|
||||||
|
progress = ProgressReport.new(children.size)
|
||||||
|
|
||||||
|
children.each do |child|
|
||||||
|
new_parent = child.revision.revision_types_de_champ.joins(:type_de_champ).find_by!(type_de_champ: { stable_id: child.parent.stable_id })
|
||||||
|
child.update!(parent: new_parent)
|
||||||
|
progress.inc
|
||||||
|
end
|
||||||
|
|
||||||
|
progress.finish
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue