mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-09 14:13:16 +08:00
34 lines
1 KiB
Ruby
34 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Repositories
|
|
class ArchiveRepositoryService < ArchiveRepositoryBaseService
|
|
def call
|
|
return self unless valid?
|
|
|
|
ActiveRecord::Base.transaction do
|
|
@repositories.each do |repository|
|
|
repository.archive!(@user)
|
|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
|
repository.repository_rows.active.update_all(archived_on: repository.archived_on,
|
|
archived_by_id: repository.archived_by_id,
|
|
archived: true)
|
|
# rubocop:enable Rails/SkipsModelValidations
|
|
|
|
log_activity(:archive_inventory, repository)
|
|
end
|
|
rescue ActiveRecord::RecordNotSaved
|
|
@errors[:archiving_error] = I18n.t('repositories.archive_inventories.unsuccess_flash')
|
|
raise ActiveRecord::Rollback
|
|
end
|
|
|
|
self
|
|
end
|
|
|
|
private
|
|
|
|
def scoped_repositories(ids)
|
|
Repository.where(id: ids, team_id: @team)
|
|
end
|
|
end
|
|
end
|