move-to-go 5.4.1 → 5.4.3

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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/bin/move-to-go +282 -282
  3. data/lib/move-to-go/can_become_immutable.rb +29 -29
  4. data/lib/move-to-go/csv_helper.rb +47 -47
  5. data/lib/move-to-go/email_helper.rb +14 -14
  6. data/lib/move-to-go/errors.rb +31 -31
  7. data/lib/move-to-go/excel_helper.rb +10 -10
  8. data/lib/move-to-go/global_phone.json +6571 -6571
  9. data/lib/move-to-go/model/address.rb +63 -63
  10. data/lib/move-to-go/model/class_settings.rb +50 -50
  11. data/lib/move-to-go/model/clientvisit.rb +10 -10
  12. data/lib/move-to-go/model/comment.rb +10 -10
  13. data/lib/move-to-go/model/coworker.rb +114 -114
  14. data/lib/move-to-go/model/coworker_reference.rb +33 -33
  15. data/lib/move-to-go/model/customfield.rb +87 -87
  16. data/lib/move-to-go/model/deal.rb +247 -243
  17. data/lib/move-to-go/model/deal_class_settings.rb +97 -97
  18. data/lib/move-to-go/model/deal_state.rb +15 -15
  19. data/lib/move-to-go/model/deal_status.rb +23 -23
  20. data/lib/move-to-go/model/deal_status_reference.rb +47 -47
  21. data/lib/move-to-go/model/deal_status_setting.rb +49 -49
  22. data/lib/move-to-go/model/documents.rb +76 -76
  23. data/lib/move-to-go/model/file.rb +198 -198
  24. data/lib/move-to-go/model/history.rb +159 -159
  25. data/lib/move-to-go/model/history_classification.rb +29 -29
  26. data/lib/move-to-go/model/link.rb +87 -87
  27. data/lib/move-to-go/model/meeting.rb +219 -219
  28. data/lib/move-to-go/model/organization.rb +359 -359
  29. data/lib/move-to-go/model/organizations.rb +70 -70
  30. data/lib/move-to-go/model/person.rb +200 -200
  31. data/lib/move-to-go/model/referencetosource.rb +57 -57
  32. data/lib/move-to-go/model/relation.rb +23 -23
  33. data/lib/move-to-go/model/rootmodel.rb +879 -879
  34. data/lib/move-to-go/model/salescall.rb +10 -10
  35. data/lib/move-to-go/model/settings.rb +61 -61
  36. data/lib/move-to-go/model/tag.rb +35 -35
  37. data/lib/move-to-go/model/talkedto.rb +10 -10
  38. data/lib/move-to-go/model/todo.rb +182 -182
  39. data/lib/move-to-go/model/triedtoreach.rb +10 -10
  40. data/lib/move-to-go/model_helpers.rb +97 -97
  41. data/lib/move-to-go/phone_helper.rb +75 -75
  42. data/lib/move-to-go/roo_helper.rb +87 -87
  43. data/lib/move-to-go/serialize_helper.rb +217 -217
  44. data/lib/move-to-go/shard_helper.rb +112 -112
  45. data/lib/move-to-go/source.rb +110 -110
  46. data/lib/move-to-go/templating.rb +52 -52
  47. data/lib/move-to-go.rb +20 -20
  48. data/sources/VISMA/.gitignore +13 -13
  49. data/sources/VISMA/.move-to-go/readme.txt +1 -1
  50. data/sources/VISMA/.move-to-go/runner.rb +89 -89
  51. data/sources/VISMA/Gemfile +5 -5
  52. data/sources/VISMA/converter.rb +120 -120
  53. data/sources/base-crm/.gitignore +14 -14
  54. data/sources/base-crm/.move-to-go/runner.rb +235 -235
  55. data/sources/base-crm/Gemfile +5 -5
  56. data/sources/base-crm/README.md +9 -9
  57. data/sources/base-crm/converter.rb +56 -56
  58. data/sources/base-crm/data/contacts.csv +13 -13
  59. data/sources/base-crm/data/coworkers.csv +2 -2
  60. data/sources/base-crm/data/deals.csv +5 -5
  61. data/sources/base-crm/data/histories.csv +6 -6
  62. data/sources/base-crm/data/leads.csv +4 -4
  63. data/sources/base-crm/data/tasks.csv +5 -5
  64. data/sources/csv/.gitignore +14 -14
  65. data/sources/csv/.move-to-go/readme.txt +1 -1
  66. data/sources/csv/.move-to-go/runner.rb +65 -65
  67. data/sources/csv/Gemfile +5 -5
  68. data/sources/csv/converter.rb +218 -218
  69. data/sources/csv/data/coworkers.csv +2 -2
  70. data/sources/csv/data/deals.csv +2 -2
  71. data/sources/csv/data/organizations.csv +2 -2
  72. data/sources/csv/data/persons.csv +2 -2
  73. data/sources/custom/.gitignore +14 -14
  74. data/sources/custom/.move-to-go/readme.txt +1 -1
  75. data/sources/custom/.move-to-go/runner.rb +30 -30
  76. data/sources/custom/Gemfile +4 -4
  77. data/sources/custom/converter.rb +45 -45
  78. data/sources/excel/.gitignore +14 -14
  79. data/sources/excel/.move-to-go/readme.txt +3 -3
  80. data/sources/excel/.move-to-go/runner.rb +188 -188
  81. data/sources/excel/Gemfile +6 -6
  82. data/sources/excel/converter.rb +248 -248
  83. data/sources/excel-basic/.gitignore +13 -13
  84. data/sources/excel-basic/.move-to-go/readme.txt +3 -3
  85. data/sources/excel-basic/.move-to-go/runner.rb +139 -139
  86. data/sources/excel-basic/Gemfile +6 -6
  87. data/sources/excel-basic/converter.rb +179 -179
  88. data/sources/lime-crm-basic/.gitignore +14 -14
  89. data/sources/lime-crm-basic/.move-to-go/readme.txt +1 -1
  90. data/sources/lime-crm-basic/.move-to-go/runner.rb +524 -524
  91. data/sources/lime-crm-basic/Gemfile +6 -6
  92. data/sources/lime-crm-basic/converter.rb +395 -395
  93. data/sources/lime-easy/.gitignore +14 -14
  94. data/sources/lime-easy/.move-to-go/readme.txt +1 -1
  95. data/sources/lime-easy/.move-to-go/runner.rb +465 -465
  96. data/sources/lime-easy/Export/readme.txt +6 -6
  97. data/sources/lime-easy/Gemfile +5 -5
  98. data/sources/lime-easy/converter.rb +377 -377
  99. data/sources/salesforce/.gitignore +15 -15
  100. data/sources/salesforce/.move-to-go/readme.txt +1 -1
  101. data/sources/salesforce/.move-to-go/runner.rb +404 -404
  102. data/sources/salesforce/Gemfile +6 -6
  103. data/sources/salesforce/converter.rb +113 -113
  104. data/sources/salesforce/export/readme.txt +3 -3
  105. data/spec/address_spec.rb +49 -49
  106. data/spec/class_settings_spec.rb +37 -37
  107. data/spec/coworker_spec.rb +113 -113
  108. data/spec/custom_field_spec.rb +22 -22
  109. data/spec/deal_class_settings_spec.rb +116 -116
  110. data/spec/deal_spec.rb +250 -250
  111. data/spec/deal_status_reference_spec.rb +17 -17
  112. data/spec/documents_spec.rb +64 -64
  113. data/spec/file_spec.rb +205 -205
  114. data/spec/helpers/csv_helper_spec.rb +45 -45
  115. data/spec/helpers/email_helper_spec.rb +37 -37
  116. data/spec/helpers/phone_helper_spec.rb +119 -119
  117. data/spec/helpers/roo_helper_spec.rb +10 -10
  118. data/spec/helpers/serialize_helper_spec.rb +251 -251
  119. data/spec/helpers/shard_helper_spec.rb +141 -141
  120. data/spec/helpers/xsd_validate_spec.rb +127 -127
  121. data/spec/history_spec.rb +150 -150
  122. data/spec/link_spec.rb +133 -133
  123. data/spec/meeting_spec.rb +152 -152
  124. data/spec/organization_spec.rb +287 -287
  125. data/spec/organizations_spec.rb +344 -344
  126. data/spec/person_spec.rb +129 -129
  127. data/spec/rootmodel_spec.rb +1090 -1090
  128. data/spec/spec_helper.rb +30 -30
  129. data/spec/todo_spec.rb +149 -149
  130. metadata +24 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd937b1db5bd12b8d2a67ee5268cfcfa7d7636bce84c89dfee6d22e6b5d66c5a
