2020-06-10 00:50:36 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryActions
|
|
|
|
class RestoreRowsService < ArchiveRowsBaseService
|
|
|
|
def call
|
|
|
|
return self unless valid?
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
2020-06-19 15:04:42 +08:00
|
|
|
@repository_rows.find_each(batch_size: 100) do |row|
|
2020-06-10 00:50:36 +08:00
|
|
|
row.restore!(@user)
|
2020-06-19 15:04:42 +08:00
|
|
|
log_activity(:restore_inventory_item, row) if @log_activities
|
2020-06-10 00:50:36 +08:00
|
|
|
end
|
2021-01-08 15:05:05 +08:00
|
|
|
rescue ActiveRecord::RecordInvalid
|
2021-01-28 21:43:45 +08:00
|
|
|
@errors[:restoring_error] = I18n.t('repositories.restore_records.unsuccess_flash', repository: @repository.name)
|
2020-06-10 00:50:36 +08:00
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def scoped_repository_rows(ids)
|
|
|
|
@repository.repository_rows.where(id: ids).archived
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|