drupal-exporter 0.0.1
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 +7 -0
- data/.gitignore +39 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +72 -0
- data/LICENSE +22 -0
- data/README.md +251 -0
- data/Rakefile +9 -0
- data/bin/drupal-exporter +37 -0
- data/drupal_exporter.gemspec +34 -0
- data/drupal_settings/boolean_columns.yml +2 -0
- data/drupal_settings/drupal_content_types.json +47 -0
- data/drupal_settings/drupal_settings.yml +23 -0
- data/lib/cli.rb +13 -0
- data/lib/configuration.rb +46 -0
- data/lib/converters/content_types_structure_creator.rb +60 -0
- data/lib/converters/contentful_model_to_json.rb +109 -0
- data/lib/drupal/content_type.rb +151 -0
- data/lib/drupal/export.rb +69 -0
- data/lib/drupal/file_managed.rb +42 -0
- data/lib/drupal/tag.rb +52 -0
- data/lib/drupal/user.rb +46 -0
- data/lib/drupal/vocabulary.rb +42 -0
- data/lib/migrator.rb +28 -0
- data/lib/version.rb +3 -0
- data/spec/fixtures/database_rows/content_type_article.json +14 -0
- data/spec/fixtures/database_rows/image.json +10 -0
- data/spec/fixtures/database_rows/node_content_type_article.json +15 -0
- data/spec/fixtures/database_rows/node_content_type_blog.json +15 -0
- data/spec/fixtures/database_rows/tag.json +8 -0
- data/spec/fixtures/database_rows/user.json +18 -0
- data/spec/fixtures/database_rows/vocabulary.json +9 -0
- data/spec/fixtures/drupal/assets/file/file_4.json +6 -0
- data/spec/fixtures/drupal/entries/article/article_5.json +24 -0
- data/spec/fixtures/drupal/entries/tag/tag_1.json +9 -0
- data/spec/fixtures/drupal/entries/user/user_1.json +6 -0
- data/spec/fixtures/drupal/entries/vocabulary/vocabulary_3.json +6 -0
- data/spec/fixtures/json_responses/article.json +24 -0
- data/spec/fixtures/json_responses/image.json +6 -0
- data/spec/fixtures/json_responses/tag.json +9 -0
- data/spec/fixtures/json_responses/vocabulary.json +6 -0
- data/spec/fixtures/settings/boolean_columns.yml +2 -0
- data/spec/fixtures/settings/drupal_content_types.json +47 -0
- data/spec/fixtures/settings/drupal_settings.yml +17 -0
- data/spec/lib/configuration_spec.rb +18 -0
- data/spec/lib/drupal/content_type_spec.rb +123 -0
- data/spec/lib/drupal/export_spec.rb +33 -0
- data/spec/lib/drupal/file_managed_spec.rb +52 -0
- data/spec/lib/drupal/tag_spec.rb +60 -0
- data/spec/lib/drupal/user_spec.rb +49 -0
- data/spec/lib/drupal/vocabulary_spec.rb +51 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/db_rows_json.rb +15 -0
- data/spec/support/shared_configuration.rb +20 -0
- metadata +297 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require_relative 'tag'
|
6
|
+
require_relative 'vocabulary'
|
7
|
+
require_relative 'user'
|
8
|
+
require_relative 'content_type'
|
9
|
+
require_relative 'file_managed'
|
10
|
+
|
11
|
+
module Contentful
|
12
|
+
module Exporter
|
13
|
+
module Drupal
|
14
|
+
class Export
|
15
|
+
|
16
|
+
attr_reader :config, :boolean_columns
|
17
|
+
|
18
|
+
def initialize(settings)
|
19
|
+
@config = settings
|
20
|
+
@boolean_columns = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_data_as_json
|
24
|
+
boolean_columns << YAML.load_file(config.config['drupal_boolean_columns']) if config.config['drupal_boolean_columns']
|
25
|
+
tags
|
26
|
+
vocabularies
|
27
|
+
users
|
28
|
+
content_types
|
29
|
+
files
|
30
|
+
end
|
31
|
+
|
32
|
+
def write_json_to_file(path, data)
|
33
|
+
File.open(path, 'w') do |file|
|
34
|
+
file.write(JSON.pretty_generate(data))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_directory(path)
|
39
|
+
FileUtils.mkdir_p(path) unless File.directory?(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def tags
|
45
|
+
Tag.new(self, config).save_tags_as_json
|
46
|
+
end
|
47
|
+
|
48
|
+
def vocabularies
|
49
|
+
Vocabulary.new(self, config).save_vocabularies_as_json
|
50
|
+
end
|
51
|
+
|
52
|
+
def users
|
53
|
+
User.new(self, config).save_users_as_json
|
54
|
+
end
|
55
|
+
|
56
|
+
def files
|
57
|
+
FileManaged.new(self, config).save_files_as_json
|
58
|
+
end
|
59
|
+
|
60
|
+
def content_types
|
61
|
+
config.drupal_content_types.each do |content_type, schema|
|
62
|
+
ContentType.new(self, config, content_type, schema).save_content_types_as_json
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Exporter
|
3
|
+
module Drupal
|
4
|
+
class FileManaged
|
5
|
+
|
6
|
+
attr_reader :exporter, :config
|
7
|
+
|
8
|
+
def initialize(exporter, config)
|
9
|
+
@exporter, @config = exporter, config
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_files_as_json
|
13
|
+
exporter.create_directory("#{config.assets_dir}/file")
|
14
|
+
config.db[:file_managed].each do |file_row|
|
15
|
+
extract_data(file_row)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_data(file_row)
|
22
|
+
puts "Saving file - id: #{file_row[:fid]}"
|
23
|
+
db_object = map_fields(file_row)
|
24
|
+
exporter.write_json_to_file("#{config.assets_dir}/file/#{db_object[:id]}.json", db_object)
|
25
|
+
end
|
26
|
+
|
27
|
+
def map_fields(row, result = {})
|
28
|
+
result[:id] = id(row[:fid])
|
29
|
+
result[:title] = row[:filename]
|
30
|
+
result[:description] = row[:description]
|
31
|
+
result[:url] = "#{config.drupal_base_url}/#{row[:uri].gsub(' ', '%20').gsub('public://','sites/default/files/')}"
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def id(file_id)
|
36
|
+
"file_#{file_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/drupal/tag.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Exporter
|
3
|
+
module Drupal
|
4
|
+
class Tag
|
5
|
+
|
6
|
+
attr_reader :exporter, :config
|
7
|
+
|
8
|
+
def initialize(exporter, config)
|
9
|
+
@exporter, @config = exporter, config
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_tags_as_json
|
13
|
+
exporter.create_directory("#{config.entries_dir}/tag")
|
14
|
+
config.db[:taxonomy_term_data].each do |tag_row|
|
15
|
+
extract_data(tag_row)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_data(tag_row)
|
22
|
+
puts "Saving tag - id: #{tag_row[:tid]}"
|
23
|
+
db_object = map_fields(tag_row)
|
24
|
+
exporter.write_json_to_file("#{config.entries_dir}/tag/#{db_object[:id]}.json", db_object)
|
25
|
+
end
|
26
|
+
|
27
|
+
def map_fields(row, result = {})
|
28
|
+
result[:id] = id(row[:tid])
|
29
|
+
result[:name] = row[:name]
|
30
|
+
result[:description] = row[:description]
|
31
|
+
result[:vocabulary] = vocabulary(row[:vid])
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def id(tag_id)
|
36
|
+
'tag_' + tag_id.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def vocabulary(tag_vocabulary_id)
|
40
|
+
vocabulary = tag_vocabulary(tag_vocabulary_id)
|
41
|
+
{type: 'EntryVocabulary', id: "vocabulary_#{vocabulary[:vid]}"}
|
42
|
+
end
|
43
|
+
|
44
|
+
def tag_vocabulary(tag_vocabulary_id)
|
45
|
+
config.db[:taxonomy_vocabulary].where(vid: tag_vocabulary_id).first
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/lib/drupal/user.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Exporter
|
3
|
+
module Drupal
|
4
|
+
class User
|
5
|
+
|
6
|
+
attr_reader :exporter, :config
|
7
|
+
|
8
|
+
def initialize(exporter, config)
|
9
|
+
@exporter, @config = exporter, config
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_users_as_json
|
13
|
+
exporter.create_directory("#{config.entries_dir}/user")
|
14
|
+
config.db[:users].each do |user_row|
|
15
|
+
extract_data(user_row)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_data(user_row)
|
22
|
+
puts "Saving user - id: #{user_row[:uid]}"
|
23
|
+
db_object = map_fields(user_row)
|
24
|
+
exporter.write_json_to_file("#{config.entries_dir}/user/#{db_object[:id]}.json", db_object)
|
25
|
+
end
|
26
|
+
|
27
|
+
def map_fields(row, result = {})
|
28
|
+
result[:id] = id(row[:uid])
|
29
|
+
result[:name] = row[:name]
|
30
|
+
result[:email] = row[:mail]
|
31
|
+
result[:created_at] = created_at(row[:created])
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def id(user_id)
|
36
|
+
"user_#{user_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def created_at(timestamp)
|
40
|
+
Time.at(timestamp).to_datetime
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Contentful
|
2
|
+
module Exporter
|
3
|
+
module Drupal
|
4
|
+
class Vocabulary
|
5
|
+
|
6
|
+
attr_reader :exporter, :config
|
7
|
+
|
8
|
+
def initialize(exporter, config)
|
9
|
+
@exporter, @config = exporter, config
|
10
|
+
end
|
11
|
+
|
12
|
+
def save_vocabularies_as_json
|
13
|
+
exporter.create_directory("#{config.entries_dir}/vocabulary")
|
14
|
+
config.db[:taxonomy_vocabulary].each do |vocabulary_row|
|
15
|
+
extract_data(vocabulary_row)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def extract_data(vocabulary_row)
|
22
|
+
puts "Saving vocabulary - id: #{vocabulary_row[:vid]}"
|
23
|
+
db_object = map_fields(vocabulary_row)
|
24
|
+
exporter.write_json_to_file("#{config.entries_dir}/vocabulary/#{db_object[:id]}.json", db_object)
|
25
|
+
end
|
26
|
+
|
27
|
+
def map_fields(row, result = {})
|
28
|
+
result[:id] = id(row[:vid])
|
29
|
+
result[:name] = row[:name]
|
30
|
+
result[:description] = row[:description]
|
31
|
+
result[:machine_name] = row[:machine_name]
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def id(vocabulary_id)
|
36
|
+
"vocabulary_#{vocabulary_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/migrator.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'drupal/export'
|
2
|
+
require_relative 'converters/contentful_model_to_json'
|
3
|
+
require_relative 'configuration'
|
4
|
+
|
5
|
+
|
6
|
+
class Migrator
|
7
|
+
|
8
|
+
attr_reader :exporter, :config, :converter
|
9
|
+
|
10
|
+
def initialize(settings)
|
11
|
+
@config = Contentful::Configuration.new(settings)
|
12
|
+
@exporter = Contentful::Exporter::Drupal::Export.new(config)
|
13
|
+
@converter = Contentful::Converter::ContentfulModelToJson.new(config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(action)
|
17
|
+
case action.to_s
|
18
|
+
when '--extract-to-json'
|
19
|
+
exporter.save_data_as_json
|
20
|
+
when '--convert-content-model-to-json'
|
21
|
+
converter.convert_to_import_form
|
22
|
+
when '--create-contentful-model-from-json'
|
23
|
+
converter.create_content_type_json
|
24
|
+
else
|
25
|
+
fail ArgumentError, 'You have entered incorrect action! View README'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"entity_type": "node",
|
3
|
+
"bundle": "article",
|
4
|
+
"deleted": 0,
|
5
|
+
"entity_id": 5,
|
6
|
+
"revision_id": 5,
|
7
|
+
"language": "und",
|
8
|
+
"delta": 0,
|
9
|
+
"field_image_fid": 1,
|
10
|
+
"field_image_alt": "alternate text",
|
11
|
+
"field_image_title": "",
|
12
|
+
"field_image_width": 449,
|
13
|
+
"field_image_height": 441
|
14
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"uid": 1,
|
3
|
+
"name": "username",
|
4
|
+
"pass": "password",
|
5
|
+
"mail": "useremail@gmail.com",
|
6
|
+
"theme": "",
|
7
|
+
"signature": "",
|
8
|
+
"signature_format": null,
|
9
|
+
"created": 1417517150,
|
10
|
+
"access": 1418026959,
|
11
|
+
"login": 1417605965,
|
12
|
+
"status": 1,
|
13
|
+
"timezone": "Europe/Berlin",
|
14
|
+
"language": "",
|
15
|
+
"picture": 0,
|
16
|
+
"init": "useremail@gmail.com",
|
17
|
+
"data": "b:0;"
|
18
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"id": "article_5",
|
3
|
+
"title": "Article first title",
|
4
|
+
"author": {
|
5
|
+
"type": "Author",
|
6
|
+
"id": "user_1"
|
7
|
+
},
|
8
|
+
"tags": [
|
9
|
+
{
|
10
|
+
"type": "EntryTag",
|
11
|
+
"id": "tag_1"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"type": "EntryTag",
|
15
|
+
"id": "tag_2"
|
16
|
+
}
|
17
|
+
],
|
18
|
+
"created_at": "2014-12-02T12:36:19+01:00",
|
19
|
+
"body": "Article first body!",
|
20
|
+
"image": {
|
21
|
+
"type": "File",
|
22
|
+
"id": "file_1"
|
23
|
+
}
|
24
|
+
}
|