contentful-importer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -4
- data/README.md +31 -139
- data/bin/contentful-importer +8 -81
- data/contentful_importer.gemspec +3 -3
- data/lib/contentful/importer/command.rb +87 -0
- data/lib/contentful/importer/import.rb +24 -0
- data/lib/contentful/importer/import_assets.rb +23 -0
- data/lib/contentful/importer/import_entries.rb +23 -0
- data/lib/contentful/importer/import_model.rb +30 -0
- data/lib/contentful/importer/parallel_importer.rb +24 -1
- data/lib/contentful/importer/publish.rb +21 -0
- data/lib/contentful/importer/publish_assets.rb +23 -0
- data/lib/contentful/importer/publish_entries.rb +23 -0
- data/lib/contentful/importer/test_credentials.rb +17 -0
- data/lib/contentful/importer/version.rb +1 -1
- data/spec/lib/import_assets_spec.rb +20 -0
- data/spec/lib/import_entries_spec.rb +23 -0
- data/spec/lib/{migrator_spec.rb → import_model_spec.rb} +22 -53
- data/spec/lib/publish_assets_spec.rb +23 -0
- data/spec/lib/publish_entries_spec.rb +20 -0
- data/spec/lib/test_credentials_spec.rb +27 -0
- metadata +30 -13
- data/lib/contentful/importer/cli.rb +0 -15
- data/lib/contentful/importer/migrator.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 569b9ef01dc69598930b6340c14621c2a078f6d7
|
4
|
+
data.tar.gz: 71ad10863d5045c601823a4b3a369dd66d397e6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6448daef3961d265952d7b297b04c974b9deaba953982165a4006ffdbd9e105c65b7e56414748c2155fe2ab077c63374e212e5ed369dac1574134dafeea9f5c
|
7
|
+
data.tar.gz: 6205fff19db2ce9764517bfcdf93fa8122bb3ab21db6b04cf8420beb5fb7ec6f03038f076bb1a4a36128ca8c56657b34b556466ddfe9360b9ddd5ce508c1f491
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,8 +4,8 @@ PATH
|
|
4
4
|
contentful-importer (0.1.0)
|
5
5
|
activesupport (~> 4.1)
|
6
6
|
api_cache (~> 0.3.0)
|
7
|
+
claide (~> 0.8.1)
|
7
8
|
contentful-management (~> 0.5.0)
|
8
|
-
escort (~> 0.4.0)
|
9
9
|
http (~> 0.6)
|
10
10
|
i18n (~> 0.6)
|
11
11
|
json-schema (~> 2.5.0)
|
@@ -22,6 +22,7 @@ GEM
|
|
22
22
|
tzinfo (~> 1.1)
|
23
23
|
addressable (2.3.6)
|
24
24
|
api_cache (0.3.0)
|
25
|
+
claide (0.8.1)
|
25
26
|
contentful-management (0.5.0)
|
26
27
|
http (~> 0.6)
|
27
28
|
multi_json (~> 1)
|
@@ -29,8 +30,6 @@ GEM
|
|
29
30
|
safe_yaml (~> 1.0.0)
|
30
31
|
diff-lcs (1.2.5)
|
31
32
|
docile (1.1.5)
|
32
|
-
escort (0.4.0)
|
33
|
-
nesty
|
34
33
|
http (0.7.3)
|
35
34
|
http-form_data (~> 1.0.0)
|
36
35
|
http_parser.rb (~> 0.6.0)
|
@@ -42,7 +41,6 @@ GEM
|
|
42
41
|
addressable (~> 2.3)
|
43
42
|
minitest (5.5.1)
|
44
43
|
multi_json (1.10.1)
|
45
|
-
nesty (1.0.2)
|
46
44
|
rake (10.4.2)
|
47
45
|
rspec (3.1.0)
|
48
46
|
rspec-core (~> 3.1.0)
|
data/README.md
CHANGED
@@ -32,17 +32,19 @@ As a first step you should create a `settings.yml` file and fill in your credent
|
|
32
32
|
```yaml
|
33
33
|
#Contentful
|
34
34
|
access_token: access_token
|
35
|
-
|
35
|
+
organization_id: organization_id
|
36
36
|
```
|
37
37
|
|
38
|
+
Alternatively, you can also specify those options on the commandline.
|
39
|
+
|
38
40
|
**A Contentful OAuth access token can be created using the [Contentful Management API - documentation](https://www.contentful.com/developers/documentation/content-management-api/#getting-started)**
|
39
41
|
|
40
|
-
The Contentful organization
|
42
|
+
The Contentful organization ID can be found in your account settings, but you will only need to specify it if you are member of more than one organization.
|
41
43
|
|
42
44
|
Once you installed the Gem and created the YAML file with the settings you can invoke the tool using:
|
43
45
|
|
44
46
|
```bash
|
45
|
-
contentful-importer --
|
47
|
+
contentful-importer --configuration=settings.yml ACTION
|
46
48
|
```
|
47
49
|
|
48
50
|
## Step by step
|
@@ -53,21 +55,17 @@ contentful-importer --config-file settings.yml --action
|
|
53
55
|
#PATH to all data
|
54
56
|
data_dir: DEFINE_BEFORE_EXPORTING_DATA
|
55
57
|
|
58
|
+
#JSON describing your content model
|
59
|
+
content_model_json: PATH_TO_CONTENTFUL_MODEL_JSON_FILE
|
60
|
+
|
56
61
|
#Contentful credentials
|
57
62
|
access_token: ACCESS_TOKEN
|
58
63
|
organization_id: ORGANIZATION_ID
|
59
64
|
space_id: DEFINE_AFTER_CREATING_SPACE
|
60
65
|
default_locale: DEFINE_LOCALE_CODE
|
61
|
-
|
62
|
-
## CONTENTFUL STRUCTURE
|
63
|
-
contentful_structure_dir: PATH_TO_CONTENTFUL_STRUCTURE_JSON_FILE
|
64
|
-
|
65
|
-
## CONVERT CONTENTFUL MODEL TO CONTENTFUL IMPORT STRUCTURE
|
66
|
-
content_model_json: PATH_TO_CONTENTFUL_MODEL_JSON_FILE ## for input
|
67
|
-
converted_model_dir: PATH_TO_CONTENTFUL_MODEL_JSON_FILE ## for output
|
68
66
|
```
|
69
67
|
|
70
|
-
2.
|
68
|
+
2. First you need to create a content model using the [Contentful web application](www.contentful.com). Then you can download the content model using the content management api and use the content model for the import:
|
71
69
|
|
72
70
|
```bash
|
73
71
|
curl -X GET \
|
@@ -75,58 +73,50 @@ contentful-importer --config-file settings.yml --action
|
|
75
73
|
'https://api.contentful.com/spaces/SPACE_ID/content_types' > contentful_model.json
|
76
74
|
```
|
77
75
|
|
78
|
-
It will create ```contentful_model.json``` file, which you
|
79
|
-
|
80
|
-
```bash
|
81
|
-
contentful-importer --config-file settings.yml --convert-content-model-to-json
|
82
|
-
```
|
83
|
-
|
84
|
-
The converted content model will be saved as JSON file in the ```converted_model_dir``` path.
|
76
|
+
It will create ```contentful_model.json``` file, which you can pass to the tool via the `content_model_json` option. If you are using one of our exporter tools, this will not be necessary.
|
85
77
|
|
86
78
|
|
87
79
|
3. Once you have prepared the `content types`, `assets` and `entries` (for example using one of the existing extraction adapters or creating your own) they can be imported. It can be chosen to use one (default) or two parallel threads to speedup this process.
|
88
|
-
There are two steps to import entries and assets.
|
89
80
|
|
90
|
-
|
81
|
+
It is possible to import the everything in one step using the `import` action or to import content model, entries or assets individually:
|
91
82
|
|
92
83
|
```bash
|
93
|
-
contentful-importer --
|
84
|
+
contentful-importer --configuration=settings.yml import --threads=2
|
85
|
+
contentful-importer --configuration=settings.yml import-content-model
|
86
|
+
contentful-importer --configuration=settings.yml import-entries
|
87
|
+
contentful-importer --configuration=settings.yml import-assets
|
94
88
|
```
|
95
89
|
|
96
|
-
|
90
|
+
Optionally, two threads can be used for the import.
|
97
91
|
|
98
|
-
|
99
|
-
|
100
|
-
```
|
92
|
+
After each request the `success_thread_{0,1}.csv` or `success_assets.csv` file is updated. You can find those in `$data_dir/logs`.
|
93
|
+
If an entry or asset fails to be imported, it will end up in the `failure_thread_{0,1}.csv` or `failure_assets.csv` including the error message.
|
101
94
|
|
102
|
-
**Assets**
|
103
95
|
|
104
|
-
|
105
|
-
contentful-importer --config-file settings.yml --import-assets
|
106
|
-
```
|
107
|
-
|
108
|
-
After each request the `success_number_of_thread.csv` or `success_assets.csv` file is updated. You can find those in `data_dir/logs`.
|
109
|
-
If an entry or asset fails to be imported, it will end up in the `failure_number_of_thread.csv` or `assets_failure.csv` including the error message.
|
96
|
+
4. Publish entries and assets. After successfully importing the entries and assets to contentful, they need to be published in order to be available through the delivery API.
|
110
97
|
|
98
|
+
To publish everything that has been imported:
|
111
99
|
|
112
|
-
|
100
|
+
```bash
|
101
|
+
contentful-importer --configuration=settings.yml publish
|
102
|
+
```
|
113
103
|
|
114
104
|
To publish all entries use:
|
115
105
|
|
116
106
|
```bash
|
117
|
-
contentful-importer --
|
107
|
+
contentful-importer --configuration=settings.yml publish-entries
|
118
108
|
```
|
119
109
|
|
120
110
|
To publish all assets use:
|
121
111
|
|
122
112
|
```bash
|
123
|
-
contentful-importer --
|
113
|
+
contentful-importer --configuration=settings.yml publish-assets
|
124
114
|
```
|
125
115
|
|
126
116
|
or
|
127
117
|
|
128
118
|
```bash
|
129
|
-
contentful-importer --
|
119
|
+
contentful-importer --configuration=settings.yml publish-assets --threads=2
|
130
120
|
```
|
131
121
|
|
132
122
|
After each request the ```success_published_entries.csv``` or ```success_published_assets.csv``` file is updated. You can find those in ```data_dir/logs```.
|
@@ -135,108 +125,10 @@ contentful-importer --config-file settings.yml --action
|
|
135
125
|
|
136
126
|
## Actions
|
137
127
|
|
138
|
-
To display all actions use the
|
139
|
-
|
140
|
-
```bash
|
141
|
-
contentful-importer -h
|
142
|
-
```
|
143
|
-
|
144
|
-
#### --convert-content-model-to-json
|
145
|
-
|
146
|
-
If you already have an existing content model for a space it can be downloaded and used for the import:
|
147
|
-
|
148
|
-
```bash
|
149
|
-
curl -X GET \
|
150
|
-
-H 'Authorization: Bearer ACCESS_TOKEN' \
|
151
|
-
'https://api.contentful.com/spaces/SPACE_ID/content_types' > contentful_model.json
|
152
|
-
```
|
153
|
-
|
154
|
-
In the **settings.yml** specify the PATH to **contentful_model.json**.
|
155
|
-
|
156
|
-
```yaml
|
157
|
-
#Dump file with content model.
|
158
|
-
content_model_json: example_path/contentful_model.json
|
159
|
-
```
|
160
|
-
|
161
|
-
and define the PATH where you want to save the converted JSON file:
|
162
|
-
|
163
|
-
```yaml
|
164
|
-
#File with converted structure of contentful model. Almost ready to import.
|
165
|
-
converted_model_dir: example_path/contentful_structure.json
|
166
|
-
```
|
167
|
-
|
168
|
-
#### --create-contentful-model-from-json
|
169
|
-
|
170
|
-
Create the content model based on the structure defined in ```contentful_structure.json```.
|
171
|
-
This will generate content types files that are ready to be imported.
|
172
|
-
Set the `contentful_structure_dir` variable to point to the structure file in your settings file.
|
173
|
-
|
174
|
-
Path to collections: **data_dir/collections**
|
175
|
-
|
176
|
-
```bash
|
177
|
-
contentful-importer --config-file settings.yml --create-contentful-model-from-json
|
178
|
-
```
|
179
|
-
|
180
|
-
This is optional if you intend to create your own content structure as JSON files and not use the web application for it.
|
181
|
-
|
182
|
-
#### --import-content-types ARGS
|
183
|
-
|
184
|
-
To import the content types into an existing space use `--space_id SPACE_ID`:
|
185
|
-
|
186
|
-
```bash
|
187
|
-
contentful-importer --config-file settings.yml --import-content-types --space_id SPACE_ID
|
188
|
-
```
|
189
|
-
|
190
|
-
To create a new Space and import content types use `--space_name NAME`:
|
191
|
-
|
192
|
-
```bash
|
193
|
-
contentful-importer --config-file settings.yml --import-content-types --space_name NAME
|
194
|
-
```
|
195
|
-
|
196
|
-
#### --import
|
197
|
-
|
198
|
-
Import the entries with a single thread:
|
199
|
-
|
200
|
-
```bash
|
201
|
-
contentful-importer --config-file settings.yml --import
|
202
|
-
```
|
203
|
-
|
204
|
-
or using two threads
|
205
|
-
|
206
|
-
```bash
|
207
|
-
contentful-importer --config-file settings.yml --import --threads 2
|
208
|
-
```
|
209
|
-
|
210
|
-
#### --import-assets
|
211
|
-
|
212
|
-
Import the assets:
|
213
|
-
|
214
|
-
```bash
|
215
|
-
contentful-importer --config-file settings.yml --import-assets
|
216
|
-
```
|
217
|
-
|
218
|
-
#### --publish-entries
|
219
|
-
|
220
|
-
To publish all entries:
|
221
|
-
|
222
|
-
```bash
|
223
|
-
contentful-importer --config-file settings.yml --publish-entries
|
224
|
-
```
|
225
|
-
|
226
|
-
Number of threads that are used in the publishing of entries is dependent on `--threads` argument, which you specified when import data.
|
227
|
-
|
228
|
-
#### --publish-assets ARGS
|
229
|
-
|
230
|
-
You can publish all assets with single Thread:
|
231
|
-
|
232
|
-
```bash
|
233
|
-
contentful-importer --config-file settings.yml --publish-assets
|
234
|
-
```
|
235
|
-
|
236
|
-
or add ```--threads``` argument to use multiple Threads:
|
128
|
+
To display all actions use the `--help` option:
|
237
129
|
|
238
130
|
```bash
|
239
|
-
contentful-importer --
|
131
|
+
contentful-importer --help
|
240
132
|
```
|
241
133
|
|
242
134
|
#### --test-credentials
|
@@ -244,14 +136,14 @@ contentful-importer --config-file settings.yml --publish-assets --threads 2
|
|
244
136
|
Before importing any content you can verify that your credentials in the **settings.yml** file are correct:
|
245
137
|
|
246
138
|
```bash
|
247
|
-
contentful-importer --
|
139
|
+
contentful-importer --configuration=settings.yml test-credentials
|
248
140
|
```
|
249
141
|
|
250
142
|
#### --validate-schema
|
251
143
|
|
252
144
|
After preparing the files to import, you can validate the JSON schema, use command:
|
253
145
|
|
254
|
-
```contentful-importer --
|
146
|
+
```contentful-importer --configuration=settings.yml validate-schema```
|
255
147
|
|
256
148
|
This comes in handy when you want to create your own extraction adapter.
|
257
149
|
|
@@ -312,7 +204,7 @@ Before you start importing the content make sure you read [how to use it](https:
|
|
312
204
|
|
313
205
|
#### Space ID
|
314
206
|
|
315
|
-
After [importing the content types](https://github.com/contentful/generic-importer.rb#--import-content-types-args) to the Space, you need to specify the `space_id` parameter in the settings.
|
207
|
+
After [importing the content types](https://github.com/contentful/generic-importer.rb#--import-content-types-args) to the Space, you need to specify the `space_id` parameter in the settings.
|
316
208
|
|
317
209
|
|
318
210
|
Example:
|
data/bin/contentful-importer
CHANGED
@@ -1,85 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Escort::App.create do |app|
|
10
|
-
app.summary 'Executable file of Generic-importer Gem'
|
11
|
-
|
12
|
-
app.options do |opts|
|
13
|
-
opts.opt :file, '--config-file', short: '-f', long: '--config-file', type: :string
|
14
|
-
|
15
|
-
app.command '--create-contentful-model-from-json' do |command|
|
16
|
-
command.summary 'Create content types json files, based on contentful_structure.json file.'
|
17
|
-
command.action do |options, arguments|
|
18
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
19
|
-
end
|
20
|
-
end
|
21
|
-
app.command '--convert-content-model-to-json' do |command|
|
22
|
-
command.summary 'Transform contentful model to contentful structure ready to import. View README'
|
23
|
-
command.action do |options, arguments|
|
24
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
25
|
-
end
|
26
|
-
end
|
27
|
-
app.command '--import-content-types' do |command|
|
28
|
-
command.summary 'Find an existing Space or create new one. Import content types to Contentful platform'
|
29
|
-
command.requires_arguments false
|
30
|
-
command.options do |opts|
|
31
|
-
opts.opt :space_id, 'space_id', short: '-s', long: '--space_id', type: :string
|
32
|
-
opts.opt :space_name, 'space_name', short: :none, long: '--space_name', type: :string
|
33
|
-
end
|
34
|
-
command.action do |options, arguments|
|
35
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
36
|
-
end
|
37
|
-
end
|
38
|
-
app.command '--import' do |command|
|
39
|
-
command.summary 'Import entries to Contentful platform'
|
40
|
-
command.options do |opts|
|
41
|
-
opts.opt :threads, 'threads', short: '-t', long: '--threads', type: :integer, default: 1
|
42
|
-
opts.validate(:threads, 'argument must be set to 1 or 2 exclusive. ') { |option| option > 0 && option <= 2 }
|
43
|
-
end
|
44
|
-
command.action do |options, arguments|
|
45
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
46
|
-
end
|
47
|
-
end
|
48
|
-
app.command '--test-credentials' do |command|
|
49
|
-
command.summary 'Check your Contentful-management credentials'
|
50
|
-
command.action do |options, arguments|
|
51
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
52
|
-
end
|
53
|
-
end
|
54
|
-
app.command '--import-assets' do |command|
|
55
|
-
command.summary 'Import only assets'
|
56
|
-
command.action do |options, arguments|
|
57
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
58
|
-
end
|
59
|
-
end
|
3
|
+
if $PROGRAM_NAME == __FILE__
|
4
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
8
|
+
end
|
60
9
|
|
61
|
-
|
62
|
-
command.summary 'Publish all entries'
|
63
|
-
command.action do |options, arguments|
|
64
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
65
|
-
end
|
66
|
-
end
|
10
|
+
require 'contentful/importer/command'
|
67
11
|
|
68
|
-
|
69
|
-
command.summary 'Publish all assets'
|
70
|
-
command.options do |opts|
|
71
|
-
opts.opt :threads, 'threads', short: '-t', long: '--threads', type: :integer, default: 1
|
72
|
-
opts.validate(:threads, 'argument must be set to 1 or 2 exclusive. ') { |option| option > 0 && option <= 2 }
|
73
|
-
end
|
74
|
-
command.action do |options, arguments|
|
75
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
76
|
-
end
|
77
|
-
end
|
78
|
-
app.command '--validate-schema' do |command|
|
79
|
-
command.summary 'Validate entries JSON schema'
|
80
|
-
command.action do |options, arguments|
|
81
|
-
Contentful::Importer::CLI.new(options, arguments).execute
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
12
|
+
Contentful::Importer::Command.run(ARGV)
|
data/contentful_importer.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency 'http', '~> 0.
|
22
|
+
spec.add_dependency 'http', '~> 0.8'
|
23
23
|
spec.add_dependency 'multi_json', '~> 1'
|
24
|
-
spec.add_dependency 'contentful-management', '~> 0.
|
24
|
+
spec.add_dependency 'contentful-management', '~> 0.7.0'
|
25
25
|
spec.add_dependency 'activesupport','~> 4.1'
|
26
|
-
spec.add_dependency '
|
26
|
+
spec.add_dependency 'claide','~> 0.8.1'
|
27
27
|
spec.add_dependency 'api_cache', ' ~> 0.3.0'
|
28
28
|
spec.add_dependency 'i18n', '~> 0.6'
|
29
29
|
spec.add_dependency 'json-schema', '~> 2.5.0'
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'claide'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require_relative 'parallel_importer'
|
5
|
+
require_relative 'configuration'
|
6
|
+
require_relative 'converters/contentful_model_to_json'
|
7
|
+
require_relative 'json_schema_validator'
|
8
|
+
|
9
|
+
module Contentful
|
10
|
+
module Importer
|
11
|
+
class PlainInformative < StandardError
|
12
|
+
include CLAide::InformativeError
|
13
|
+
end
|
14
|
+
|
15
|
+
class Informative < PlainInformative
|
16
|
+
def message
|
17
|
+
"[!] #{super}".red
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Command < CLAide::Command
|
22
|
+
require_relative 'import'
|
23
|
+
require_relative 'import_assets'
|
24
|
+
require_relative 'import_entries'
|
25
|
+
require_relative 'import_model'
|
26
|
+
require_relative 'publish'
|
27
|
+
require_relative 'publish_assets'
|
28
|
+
require_relative 'publish_entries'
|
29
|
+
require_relative 'test_credentials'
|
30
|
+
|
31
|
+
attr_reader :importer, :converter, :config, :json_validator
|
32
|
+
|
33
|
+
self.abstract_command = true
|
34
|
+
self.command = 'contentful-importer'
|
35
|
+
self.version = VERSION
|
36
|
+
self.description = 'Import structured JSON data to Contentful.'
|
37
|
+
|
38
|
+
def self.options
|
39
|
+
[['--configuration=config.yaml', 'Use the given configuration file.'],
|
40
|
+
['--access_token=XXX', 'The CMA access token to be used.']].concat(super).sort
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.data_options
|
44
|
+
[['--data_dir=data', 'The directory to use for input, temporary data and logs.']]
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.space_options
|
48
|
+
[['--organization_id=YYY', 'Select organization if you are member of more than one.'],
|
49
|
+
['--space_id=ZZZ', 'Import into an existing space.'],
|
50
|
+
['--space_name=ZZZ', 'Import into a new space with the given name.'],
|
51
|
+
['--default_locale=de-DE', 'Locale to use if a new space is being created.']]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.thread_options
|
55
|
+
[['--threads=1', 'Number of threads to be used, can be either 1 or 2.']]
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize(args)
|
59
|
+
super(args)
|
60
|
+
|
61
|
+
@settings = {}
|
62
|
+
|
63
|
+
settings_file = args.option('configuration')
|
64
|
+
@settings.merge!(YAML.load_file(settings_file)) if settings_file
|
65
|
+
|
66
|
+
# CLI options can override settings of the same name
|
67
|
+
self.class.options.map { |opt| opt.first.split('=').first.split('-').last }.each do |opt|
|
68
|
+
arg = args.option(opt)
|
69
|
+
arg = arg.to_i if opt == 'threads'
|
70
|
+
@settings[opt] = arg if arg
|
71
|
+
end
|
72
|
+
|
73
|
+
@settings = @settings.with_indifferent_access
|
74
|
+
@settings[:threads] = 1 if @settings[:threads].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
@config = Configuration.new(@settings)
|
79
|
+
@importer = ParallelImporter.new(@config)
|
80
|
+
@converter = ContentfulModelToJson.new(@config)
|
81
|
+
@json_validator = JsonSchemaValidator.new(@config)
|
82
|
+
|
83
|
+
json_validator.validate_schemas
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Importer
|
3
|
+
class Import < Command
|
4
|
+
require_relative 'import_assets'
|
5
|
+
require_relative 'import_entries'
|
6
|
+
require_relative 'import_model'
|
7
|
+
|
8
|
+
self.command = 'import'
|
9
|
+
self.summary = 'Import content model, entries and assets.'
|
10
|
+
|
11
|
+
def self.options
|
12
|
+
ImportModel.options.concat(ImportEntries.options).concat(ImportAssets.options).uniq.sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
super
|
17
|
+
|
18
|
+
ImportModel.import(@settings, @converter, @importer)
|
19
|
+
ImportEntries.import(@settings, @importer)
|
20
|
+
ImportAssets.import(@importer)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Importer
|
5
|
+
class ImportAssets < Command
|
6
|
+
self.command = 'import-assets'
|
7
|
+
self.summary = 'Import assets.'
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
super.concat(data_options).sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.import(importer)
|
14
|
+
importer.import_only_assets
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
super
|
19
|
+
self.class.import(@importer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Importer
|
5
|
+
class ImportEntries < Command
|
6
|
+
self.command = 'import-entries'
|
7
|
+
self.summary = 'Import entries.'
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
super.concat(data_options).concat(space_options).concat(thread_options).sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.import(settings, importer)
|
14
|
+
importer.import_data(settings[:threads])
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
super
|
19
|
+
self.class.import(@settings, @importer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Importer
|
5
|
+
class ImportModel < Command
|
6
|
+
self.command = 'import-content-model'
|
7
|
+
self.summary = 'Import the content model.'
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
[['--content_model_json=model.json',
|
11
|
+
'Content model to use for import. Uses the data directory by default.']
|
12
|
+
].concat(super).concat(data_options).concat(space_options).sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.import(settings, converter, importer)
|
16
|
+
if settings['content_model_json']
|
17
|
+
converter.convert_to_import_form
|
18
|
+
converter.create_content_type_json
|
19
|
+
end
|
20
|
+
|
21
|
+
importer.create_contentful_model(settings)
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
super
|
26
|
+
self.class.import(@settings, @converter, @importer)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -195,8 +195,8 @@ module Contentful
|
|
195
195
|
collection_attributes = JSON.parse(File.read(file_path))
|
196
196
|
content_type = create_new_content_type(space, collection_attributes)
|
197
197
|
logger.info "Importing content_type: #{content_type.name}"
|
198
|
+
content_type.properties[:displayField] = collection_attributes['displayField'] or ""
|
198
199
|
create_content_type_fields(collection_attributes, content_type)
|
199
|
-
content_type.update(displayField: collection_attributes['displayField']) if collection_attributes['displayField']
|
200
200
|
active_status(content_type.activate)
|
201
201
|
end
|
202
202
|
end
|
@@ -317,6 +317,9 @@ module Contentful
|
|
317
317
|
def create_field(field)
|
318
318
|
field_params = {id: field['id'], name: field['name'], required: field['required']}
|
319
319
|
field_params.merge!(additional_field_params(field))
|
320
|
+
if field['validations']
|
321
|
+
field_params[:validations] = create_validations(field['validations'])
|
322
|
+
end
|
320
323
|
logger.info "Creating field: #{field_params[:type]}"
|
321
324
|
create_content_type_field(field_params)
|
322
325
|
end
|
@@ -329,7 +332,27 @@ module Contentful
|
|
329
332
|
field.link_type = field_params[:link_type]
|
330
333
|
field.required = field_params[:required]
|
331
334
|
field.items = field_params[:items]
|
335
|
+
field.validations = field_params[:validations] if field_params[:validations]
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
def create_validations(validations_params)
|
340
|
+
validations = validations_params.each_with_object([]) do |validation_params, validations|
|
341
|
+
validations << create_validation(validation_params)
|
332
342
|
end
|
343
|
+
return validations
|
344
|
+
end
|
345
|
+
|
346
|
+
def create_validation(validation_params)
|
347
|
+
validation = Contentful::Management::Validation.new
|
348
|
+
|
349
|
+
mappings = {'linkContentType' => 'link_content_type'}
|
350
|
+
type = validation_params['type']
|
351
|
+
type = mappings[type] if mappings[type]
|
352
|
+
|
353
|
+
params = validation_params['params']
|
354
|
+
validation.send("#{type}=", params)
|
355
|
+
return validation
|
333
356
|
end
|
334
357
|
|
335
358
|
def active_status(ct_object)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Importer
|
3
|
+
class Publish < Command
|
4
|
+
require_relative 'publish_assets'
|
5
|
+
require_relative 'publish_entries'
|
6
|
+
|
7
|
+
self.command = 'publish'
|
8
|
+
self.summary = 'Publish entries and assets.'
|
9
|
+
|
10
|
+
def self.options
|
11
|
+
PublishAssets.options.concat(PublishEntries.options).uniq.sort
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
super
|
16
|
+
PublishAssets.publish(@settings, @importer)
|
17
|
+
PublishEntries.publish(@importer)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Importer
|
5
|
+
class PublishAssets < Command
|
6
|
+
self.command = 'publish-assets'
|
7
|
+
self.summary = 'Publish assets.'
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
super.concat(data_options).concat(thread_options).sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.publish(settings, importer)
|
14
|
+
importer.publish_assets_in_threads(settings[:threads])
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
super
|
19
|
+
self.class.publish(@settings, @importer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Importer
|
5
|
+
class PublishEntries < Command
|
6
|
+
self.command = 'publish-entries'
|
7
|
+
self.summary = 'Publish entries.'
|
8
|
+
|
9
|
+
def self.options
|
10
|
+
super.concat(data_options).sort
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.publish(importer)
|
14
|
+
importer.publish_entries_in_threads
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
super
|
19
|
+
self.class.publish(@importer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Importer
|
3
|
+
class TestCredentials < Command
|
4
|
+
self.command = 'test-credentials'
|
5
|
+
self.summary = 'Test given credentials against the server.'
|
6
|
+
|
7
|
+
def self.options
|
8
|
+
super.concat(space_options).sort
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
super
|
13
|
+
importer.test_credentials
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './lib/contentful/importer/import_assets'
|
3
|
+
|
4
|
+
module Contentful
|
5
|
+
module Importer
|
6
|
+
describe ImportAssets do
|
7
|
+
before do
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'import an assets to Contentful' do
|
13
|
+
vcr('import_assets') do
|
14
|
+
command = ImportAssets.parse(@args << 'import-assets')
|
15
|
+
command.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './lib/contentful/importer/import_entries'
|
3
|
+
|
4
|
+
module Contentful
|
5
|
+
module Importer
|
6
|
+
describe ImportEntries do
|
7
|
+
before do
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'import an entires to Contentful with two Threads' do
|
13
|
+
vcr('import_entries') do
|
14
|
+
allow(FileUtils).to receive(:rm_r)
|
15
|
+
command = ImportEntries.parse(@args + ['import-entries', '--threads=2'])
|
16
|
+
import = command.run
|
17
|
+
expect(import).to be_a Array
|
18
|
+
expect(import.count).to eq 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require './lib/contentful/importer/
|
2
|
+
require './lib/contentful/importer/import_model'
|
3
3
|
|
4
4
|
module Contentful
|
5
5
|
module Importer
|
6
|
-
describe
|
6
|
+
describe ImportModel do
|
7
7
|
before do
|
8
|
-
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}"]
|
9
10
|
end
|
11
|
+
|
10
12
|
it 'convert contentful model to contentful structure' do
|
11
|
-
|
13
|
+
allow_any_instance_of(ParallelImporter).to receive(:create_contentful_model)
|
14
|
+
|
15
|
+
command = ImportModel.parse(@args << 'import-content-model')
|
16
|
+
command.run
|
17
|
+
|
12
18
|
contentful_structure = load_fixture('settings/contentful_structure_test')
|
13
19
|
expect(contentful_structure.count).to eq 4
|
14
20
|
expect(contentful_structure['Jobs']).to include(id: '4L1bg4WQ5aWQMiE82ouag', name: 'Jobs', displayField: 'title', description: nil)
|
@@ -18,7 +24,11 @@ module Contentful
|
|
18
24
|
end
|
19
25
|
|
20
26
|
it 'create content type json files from contentful structure' do
|
21
|
-
|
27
|
+
allow_any_instance_of(ParallelImporter).to receive(:create_contentful_model)
|
28
|
+
|
29
|
+
command = ImportModel.parse(@args << 'import-content-model')
|
30
|
+
command.run
|
31
|
+
|
22
32
|
expect(Dir.glob('spec/fixtures/import_files/collections/*').count).to eq 4
|
23
33
|
content_types_files = %w(comment.json job_skills.json jobs.json profile.json user.json)
|
24
34
|
Dir.glob('spec/fixtures/import_files/collections/*') do |directory_name|
|
@@ -46,58 +56,17 @@ module Contentful
|
|
46
56
|
|
47
57
|
it 'create content type json files from contentful structure' do
|
48
58
|
vcr('import_content_types') do
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'import an entires to Contentful with two Threads' do
|
54
|
-
vcr('import_entries') do
|
55
|
-
allow(FileUtils).to receive(:rm_r)
|
56
|
-
import = Migrator.new(@setting_file).run('--import', threads: 2)
|
57
|
-
expect(import).to be_a Array
|
58
|
-
expect(import.count).to eq 2
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'import an assets to Contentful' do
|
63
|
-
vcr('import_assets') do
|
64
|
-
Migrator.new(@setting_file).run('--import-assets')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'publish an entires' do
|
69
|
-
vcr('publish_entries') do
|
70
|
-
Migrator.new(@setting_file).run('--publish-entries')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'publish an assets' do
|
75
|
-
vcr('publish_asset') do
|
76
|
-
expect_any_instance_of(ParallelImporter).to receive(:publish_status).exactly(4).times
|
77
|
-
expect_any_instance_of(ParallelImporter).to receive(:create_log_file).with('success_published_assets')
|
78
|
-
Migrator.new(@setting_file).run('--publish-assets', threads: 1)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'test credentials' do
|
83
|
-
it 'when valid' do
|
84
|
-
vcr('valid_credentials') do
|
85
|
-
expect_any_instance_of(Logger).to receive(:info).with('Contentful Management API credentials: OK')
|
86
|
-
Migrator.new(@setting_file).run('--test-credentials')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
it 'when invalid' do
|
90
|
-
vcr('invalid_credentials') do
|
91
|
-
expect_any_instance_of(Logger).to receive(:info).with('Contentful Management API credentials: INVALID (check README)')
|
92
|
-
Migrator.new(@setting_file).run('--test-credentials')
|
93
|
-
end
|
59
|
+
command = ImportModel.parse(@args + ['import-content-model', '--space_id=space_id'])
|
60
|
+
command.run
|
94
61
|
end
|
95
62
|
end
|
96
63
|
|
97
64
|
it 'validate JSON schema' do
|
98
|
-
|
65
|
+
allow_any_instance_of(ParallelImporter).to receive(:create_contentful_model)
|
66
|
+
|
67
|
+
command = ImportModel.parse(@args << 'import-content-model')
|
68
|
+
expect { command.run }.not_to raise_error
|
99
69
|
end
|
100
|
-
|
101
70
|
end
|
102
71
|
end
|
103
|
-
end
|
72
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './lib/contentful/importer/publish_assets'
|
3
|
+
|
4
|
+
module Contentful
|
5
|
+
module Importer
|
6
|
+
describe PublishAssets do
|
7
|
+
before do
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'publish an assets' do
|
13
|
+
vcr('publish_asset') do
|
14
|
+
expect_any_instance_of(ParallelImporter).to receive(:publish_status).exactly(4).times
|
15
|
+
expect_any_instance_of(ParallelImporter).to receive(:create_log_file).with('success_published_assets')
|
16
|
+
|
17
|
+
command = PublishAssets.parse(@args + ['publish-assets', '--threads=1'])
|
18
|
+
command.run
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './lib/contentful/importer/publish_entries'
|
3
|
+
|
4
|
+
module Contentful
|
5
|
+
module Importer
|
6
|
+
describe ImportModel do
|
7
|
+
before do
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'publish an entires' do
|
13
|
+
vcr('publish_entries') do
|
14
|
+
command = PublishEntries.parse(@args << 'publish-entries')
|
15
|
+
command.run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require './lib/contentful/importer/test_credentials'
|
3
|
+
|
4
|
+
module Contentful
|
5
|
+
module Importer
|
6
|
+
describe TestCredentials do
|
7
|
+
before do
|
8
|
+
setting_file = 'spec/fixtures/settings/settings.yml'
|
9
|
+
@args = ["--configuration=#{setting_file}", 'test-credentials']
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'when valid' do
|
13
|
+
vcr('valid_credentials') do
|
14
|
+
expect_any_instance_of(Logger).to receive(:info).with('Contentful Management API credentials: OK')
|
15
|
+
TestCredentials.parse(@args).run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'when invalid' do
|
20
|
+
vcr('invalid_credentials') do
|
21
|
+
expect_any_instance_of(Logger).to receive(:info).with('Contentful Management API credentials: INVALID (check README)')
|
22
|
+
TestCredentials.parse(@args).run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful-importer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH (Andreas Tiefenthaler)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '4.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: claide
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.8.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.8.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: api_cache
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,15 +229,22 @@ files:
|
|
229
229
|
- example_settings/contentful_structure.json
|
230
230
|
- example_settings/files_meaning.txt
|
231
231
|
- example_settings/settings.yml
|
232
|
-
- lib/contentful/importer/
|
232
|
+
- lib/contentful/importer/command.rb
|
233
233
|
- lib/contentful/importer/configuration.rb
|
234
234
|
- lib/contentful/importer/converters/content_types_structure_creator.rb
|
235
235
|
- lib/contentful/importer/converters/contentful_model_to_json.rb
|
236
236
|
- lib/contentful/importer/data_organizer.rb
|
237
|
+
- lib/contentful/importer/import.rb
|
238
|
+
- lib/contentful/importer/import_assets.rb
|
239
|
+
- lib/contentful/importer/import_entries.rb
|
240
|
+
- lib/contentful/importer/import_model.rb
|
237
241
|
- lib/contentful/importer/json_schema_validator.rb
|
238
|
-
- lib/contentful/importer/migrator.rb
|
239
242
|
- lib/contentful/importer/mime_content_type.rb
|
240
243
|
- lib/contentful/importer/parallel_importer.rb
|
244
|
+
- lib/contentful/importer/publish.rb
|
245
|
+
- lib/contentful/importer/publish_assets.rb
|
246
|
+
- lib/contentful/importer/publish_entries.rb
|
247
|
+
- lib/contentful/importer/test_credentials.rb
|
241
248
|
- lib/contentful/importer/version.rb
|
242
249
|
- spec/fixtures/import_files/assets/image/image_1.json
|
243
250
|
- spec/fixtures/import_files/assets/image/image_2.json
|
@@ -317,9 +324,14 @@ files:
|
|
317
324
|
- spec/fixtures/vcr_cassettes/publish_entries.yml
|
318
325
|
- spec/fixtures/vcr_cassettes/valid_credentials.yml
|
319
326
|
- spec/lib/configuration_spec.rb
|
327
|
+
- spec/lib/import_assets_spec.rb
|
328
|
+
- spec/lib/import_entries_spec.rb
|
329
|
+
- spec/lib/import_model_spec.rb
|
320
330
|
- spec/lib/importer/parallel_importer_spec.rb
|
321
331
|
- spec/lib/json_schema_validator_spec.rb
|
322
|
-
- spec/lib/
|
332
|
+
- spec/lib/publish_assets_spec.rb
|
333
|
+
- spec/lib/publish_entries_spec.rb
|
334
|
+
- spec/lib/test_credentials_spec.rb
|
323
335
|
- spec/spec_helper.rb
|
324
336
|
- spec/support/db_rows_json.rb
|
325
337
|
- spec/support/shared_configuration.rb
|
@@ -427,9 +439,14 @@ test_files:
|
|
427
439
|
- spec/fixtures/vcr_cassettes/publish_entries.yml
|
428
440
|
- spec/fixtures/vcr_cassettes/valid_credentials.yml
|
429
441
|
- spec/lib/configuration_spec.rb
|
442
|
+
- spec/lib/import_assets_spec.rb
|
443
|
+
- spec/lib/import_entries_spec.rb
|
444
|
+
- spec/lib/import_model_spec.rb
|
430
445
|
- spec/lib/importer/parallel_importer_spec.rb
|
431
446
|
- spec/lib/json_schema_validator_spec.rb
|
432
|
-
- spec/lib/
|
447
|
+
- spec/lib/publish_assets_spec.rb
|
448
|
+
- spec/lib/publish_entries_spec.rb
|
449
|
+
- spec/lib/test_credentials_spec.rb
|
433
450
|
- spec/spec_helper.rb
|
434
451
|
- spec/support/db_rows_json.rb
|
435
452
|
- spec/support/shared_configuration.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative 'migrator'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module Contentful
|
5
|
-
module Importer
|
6
|
-
class CLI < Escort::ActionCommand::Base
|
7
|
-
|
8
|
-
def execute
|
9
|
-
setting_file = YAML.load_file(global_options[:file])
|
10
|
-
Migrator.new(setting_file).run(command_name, command_options)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require_relative 'parallel_importer'
|
2
|
-
require_relative 'configuration'
|
3
|
-
require_relative 'converters/contentful_model_to_json'
|
4
|
-
require_relative 'json_schema_validator'
|
5
|
-
|
6
|
-
module Contentful
|
7
|
-
module Importer
|
8
|
-
class Migrator
|
9
|
-
|
10
|
-
attr_reader :importer, :converter, :config, :json_validator
|
11
|
-
|
12
|
-
def initialize(settings)
|
13
|
-
@config = Configuration.new(settings)
|
14
|
-
@importer = ParallelImporter.new(@config)
|
15
|
-
@converter = ContentfulModelToJson.new(@config)
|
16
|
-
@json_validator = JsonSchemaValidator.new(@config)
|
17
|
-
end
|
18
|
-
|
19
|
-
def run(action, options = {})
|
20
|
-
case action.to_s
|
21
|
-
when '--create-contentful-model-from-json'
|
22
|
-
converter.create_content_type_json
|
23
|
-
when '--import-content-types'
|
24
|
-
importer.create_contentful_model(options)
|
25
|
-
when '--import'
|
26
|
-
importer.import_data(options[:threads])
|
27
|
-
when '--convert-content-model-to-json'
|
28
|
-
converter.convert_to_import_form
|
29
|
-
when '--publish-entries'
|
30
|
-
importer.publish_entries_in_threads
|
31
|
-
when '--test-credentials'
|
32
|
-
importer.test_credentials
|
33
|
-
when '--import-assets'
|
34
|
-
importer.import_only_assets
|
35
|
-
when '--publish-assets'
|
36
|
-
importer.publish_assets_in_threads(options[:threads])
|
37
|
-
when '--validate-schema'
|
38
|
-
json_validator.validate_schemas
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|