canvas_sync 0.22.12.beta4 → 0.22.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc92f78b570ceb30606d3757b304a7a4091570bd62f8a7e534f6326f94105048
4
- data.tar.gz: 75c4f6e0d78615da39ac766258ebde594589798af68626899452447214d15fcf
3
+ metadata.gz: f42b6a25ec5fc3e6c78c579e766d19e9c0ff7acec94fd7a9737bb6a0955b88a2
4
+ data.tar.gz: 228358cb249033c7d3a9791bad5107029b78dfc427ce56a1a020a354b3d7b7b7
5
5
  SHA512:
6
- metadata.gz: 96d9e72e36e149f848769ab8e8b5fb397d222005ff1dc12b3c04563792e6c333f420cde4d792ce148d40745685eafa9b422a94fafcc6e7e021a0125f57544e58
7
- data.tar.gz: e50fd5faf9f78b4d0fb0be7c5701eea7f774fe051b5fec3d1d9eab2d0b66a88eb6649761d44f91629f6866d9bae7076eab8c8aa2b7d4fbe2c0ca2d2e8f2124bc
6
+ metadata.gz: 033e9c71870c0e7c4436e98a2f8dfbfe72fa502fc3a976f2f7e0a8c9ca36e4a042323a539132575e56a10272eece7038ad8cfaf14d73c2e8bf501f17d2b1f4cc
7
+ data.tar.gz: f935ad7d973455ac77567dfac091158bff7cf0a69111eee16c77a677961d3330c7002f99547720743ef82da3c603306d5bfe3d6a82c107f5c0d87708223b9295
@@ -33,6 +33,7 @@ module CanvasSync::Concerns
33
33
  @map_def = map_def
34
34
  @map_def[:conflict_target] ||= []
35
35
  @map_def[:columns] ||= {}
36
+ @map_def[:row_alterations] ||= []
36
37
  end
37
38
 
38
39
  def self.normalize_model_name(model)
@@ -105,6 +106,10 @@ module CanvasSync::Concerns
105
106
  @map_def[:columns].delete(key)
106
107
  end
107
108
 
109
+ def alter_rows(&blk)
110
+ @map_def[:row_alterations] << blk
111
+ end
112
+
108
113
  def link_column(m = {}, type: nil, **kwargs, &blk)
109
114
  if m.is_a?(Hash)
110
115
  m = m.merge(kwargs)
File without changes
@@ -6,7 +6,14 @@
6
6
  class ContextModule < ApplicationRecord
7
7
  include CanvasSync::Record
8
8
  include CanvasSync::Concerns::ApiSyncable
9
+
9
10
  # include CanvasSync::Concerns::LiveEventSync
11
+ # live_events_config event_prefix: :module
12
+ # def process_live_event(event_type, payload, metadata)
13
+ # self.canvas_context_id = payload['context_id']
14
+ # self.canvas_context_type = payload['context_type']
15
+ # super
16
+ # end
10
17
 
11
18
  canvas_sync_features :defaults
12
19
 
@@ -17,25 +17,35 @@ module CanvasSync
17
17
  # Note: passing the key [:on_duplicate_key_ignore] will override the default behavior of [:on_duplicate_key_update]
18
18
  # @yieldparam [Array] row if a block is passed in it will yield the current row from the CSV.
19
19
  # This can be used if you need to filter or massage the data in any way.
20
- def self.import(report_file_path, mapping, klass, conflict_target, import_args: {}, &blk) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/LineLength
20
+
21
+ # NEW: (report_file_path, klass, mapping, import_args: {}, &blk)
22
+ # LEGACY: (report_file_path, columns, klass, conflict_target, import_args: {}, &blk)
23
+ def self.import(report_file_path, *args, import_args: {}, &blk) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/LineLength
24
+ if args.length == 2
25
+ klass = args[0]
26
+ mapping = args[1]
27
+ elsif args.length == 3
28
+ klass = args[1]
29
+ mapping = { columns: args[0], conflict_target: args[2] }
30
+ end
31
+
21
32
  ClassCallbackExecutor.run_if_defined(klass, :sync_import) do
22
- perform_in_batches(report_file_path, mapping, klass, conflict_target, import_args: import_args, &blk)
33
+ perform_in_batches(report_file_path, klass, mapping, import_args: import_args, &blk)
23
34
  end
24
35
  end
25
36
 
26
- def self.perform_in_batches(report_file_path, raw_mapping, klass, conflict_target, import_args: {}, &block)
27
- mapping = {}.with_indifferent_access
28
- raw_mapping.each do |db_col, opts|
37
+ def self.perform_in_batches(report_file_path, klass, mapping, import_args: {}, &block)
38
+ conflict_target = Array(mapping[:conflict_target]).map(&:to_s)
39
+
40
+ col_mapping = {}.with_indifferent_access
41
+ mapping[:columns].each do |db_col, opts|
29
42
  next if opts[:deprecated] && !klass.column_names.include?(db_col.to_s)
30
43
 
31
- mapping[db_col] = opts
44
+ col_mapping[db_col] = opts
32
45
  end
33
46
 
34
- csv_column_names = mapping.values.map { |value| value[:report_column].to_s }
35
- database_column_names = mapping.keys
36
-
37
- conflict_target = Array(conflict_target).map(&:to_s)
38
- conflict_target_indices = conflict_target.map{|ct| database_column_names.index(ct) }
47
+ csv_column_names = col_mapping.values.map { |value| value[:report_column].to_s }
48
+ database_column_names = col_mapping.keys
39
49
 
40
50
  enumer = CSV.foreach(report_file_path, headers: true, header_converters: :symbol).lazy
41
51
 
@@ -48,6 +58,9 @@ module CanvasSync
48
58
  end
49
59
  end
50
60
 
61
+ # Convert rows to a hash that we can manipulate if desired
62
+ enumer = enumer.map {|row| row.to_h.with_indifferent_access }
63
+
51
64
  # Optionally chunk by a computed value. Mainly so we can group duplicate rows and choose one
52
65
  chunker = nil
53
66
  chunker = UserChunker.new if defined?(User) && klass == User && csv_column_names.include?('user_id')
@@ -55,9 +68,14 @@ module CanvasSync
55
68
  enumer = enumer.chunk{|row| chunker.key(row) }.flat_map{|key, rows| chunker.choose(key, rows) }
56
69
  end
57
70
 
71
+ # Pre-alter rows
72
+ (mapping[:row_alterations] || []).each do |alterer|
73
+ enumer = enumer.each {|r| alterer.call(r) }
74
+ end
75
+
58
76
  # Prepare the rows for import
59
77
  enumer = enumer.map do |row|
60
- mapping.map do |db_col, col_def|
78
+ col_mapping.map do |db_col, col_def|
61
79
  value = nil
62
80
  value = row[col_def[:report_column]] if col_def[:report_column]
63
81
 
@@ -78,22 +96,23 @@ module CanvasSync
78
96
  end
79
97
  end
80
98
 
81
- # Reject rows within a single batch that have the same ID
82
- row_ids = nil
99
+ # Reject rows within a single batch that have the same ID (use indices so we can use the post-transformed values)
100
+ conflict_target_indices = conflict_target.map{|ct| database_column_names.index(ct) }
101
+ row_ids = Set.new
83
102
  if conflict_target.present?
84
103
  enumer = enumer.reject do |row|
85
104
  key = conflict_target_indices.map{|ct| row[ct] }
86
- skip = row_ids[key]
87
- row_ids[key] = true
88
- skip
105
+ next true if row_ids.include?(key)
106
+
107
+ row_ids << key
108
+ false
89
109
  end
90
110
  end
91
111
 
92
112
  # Start importing
93
- row_ids = {}
94
113
  enumer.each_slice(batch_size) do |batch|
95
114
  perform_import(klass, database_column_names, batch, conflict_target, import_args)
96
- row_ids = {}
115
+ row_ids.clear
97
116
  end
98
117
  end
99
118
 
File without changes
File without changes
@@ -13,12 +13,10 @@ module CanvasSync
13
13
  end
14
14
 
15
15
  def do_bulk_import(report_file_path, model, options: {}, mapping_key: nil, &blk)
16
- m = mapping_for(model, mapping_key)
17
16
  CanvasSync::Importers::BulkImporter.import(
18
17
  report_file_path,
19
- m[:columns],
20
18
  model,
21
- m[:conflict_target],
19
+ mapping_for(model, mapping_key),
22
20
  import_args: options,
23
21
  &blk
24
22
  )
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.22.12.beta4".freeze
2
+ VERSION = "0.22.13".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.12.beta4
4
+ version: 0.22.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-20 00:00:00.000000000 Z
11
+ date: 2025-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -444,12 +444,10 @@ files:
444
444
  - lib/canvas_sync/concerns/account/ancestry.rb
445
445
  - lib/canvas_sync/concerns/account/base.rb
446
446
  - lib/canvas_sync/concerns/api_syncable.rb
447
- - lib/canvas_sync/concerns/auto_relations.rb
448
447
  - lib/canvas_sync/concerns/legacy_columns.rb
449
448
  - lib/canvas_sync/concerns/live_event_sync.rb
450
449
  - lib/canvas_sync/concerns/role/base.rb
451
450
  - lib/canvas_sync/concerns/sync_mapping.rb
452
- - lib/canvas_sync/concerns/user/sharded.rb
453
451
  - lib/canvas_sync/config.rb
454
452
  - lib/canvas_sync/engine.rb
455
453
  - lib/canvas_sync/generators/install_generator.rb
@@ -776,7 +774,6 @@ files:
776
774
  - spec/dummy/db/migrate/20250319194134_create_course_nicknames.rb
777
775
  - spec/dummy/db/migrate/20250319194135_create_rubrics.rb
778
776
  - spec/dummy/db/schema.rb
779
- - spec/dummy/tmp/local_secret.txt
780
777
  - spec/factories/account_factory.rb
781
778
  - spec/factories/admin_factory.rb
782
779
  - spec/factories/assignment_factory.rb
@@ -1039,7 +1036,6 @@ test_files:
1039
1036
  - spec/dummy/db/migrate/20250319194134_create_course_nicknames.rb
1040
1037
  - spec/dummy/db/migrate/20250319194135_create_rubrics.rb
1041
1038
  - spec/dummy/db/schema.rb
1042
- - spec/dummy/tmp/local_secret.txt
1043
1039
  - spec/factories/account_factory.rb
1044
1040
  - spec/factories/admin_factory.rb
1045
1041
  - spec/factories/assignment_factory.rb
@@ -1,11 +0,0 @@
1
- module CanvasSync::Concerns
2
- module AutoRelations
3
- extend ActiveSupport::Concern
4
-
5
- # CanvasSync::Record.define_feature self, default: true
6
-
7
- included do
8
-
9
- end
10
- end
11
- end
@@ -1,18 +0,0 @@
1
- module CanvasSync::Concerns
2
- module User
3
- module CanvasSharded
4
- extend ActiveSupport::Concern
5
-
6
- CanvasSync::Record.define_feature self, default: false
7
-
8
- included do
9
-
10
- end
11
-
12
- class_methods do
13
-
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1 +0,0 @@
1
- 851f946ee3fdb7c1b6265a8445cdcc0071988f43898ec1099500a655f28484d45fa06dd9628496983d323a058d72b6282782401cabcb8856c09378199ca2ab38