2020-06-19 00:07:23 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Repositories
|
|
|
|
class ArchiveRepositoryService < ArchiveRepositoryBaseService
|
|
|
|
def call
|
|
|
|
return self unless valid?
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
@repositories.each do |repository|
|
2020-06-19 00:08:53 +08:00
|
|
|
log_activity(:archive_inventory, repository)
|
2020-06-19 00:07:23 +08:00
|
|
|
repository.archive!(@user)
|
|
|
|
|
|
|
|
RepositoryActions::ArchiveRowsService.call(repository: repository,
|
|
|
|
repository_rows: repository.repository_rows.pluck(:id),
|
|
|
|
user: @user,
|
|
|
|
team: @team)
|
|
|
|
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
|