mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-04 14:44:26 +08:00
Merge pull request #6117 from artoscinote/ma_SCI_9180
Fix result assets when duplicating [SCI-9180]
This commit is contained in:
commit
19026b936d
1 changed files with 20 additions and 1 deletions
|
@ -68,10 +68,12 @@ class Result < ApplicationRecord
|
|||
end
|
||||
|
||||
# Copy assets
|
||||
assets.each do |asset|
|
||||
assets_to_clone = assets.map do |asset|
|
||||
new_asset = asset.dup
|
||||
new_asset.save!
|
||||
new_result.assets << new_asset
|
||||
|
||||
[asset.id, new_asset.id]
|
||||
end
|
||||
|
||||
# Copy tables
|
||||
|
@ -79,10 +81,27 @@ class Result < ApplicationRecord
|
|||
table.duplicate(new_result, user)
|
||||
end
|
||||
|
||||
Result.delay(queue: :assets).deep_clone_assets(assets_to_clone)
|
||||
|
||||
new_result
|
||||
end
|
||||
end
|
||||
|
||||
# Deep-clone given array of assets
|
||||
def self.deep_clone_assets(assets_to_clone)
|
||||
ActiveRecord::Base.no_touching do
|
||||
assets_to_clone.each do |src_id, dest_id|
|
||||
src = Asset.find_by(id: src_id)
|
||||
dest = Asset.find_by(id: dest_id)
|
||||
dest.destroy! if src.blank? && dest.present?
|
||||
next unless src.present? && dest.present?
|
||||
|
||||
# Clone file
|
||||
src.duplicate_file(dest)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def default_view_state
|
||||
{ 'assets' => { 'sort' => 'new' } }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue