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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 12:09:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 12:09:35 +0300
commitbf774d67fc8a84f76f20494c318d7cfacb0c69ac (patch)
treeb991cad6b68560d19f8ce3075577aab2eb51fae6 /app/services/concerns
parent50f0475ee134da9ea12e758a9f3250f2ab19cd65 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/concerns')
-rw-r--r--app/services/concerns/integrations/bulk_operation_hashes.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/services/concerns/integrations/bulk_operation_hashes.rb b/app/services/concerns/integrations/bulk_operation_hashes.rb
new file mode 100644
index 00000000000..3f13c764ebe
--- /dev/null
+++ b/app/services/concerns/integrations/bulk_operation_hashes.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# Returns hashes of attributes suitable for passing to `.insert_all` or `update_all`
+module Integrations
+ module BulkOperationHashes
+ private
+
+ def integration_hash(operation)
+ integration
+ .to_database_hash
+ .merge('inherit_from_id' => integration.inherit_from_id || integration.id)
+ .merge(update_timestamps(operation))
+ end
+
+ def data_fields_hash(operation)
+ integration
+ .data_fields
+ .to_database_hash
+ .merge(update_timestamps(operation))
+ end
+
+ def update_timestamps(operation)
+ time_now = Time.current
+
+ {
+ 'created_at' => (time_now if operation == :create),
+ 'updated_at' => time_now
+ }.compact
+ end
+ end
+end