mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 11:14:24 +08:00
a1c1b6e5a7
Co-Author okriuchykhin <oleksii@scinote.net>
31 lines
1.2 KiB
Ruby
31 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module MyModules
|
|
class CopyContentJob < ApplicationJob
|
|
def perform(user, source_my_module_id, target_my_module_id)
|
|
target_my_module = MyModule.find(target_my_module_id)
|
|
MyModule.transaction do
|
|
MyModule.find(source_my_module_id).copy_content(user, target_my_module)
|
|
create_copy_my_module_activity(user, source_my_module_id, target_my_module_id)
|
|
target_my_module.update!(provisioning_status: :done)
|
|
end
|
|
rescue StandardError => e
|
|
Rails.logger.error e.message
|
|
target_my_module.update(provisioning_status: :failed)
|
|
end
|
|
|
|
private
|
|
|
|
def create_copy_my_module_activity(user, my_module_original_id, my_module_new_id)
|
|
my_module_new = MyModule.find(my_module_new_id)
|
|
Activities::CreateActivityService
|
|
.call(activity_type: :clone_module,
|
|
owner: user,
|
|
team: my_module_new.experiment.project.team,
|
|
project: my_module_new.experiment.project,
|
|
subject: my_module_new,
|
|
message_items: { my_module_original: my_module_original_id,
|
|
my_module_new: my_module_new.id })
|
|
end
|
|
end
|
|
end
|