Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_feature_usage.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f445758653dbc8ee4a1963ee1388ce352d183d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class ProjectFeatureUsage < ApplicationRecord
  self.primary_key = :project_id

  JIRA_DVCS_CLOUD_FIELD = 'jira_dvcs_cloud_last_sync_at'
  JIRA_DVCS_SERVER_FIELD = 'jira_dvcs_server_last_sync_at'

  belongs_to :project
  validates :project, presence: true

  scope :with_jira_dvcs_integration_enabled, -> (cloud: true) do
    where.not(jira_dvcs_integration_field(cloud: cloud) => nil)
  end

  class << self
    def jira_dvcs_integration_field(cloud: true)
      cloud ? JIRA_DVCS_CLOUD_FIELD : JIRA_DVCS_SERVER_FIELD
    end
  end

  def log_jira_dvcs_integration_usage(cloud: true)
    transaction(requires_new: true) do
      save unless persisted?
      touch(self.class.jira_dvcs_integration_field(cloud: cloud))
    end
  rescue ActiveRecord::RecordNotUnique
    reset
    retry
  end
end