4
- data.tar.gz: 9c494ea595c8918351912ca6323e5dd06e37289fd217f28c6b650a9f82dcc2ea
3
+ metadata.gz: 13edd3a147e80972833169fde78bc114bf3632f50931c0114f1d693995f07905
4
+ data.tar.gz: ab524b2aaf3ebe90a6507ab3636678bccfc68ba6275902219a312057c50979a0
5
5
  SHA512:
6
- metadata.gz: 93548a71b79eafbd314b33bfa5a1618c1bbf4cc3eac7117ceef4e7cc0a083cbbb8be62e12238b1d7f0e33d2360978fb32922796ccabad1e253e71b8def6abc79
7
- data.tar.gz: 468ed5939dce2a4fabcf81ba5498f60c8489fb571016d6f8403f5fc2cf16876637d0d335e6730cfdd81257872f2321467024b102a5955509fff46aaaba042dac
6
+ metadata.gz: 1ec6aedef9ef83b5ae48e6d347de6c94d3fa72cc62f18bf5d977dfa26f15fa1bf7de6192283d3f9f92d31f7d9204023a35970b6bbf59f8a1e87ba407e9f5def7
7
+ data.tar.gz: 67e86d7e7c60b39cf4102ae848c46b8e8c0791045066079e2b4d469581ec05134f2005d3093beeb2e1a11b4eff62e3ccb174be67d2b23bf7940b9159a2180d6c
data/bin/move-to-go CHANGED
@@ -1,282 +1,282 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "thor"
4
- require_relative '../lib/move-to-go'
5
- require 'progress'
6
- require 'net/http'
7
- require 'json'
8
-
9
-
10
- RUNNER_DIR = ".move-to-go"
11
-
12
- class MoveToGoCommandLine < Thor
13
-
14
- desc "about", "About move-to-go"
15
- def about()
16
- display_current_version()
17
- puts "move-to-go is an migration tool for Lime Go. It can take virtually any input source and create import data files that Lime Go likes."
18
- puts "move-to-go has some predefined sources that will make it easy for you to migrate your data."
19
- puts
20
- end
21
-
22
- desc "list-sources", "Lists the available sources"
23
- def list_sources()
24
- display_current_version()
25
-
26
- puts "The following sources are available:"
27
- puts
28
-
29
- sources = MoveToGo::Sources.new(source_path)
30
- sources.list().each do |s|
31
- puts "\t#{s}"
32
- end
33
-
34
- puts
35
- puts "Create a new project with 'move-to-go new <PROJECT> <SOURCE>' with one of these sources."
36
- puts "Use 'move-to-go about <SOURCE>' for more information about a specific source."
37
- end
38
-
39
- desc "about <SOURCE>", "Prints information about the specifed source"
40
- def about(source)
41
- display_current_version()
42
-
43
- sources = MoveToGo::Sources.new(source_path)
44
-
45
- sources.about_source(source)
46
- end
47
-
48
- desc "new <PROJECT> <SOURCE>", "Creates a new migration project with a specifed name and source"
49
- option(:force_current_version,
50
- :desc => "Set this if you have an outdated version of move-to-go and still want to create a new migration. Old versions of move-to-go will not work with the current version of Lime Go.",
51
- :type => :boolean,
52
- :required => false)
53
- def new(project, source)
54
- if options.force_current_version.nil?
55
- check_current_version()
56
- end
57
-
58
- display_current_version()
59
-
60
- sources = MoveToGo::Sources.new(source_path)
61
-
62
- if sources.create_project_from_source(project, source)
63
- puts
64
- puts "Project '#{project}' created from source '#{source}'."
65
- puts "Modify the #{project}/converter.rb script to suit your source."
66
- puts "Use 'move-to-go run' from the project directory to create the zip file for Lime Go."
67
- end
68
- end
69
-
70
- desc "run", "Executes the current project and create a go.zip file with data and files. Existing go.zip will be overwritten, use --output to specify a different filename."
71
- option(:output,
72
- :desc => "Name of the file where the converted source will be saved. This file should be sent to Lime Go. If the file already exist it will be replaced.",
73
- :type => :string,
74
- :required => false)
75
- option(:ignore_invalid_files,
76
- :desc => "Output will be created even if the import contains missing or invalid files",
77
- :type => :boolean,
78
- :required => false)
79
- option(:log_to_file,
80
- :desc => "Console output will be redirected to file",
81
- :type => :string,
82
- :required => false)
83
- option(:max_file_size,
84
- :desc => "Maximum size in bytes of documents included in zip",
85
- :type => :numeric,
86
- :required => false)
87
- option(:output_documents,
88
- :desc => "Name of the file to put imported documents in (default in same as --output)",
89
- :type => :string,
90
- :required => false)
91
- option(:shard_size,
92
- :desc => "Large imports are sharded into several zip-files. This property sets how many objects each zip-file should contain. Default is 25 000",
93
- :type => :numeric,
94
- :required => false)
95
- option(:force_current_version,
96
- :desc => "Set this if you have an outdated version of move-to-go and still want to run the migration. Old versions of move-to-go will not work with the current version of Lime Go.",
97
- :type => :boolean,
98
- :required => false)
99
- def run_import()
100
- if options.force_current_version.nil?
101
- check_current_version()
102
- end
103
-
104
- display_current_version()
105
-
106
- if !options.log_to_file.nil?
107
- $stdout = File.new(options.log_to_file == "log_to_file" ? "move-to-go.log" : options.log_to_file, 'w')
108
- $stdout.sync = true
109
- end
110
- max_file_size = options.max_file_size.nil? ? MoveToGo::File::DEFAULT_MAX_FILE_SIZE : options.max_file_size
111
-
112
- if !is_valid_project?
113
- return
114
- end
115
-
116
- runner_file = ::File.expand_path("./#{RUNNER_DIR}/runner.rb", Dir.pwd)
117
- require(runner_file)
118
- model = convert_source()
119
-
120
- if model.documents.files.length > 0 && (!defined?(FILES_FOLDER) || FILES_FOLDER.empty?())
121
- puts "WARNING: It looks like you are importing files but FILES_FOLDER has not been set in your converter.rb."
122
- puts "WARNING: FILES_FOLDER should be set unless you are only importing files with absolute paths."
123
- end
124
-
125
- if model.documents.files.length > 0 && (!defined?(FILES_FOLDER_AT_CUSTOMER) || FILES_FOLDER_AT_CUSTOMER.empty?())
126
- puts "WARNING: It looks like you are importing files but FILES_FOLDER_AT_CUSTOMER has not been set in your converter.rb"
127
- puts "WARNING: This means that files with an absolute path will be imported with their original path. Set this constant if you want to get files from the FILES_FOLDER directory."
128
- end
129
-
130
- is_ok, error_msg, warnings_msg = can_be_serialized?(model, options.ignore_invalid_files, max_file_size)
131
- if is_ok
132
-
133
- if options.ignore_invalid_files && model.documents.files.length > 0
134
- log_and_remove_invalid_files model, max_file_size
135
- end
136
- model.report_rootmodel_status()
137
-
138
- puts "Checking for duplicate organizations..."
139
- possible_duplicates = model.organizations.find_duplicates_by(:name, :organization_number)
140
- puts "Found #{possible_duplicates.length} organization duplicate sets in rootmodel, based on name and organization number"
141
-
142
- puts "Starting sharding of model..."
143
- sharder = MoveToGo::ShardHelper.new(options.shard_size)
144
- models_to_serialize = sharder.shard_model(model)
145
-
146
- if models_to_serialize.length > 1
147
- puts "Import is large and will be broken into #{models_to_serialize.length} files"
148
- end
149
-
150
- models_to_serialize.each_with_index do |model, i|
151
- go_data_zip = options.output.nil? == true ? "go" : options.output
152
- go_data_zip += "_#{i}.zip"
153
- go_files = options.output_documents.nil? == true ? nil : ::File.basename(options.output_documents,File.extname(options.output_documents))
154
- model.save_to_zip(go_data_zip, go_files)
155
- puts "Source has been been converted into '#{go_data_zip}'."
156
- puts " - and files into '#{go_files}.zip'." if !go_files.nil?
157
- if !warnings_msg.empty?
158
- puts "WARNINGS: "
159
- puts warnings_msg
160
- end
161
- end
162
- else
163
- puts "ERROR: Source could not be converted due to:"
164
- puts error_msg
165
-
166
- if !options.ignore_invalid_files &&
167
- model.documents.files.any? {|file| file.validate.empty?}
168
- puts "move-to-go detected invalid files (see above), you can ignore these with the option --ignore-invalid-files."
169
- end
170
- end
171
- end
172
-
173
- private
174
- def log_and_remove_invalid_files(model, max_file_size)
175
- if model.documents.files.length > 0
176
- file_log_header = "name;integration_id;path;organization.integrationid;organization.name;deal.integrationid;deal.name;file.size"
177
- file_log = ""
178
- files_to_remove = []
179
- model.documents.files.with_progress(" - Trying to log files that can't be found...").each do |file|
180
- if !::File.exists?(file.path_for_project)
181
- file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};0\n"
182
- files_to_remove.push file
183
- elsif ::File.size(file.path_for_project) > max_file_size
184
- file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};#{::File.size(file.path_for_project)}\n"
185
- files_to_remove.push file
186
- end
187
- end
188
-
189
- files_to_remove.each do |file|
190
- model.documents.files.delete file
191
- end
192
-
193
- if file_log.length > 0
194
- log_filename = 'move-to-go-invalid-files.csv'
195
- ::File.open(log_filename, 'w') { |f|
196
- f.puts file_log_header
197
- f.puts file_log
198
- }
199
- puts "WARNING: move-to-go has invalid files (#{files_to_remove.length} of #{model.documents.files.length}). Filenames of all ignored files has been written to '#{log_filename}'."
200
- else
201
- puts "All files are OK."
202
- end
203
- end
204
- end
205
-
206
- private
207
- def can_be_serialized?(rootmodel, ignore_invalid_files, max_file_size)
208
- is_ok = false
209
- error = rootmodel.sanity_check
210
- if error.empty?
211
- error, warnings = rootmodel.validate(ignore_invalid_files, max_file_size)
212
-
213
- if error.empty?
214
- is_ok = true
215
- end
216
- end
217
-
218
- return [is_ok, error, warnings]
219
- end
220
-
221
- private
222
- def is_valid_project?()
223
- if Dir.exists?(RUNNER_DIR) == false
224
- puts "This doesnt look like a move-to-go project. Are you in the right directory or did you mess with the '#{RUNNER_DIR}' folder?"
225
- return false
226
- end
227
-
228
- runner_file = File.expand_path("./#{RUNNER_DIR}/runner.rb", Dir.pwd)
229
- if File.exists?(runner_file) == false
230
- puts "I can't run this project. Did you mess with the '#{RUNNER_DIR}' folder?"
231
- return false
232
- end
233
-
234
- return true
235
- end
236
-
237
- private
238
- def source_path()
239
- File.expand_path("../sources", File.dirname(__FILE__))
240
- end
241
-
242
- private
243
- def check_current_version()
244
- if Gem.loaded_specs["move-to-go"] == nil
245
- puts "Running source version, no version check"
246
- return
247
- end
248
- uri = URI('https://rubygems.org/api/v1/versions/move-to-go/latest.json')
249
-
250
- Net::HTTP.start(uri.host, uri.port,
251
- :verify_mode => OpenSSL::SSL::VERIFY_NONE,
252
- :use_ssl => true) do |http|
253
-
254
- request = Net::HTTP::Get.new uri
255
- response = http.request request
256
-
257
- latest_version = Gem::Version.new(JSON.parse(response.body)['version'])
258
- current_version = Gem.loaded_specs["move-to-go"].version
259
- outdated = latest_version > current_version
260
-
261
- if outdated
262
- puts "You are running an old version of move-to-go (#{current_version})"
263
- puts "Please upgrade by running 'gem install move-to-go'"
264
- exit
265
- end
266
- end
267
- end
268
-
269
- private
270
- def display_current_version()
271
- if Gem.loaded_specs["move-to-go"] == nil
272
- current_version = "source"
273
- else
274
- current_version = Gem.loaded_specs["move-to-go"].version
275
- end
276
-
277
- puts "Version: #{current_version}"
278
- puts
279
- end
280
- end
281
-
282
- MoveToGoCommandLine.start(ARGV)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require_relative '../lib/move-to-go'
5
+ require 'progress'
6
+ require 'net/http'
7
+ require 'json'
8
+
9
+
10
+ RUNNER_DIR = ".move-to-go"
11
+
12
+ class MoveToGoCommandLine < Thor
13
+
14
+ desc "about", "About move-to-go"
15
+ def about()
16
+ display_current_version()
17
+ puts "move-to-go is an migration tool for Lime Go. It can take virtually any input source and create import data files that Lime Go likes."
18
+ puts "move-to-go has some predefined sources that will make it easy for you to migrate your data."
19
+ puts
20
+ end
21
+
22
+ desc "list-sources", "Lists the available sources"
23
+ def list_sources()
24
+ display_current_version()
25
+
26
+ puts "The following sources are available:"
27
+ puts
28
+
29
+ sources = MoveToGo::Sources.new(source_path)
30
+ sources.list().each do |s|
31
+ puts "\t#{s}"
32
+ end
33
+
34
+ puts
35
+ puts "Create a new project with 'move-to-go new <PROJECT> <SOURCE>' with one of these sources."
36
+ puts "Use 'move-to-go about <SOURCE>' for more information about a specific source."
37
+ end
38
+
39
+ desc "about <SOURCE>", "Prints information about the specifed source"
40
+ def about(source)
41
+ display_current_version()
42
+
43
+ sources = MoveToGo::Sources.new(source_path)
44
+
45
+ sources.about_source(source)
46
+ end
47
+
48
+ desc "new <PROJECT> <SOURCE>", "Creates a new migration project with a specifed name and source"
49
+ option(:force_current_version,
50
+ :desc => "Set this if you have an outdated version of move-to-go and still want to create a new migration. Old versions of move-to-go will not work with the current version of Lime Go.",
51
+ :type => :boolean,
52
+ :required => false)
53
+ def new(project, source)
54
+ if options.force_current_version.nil?
55
+ check_current_version()
56
+ end
57
+
58
+ display_current_version()
59
+
60
+ sources = MoveToGo::Sources.new(source_path)
61
+
62
+ if sources.create_project_from_source(project, source)
63
+ puts
64
+ puts "Project '#{project}' created from source '#{source}'."
65
+ puts "Modify the #{project}/converter.rb script to suit your source."
66
+ puts "Use 'move-to-go run' from the project directory to create the zip file for Lime Go."
67
+ end
68
+ end
69
+
70
+ desc "run", "Executes the current project and create a go.zip file with data and files. Existing go.zip will be overwritten, use --output to specify a different filename."
71
+ option(:output,
72
+ :desc => "Name of the file where the converted source will be saved. This file should be sent to Lime Go. If the file already exist it will be replaced.",
73
+ :type => :string,
74
+ :required => false)
75
+ option(:ignore_invalid_files,
76
+ :desc => "Output will be created even if the import contains missing or invalid files",
77
+ :type => :boolean,
78
+ :required => false)
79
+ option(:log_to_file,
80
+ :desc => "Console output will be redirected to file",
81
+ :type => :string,
82
+ :required => false)
83
+ option(:max_file_size,
84
+ :desc => "Maximum size in bytes of documents included in zip",
85
+ :type => :numeric,
86
+ :required => false)
87
+ option(:output_documents,
88
+ :desc => "Name of the file to put imported documents in (default in same as --output)",
89
+ :type => :string,
90
+ :required => false)
91
+ option(:shard_size,
92
+ :desc => "Large imports are sharded into several zip-files. This property sets how many objects each zip-file should contain. Default is 25 000",
93
+ :type => :numeric,
94
+ :required => false)
95
+ option(:force_current_version,
96
+ :desc => "Set this if you have an outdated version of move-to-go and still want to run the migration. Old versions of move-to-go will not work with the current version of Lime Go.",
97
+ :type => :boolean,
98
+ :required => false)
99
+ def run_import()
100
+ if options.force_current_version.nil?
101
+ check_current_version()
102
+ end
103
+
104
+ display_current_version()
105
+
106
+ if !options.log_to_file.nil?
107
+ $stdout = File.new(options.log_to_file == "log_to_file" ? "move-to-go.log" : options.log_to_file, 'w')
108
+ $stdout.sync = true
109
+ end
110
+ max_file_size = options.max_file_size.nil? ? MoveToGo::File::DEFAULT_MAX_FILE_SIZE : options.max_file_size
111
+
112
+ if !is_valid_project?
113
+ return
114
+ end
115
+
116
+ runner_file = ::File.expand_path("./#{RUNNER_DIR}/runner.rb", Dir.pwd)
117
+ require(runner_file)
118
+ model = convert_source()
119
+
120
+ if model.documents.files.length > 0 && (!defined?(FILES_FOLDER) || FILES_FOLDER.empty?())
121
+ puts "WARNING: It looks like you are importing files but FILES_FOLDER has not been set in your converter.rb."
122
+ puts "WARNING: FILES_FOLDER should be set unless you are only importing files with absolute paths."
123
+ end
124
+
125
+ if model.documents.files.length > 0 && (!defined?(FILES_FOLDER_AT_CUSTOMER) || FILES_FOLDER_AT_CUSTOMER.empty?())
126
+ puts "WARNING: It looks like you are importing files but FILES_FOLDER_AT_CUSTOMER has not been set in your converter.rb"
127
+ puts "WARNING: This means that files with an absolute path will be imported with their original path. Set this constant if you want to get files from the FILES_FOLDER directory."
128
+ end
129
+
130
+ is_ok, error_msg, warnings_msg = can_be_serialized?(model, options.ignore_invalid_files, max_file_size)
131
+ if is_ok
132
+
133
+ if options.ignore_invalid_files && model.documents.files.length > 0
134
+ log_and_remove_invalid_files model, max_file_size
135
+ end
136
+ model.report_rootmodel_status()
137
+
138
+ puts "Checking for duplicate organizations..."
139
+ possible_duplicates = model.organizations.find_duplicates_by(:name, :organization_number)
140
+ puts "Found #{possible_duplicates.length} organization duplicate sets in rootmodel, based on name and organization number"
141
+
142
+ puts "Starting sharding of model..."
143
+ sharder = MoveToGo::ShardHelper.new(options.shard_size)
144
+ models_to_serialize = sharder.shard_model(model)
145
+
146
+ if models_to_serialize.length > 1
147
+ puts "Import is large and will be broken into #{models_to_serialize.length} files"
148
+ end
149
+
150
+ models_to_serialize.each_with_index do |model, i|
151
+ go_data_zip = options.output.nil? == true ? "go" : options.output
152
+ go_data_zip += "_#{i}.zip"
153
+ go_files = options.output_documents.nil? == true ? nil : ::File.basename(options.output_documents,File.extname(options.output_documents))
154
+ model.save_to_zip(go_data_zip, go_files)
155
+ puts "Source has been been converted into '#{go_data_zip}'."
156
+ puts " - and files into '#{go_files}.zip'." if !go_files.nil?
157
+ if !warnings_msg.empty?
158
+ puts "WARNINGS: "
159
+ puts warnings_msg
160
+ end
161
+ end
162
+ else
163
+ puts "ERROR: Source could not be converted due to:"
164
+ puts error_msg
165
+
166
+ if !options.ignore_invalid_files &&
167
+ model.documents.files.any? {|file| file.validate.empty?}
168
+ puts "move-to-go detected invalid files (see above), you can ignore these with the option --ignore-invalid-files."
169
+ end
170
+ end
171
+ end
172
+
173
+ private
174
+ def log_and_remove_invalid_files(model, max_file_size)
175
+ if model.documents.files.length > 0
176
+ file_log_header = "name;integration_id;path;organization.integrationid;organization.name;deal.integrationid;deal.name;file.size"
177
+ file_log = ""
178
+ files_to_remove = []
179
+ model.documents.files.with_progress(" - Trying to log files that can't be found...").each do |file|
180
+ if !::File.exists?(file.path_for_project)
181
+ file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};0\n"
182
+ files_to_remove.push file
183
+ elsif ::File.size(file.path_for_project) > max_file_size
184
+ file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};#{::File.size(file.path_for_project)}\n"
185
+ files_to_remove.push file
186
+ end
187
+ end
188
+
189
+ files_to_remove.each do |file|
190
+ model.documents.files.delete file
191
+ end
192
+
193
+ if file_log.length > 0
194
+ log_filename = 'move-to-go-invalid-files.csv'
195
+ ::File.open(log_filename, 'w') { |f|
196
+ f.puts file_log_header
197
+ f.puts file_log
198
+ }
199
+ puts "WARNING: move-to-go has invalid files (#{files_to_remove.length} of #{model.documents.files.length}). Filenames of all ignored files has been written to '#{log_filename}'."
200
+ else
201
+ puts "All files are OK."
202
+ end
203
+ end
204
+ end
205
+
206
+ private
207
+ def can_be_serialized?(rootmodel, ignore_invalid_files, max_file_size)
208
+ is_ok = false
209
+ error = rootmodel.sanity_check
210
+ if error.empty?
211
+ error, warnings = rootmodel.validate(ignore_invalid_files, max_file_size)
212
+
213
+ if error.empty?
214
+ is_ok = true
215
+ end
216
+ end
217
+
218
+ return [is_ok, error, warnings]
219
+ end
220
+
221
+ private
222
+ def is_valid_project?()
223
+ if Dir.exists?(RUNNER_DIR) == false
224
+ puts "This doesnt look like a move-to-go project. Are you in the right directory or did you mess with the '#{RUNNER_DIR}' folder?"
225
+ return false
226
+ end
227
+
228
+ runner_file = File.expand_path("./#{RUNNER_DIR}/runner.rb", Dir.pwd)
229
+ if File.exists?(runner_file) == false
230
+ puts "I can't run this project. Did you mess with the '#{RUNNER_DIR}' folder?"
231
+ return false
232
+ end
233
+
234
+ return true
235
+ end
236
+
237
+ private
238
+ def source_path()
239
+ File.expand_path("../sources", File.dirname(__FILE__))
240
+ end
241
+
242
+ private
243
+ def check_current_version()
244
+ if Gem.loaded_specs["move-to-go"] == nil
245
+ puts "Running source version, no version check"
246
+ return
247
+ end
248
+ uri = URI('https://rubygems.org/api/v1/versions/move-to-go/latest.json')
249
+
250
+ Net::HTTP.start(uri.host, uri.port,
251
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE,
252
+ :use_ssl => true) do |http|
253
+
254
+ request = Net::HTTP::Get.new uri
255
+ response = http.request request
256
+
257
+ latest_version = Gem::Version.new(JSON.parse(response.body)['version'])
258
+ current_version = Gem.loaded_specs["move-to-go"].version
259
+ outdated = latest_version > current_version
260
+
261
+ if outdated
262
+ puts "You are running an old version of move-to-go (#{current_version})"
263
+ puts "Please upgrade by running 'gem install move-to-go'"
264
+ exit
265
+ end
266
+ end
267
+ end
268
+
269
+ private
270
+ def display_current_version()
271
+ if Gem.loaded_specs["move-to-go"] == nil
272
+ current_version = "source"
273
+ else
274
+ current_version = Gem.loaded_specs["move-to-go"].version
275
+ end
276
+
277
+ puts "Version: #{current_version}"
278
+ puts
279
+ end
280
+ end
281
+
282
+ MoveToGoCommandLine.start(ARGV)
@@ -1,29 +1,29 @@
1
-
2
- module MoveToGo
3
- class CanBecomeImmutable
4
- def self.immutable_accessor(name)
5
- define_method(name) do
6
- return instance_variable_get("@#{name}")
7
- end
8
-
9
- define_method("#{name}=") do |value|
10
- raise_if_immutable
11
- instance_variable_set("@#{name}", value)
12
- end
13
- end
14
-
15
- def raise_if_immutable
16
- if @is_immutable
17
- raise ObjectIsImmutableError
18
- end
19
- end
20
-
21
- def set_is_immutable()
22
- @is_immutable = true
23
- end
24
-
25
- def is_immutable()
26
- @is_immutable
27
- end
28
- end
29
- end
1
+
2
+ module MoveToGo
3
+ class CanBecomeImmutable
4
+ def self.immutable_accessor(name)
5
+ define_method(name) do
6
+ return instance_variable_get("@#{name}")
7
+ end
8
+
9
+ define_method("#{name}=") do |value|
10
+ raise_if_immutable
11
+ instance_variable_set("@#{name}", value)
12
+ end
13
+ end
14
+
15
+ def raise_if_immutable
16
+ if @is_immutable
17
+ raise ObjectIsImmutableError
18
+ end
19
+ end
20
+
21
+ def set_is_immutable()
22
+ @is_immutable = true
23
+ end
24
+
25
+ def is_immutable()
26
+ @is_immutable
27
+ end
28
+ end
29
+ end