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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +39 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +72 -0
  8. data/LICENSE +22 -0
  9. data/README.md +251 -0
  10. data/Rakefile +9 -0
  11. data/bin/drupal-exporter +37 -0
  12. data/drupal_exporter.gemspec +34 -0
  13. data/drupal_settings/boolean_columns.yml +2 -0
  14. data/drupal_settings/drupal_content_types.json +47 -0
  15. data/drupal_settings/drupal_settings.yml +23 -0
  16. data/lib/cli.rb +13 -0
  17. data/lib/configuration.rb +46 -0
  18. data/lib/converters/content_types_structure_creator.rb +60 -0
  19. data/lib/converters/contentful_model_to_json.rb +109 -0
  20. data/lib/drupal/content_type.rb +151 -0
  21. data/lib/drupal/export.rb +69 -0
  22. data/lib/drupal/file_managed.rb +42 -0
  23. data/lib/drupal/tag.rb +52 -0
  24. data/lib/drupal/user.rb +46 -0
  25. data/lib/drupal/vocabulary.rb +42 -0
  26. data/lib/migrator.rb +28 -0
  27. data/lib/version.rb +3 -0
  28. data/spec/fixtures/database_rows/content_type_article.json +14 -0
  29. data/spec/fixtures/database_rows/image.json +10 -0
  30. data/spec/fixtures/database_rows/node_content_type_article.json +15 -0
  31. data/spec/fixtures/database_rows/node_content_type_blog.json +15 -0
  32. data/spec/fixtures/database_rows/tag.json +8 -0
  33. data/spec/fixtures/database_rows/user.json +18 -0
  34. data/spec/fixtures/database_rows/vocabulary.json +9 -0
  35. data/spec/fixtures/drupal/assets/file/file_4.json +6 -0
  36. data/spec/fixtures/drupal/entries/article/article_5.json +24 -0
  37. data/spec/fixtures/drupal/entries/tag/tag_1.json +9 -0
  38. data/spec/fixtures/drupal/entries/user/user_1.json +6 -0
  39. data/spec/fixtures/drupal/entries/vocabulary/vocabulary_3.json +6 -0
  40. data/spec/fixtures/json_responses/article.json +24 -0
  41. data/spec/fixtures/json_responses/image.json +6 -0
  42. data/spec/fixtures/json_responses/tag.json +9 -0
  43. data/spec/fixtures/json_responses/vocabulary.json +6 -0
  44. data/spec/fixtures/settings/boolean_columns.yml +2 -0
  45. data/spec/fixtures/settings/drupal_content_types.json +47 -0
  46. data/spec/fixtures/settings/drupal_settings.yml +17 -0
  47. data/spec/lib/configuration_spec.rb +18 -0
  48. data/spec/lib/drupal/content_type_spec.rb +123 -0
  49. data/spec/lib/drupal/export_spec.rb +33 -0
  50. data/spec/lib/drupal/file_managed_spec.rb +52 -0
  51. data/spec/lib/drupal/tag_spec.rb +60 -0
  52. data/spec/lib/drupal/user_spec.rb +49 -0
  53. data/spec/lib/drupal/vocabulary_spec.rb +51 -0
  54. data/spec/spec_helper.rb +11 -0
  55. data/spec/support/db_rows_json.rb +15 -0
  56. data/spec/support/shared_configuration.rb +20 -0
  57. metadata +297 -0
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "file_4",
3
+ "title": "ruby.png",
4
+ "description": null,
5
+ "url": "http://example_hostname.com/sites/default/files/ruby.png"
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "tag_1",
3
+ "name": "article tag",
4
+ "description": "desc",
5
+ "vocabulary": {
6
+ "type": "EntryVocabulary",
7
+ "id": "vocabulary_1"
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "vocabulary_3",
3
+ "name": "tag_name",
4
+ "description": "Very bad tag",
5
+ "machine_name": "bad"
6
+ }
@@ -0,0 +1,2 @@
1
+ - field_if_content_type
2
+ - field_boolean
@@ -0,0 +1,47 @@
1
+ // mechanic_name_of_content_type : {
2
+ // contentful_api_field : column_mechanic_name
3
+ // }
4
+
5
+ {
6
+ "article": {
7
+ "body": "body",
8
+ "image": "field_image"
9
+ },
10
+ "page": {
11
+ "body": "body"
12
+ },
13
+ "blog": {
14
+ "body": "body"
15
+ },
16
+ "content_type": {
17
+ "body": "body",
18
+ "age": "field_age",
19
+ "if_content_type": "field_if_content_type",
20
+ "decimal": "field_decimal"
21
+ },
22
+ "second_content_type": {
23
+ "body": "body",
24
+ "firma": "field_firma"
25
+ },
26
+ "content_all_types": {
27
+ "body": "body",
28
+ "file": "field_file",
29
+ "image_sec": "field_sec_image",
30
+ "integer": "field_integer",
31
+ "boolean": "field_boolean",
32
+ "decimal": "field_sec_decimal",
33
+ "list_float": "field_list_float",
34
+ "list_integer": "field_list_integer",
35
+ "list_text": "field_list_text",
36
+ "long_text": "field_long_text",
37
+ "text_summary": "field_text_summary",
38
+ "term_tagging": {
39
+ "table": "field_term_tagging"
40
+ },
41
+ "text": "field_text"
42
+ },
43
+ "assety": {
44
+ "body": "body",
45
+ "assets": "field_asset"
46
+ }
47
+ }
@@ -0,0 +1,17 @@
1
+ #PATH to all data
2
+ data_dir: /tmp/data
3
+
4
+ ########## EXPORT DATA ##########
5
+
6
+ #Connecting to a database
7
+ adapter: mysql2
8
+ host: localhost
9
+ database: drupal
10
+ user: szpryc
11
+ password: root
12
+
13
+ # DRUPAL
14
+
15
+ drupal_content_types_json: /Users/piotrprotas/Documents/RUBY_CONTENTUL/drupal_adapter/drupal_settings/drupal_content_types.json
16
+ drupal_boolean_columns: /Users/piotrprotas/Documents/RUBY_CONTENTUL/drupal_adapter/drupal_settings/boolean_columns.yml
17
+ drupal_base_url: http://example_hostname.com
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require './lib/configuration'
3
+ require './spec/support/shared_configuration.rb'
4
+
5
+ module Contentful
6
+ describe Configuration do
7
+
8
+ include_context 'shared_configuration'
9
+
10
+ it 'initialize' do
11
+ expect(@config.assets_dir).to eq 'spec/fixtures/drupal/assets'
12
+ expect(@config.collections_dir).to eq 'spec/fixtures/drupal/collections'
13
+ expect(@config.data_dir).to eq 'spec/fixtures/drupal'
14
+ expect(@config.entries_dir).to eq 'spec/fixtures/drupal/entries'
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+ require './lib/drupal/content_type'
3
+ require './lib/drupal/export'
4
+ require './spec/support/shared_configuration.rb'
5
+ require './spec/support/db_rows_json.rb'
6
+
7
+ module Contentful
8
+ module Exporter
9
+ module Drupal
10
+ describe ContentType do
11
+
12
+ include_context 'shared_configuration'
13
+
14
+ before do
15
+ @exporter = Export.new(@config)
16
+ @type = 'article'
17
+ @row = json_fixture('database_rows/node_content_type_article')
18
+ @content_type = ContentType.new(@exporter, @config, @type, @row)
19
+ end
20
+
21
+ it 'initialize' do
22
+ expect(@content_type.config).to be_a Contentful::Configuration
23
+ expect(@content_type.exporter).to be_a Contentful::Exporter::Drupal::Export
24
+ end
25
+
26
+ it 'extract_data' do
27
+ expect_any_instance_of(ContentType).to receive(:map_fields) { json_fixture('json_responses/article') }
28
+ @content_type.send(:extract_data, @row)
29
+ article = entry_fixture('article/article_5')
30
+ expect(article).to include(id: 'article_5', title: 'Article first title', body: 'Article first body!')
31
+ expect(article[:tags].count).to eq 2
32
+ expect(article[:image]).to include(type: 'File', id: 'file_1')
33
+ end
34
+
35
+ it 'map_fields' do
36
+ expect_any_instance_of(ContentType).to receive(:set_default_data) { {data: 'default'} }
37
+ expect_any_instance_of(ContentType).to receive(:find_related_data) { {data2: 'related'} }
38
+ result = @content_type.send(:map_fields, @row)
39
+ expect(result.count).to eq 2
40
+ expect(result).to include(data: 'default', data2: 'related')
41
+ end
42
+
43
+ it 'id' do
44
+ content_type_id = @content_type.send(:id, @row[:nid])
45
+ expect(content_type_id).to eq "#{@type}_#{@row[:nid]}"
46
+ end
47
+
48
+ it 'author' do
49
+ author = @content_type.send(:author, @row[:uid])
50
+ expect(author).to include(type: 'Author', id: 'user_1')
51
+ end
52
+
53
+ it 'related_table_name' do
54
+ related_table = @content_type.send(:related_table_name, 'test')
55
+ expect(related_table).to eq :field_data_test
56
+ end
57
+
58
+ it 'field_name' do
59
+ field_name = @content_type.send(:field_name, 'test')
60
+ expect(field_name).to eq :test_value
61
+ end
62
+
63
+ it 'created_at' do
64
+ created_at = @content_type.send(:created_at, 1418292000)
65
+ expect(created_at).to eq 'Thu, 11 Dec 2014 11:00:00 +0100'
66
+ end
67
+
68
+ context 'convert_type_value' do
69
+ it 'convert to float when BigDecimal type' do
70
+ big_decimal = BigDecimal.new('123')
71
+ value = @content_type.send(:convert_type_value, big_decimal, 'test_column')
72
+ expect(value).to eq 123.0
73
+ end
74
+ it 'convert to true value when boolean type' do
75
+ @exporter.boolean_columns << ['test_column']
76
+ value = @content_type.send(:convert_type_value, 1, 'test_column')
77
+ expect(value).to be true
78
+ end
79
+ it 'convert to false value when boolean type' do
80
+ @exporter.boolean_columns << ['test_column']
81
+ value = @content_type.send(:convert_type_value, 0, 'test_column')
82
+ expect(value).to be false
83
+ end
84
+ it 'convert to nil value when boolean type' do
85
+ @exporter.boolean_columns << ['test_column']
86
+ value = @content_type.send(:convert_type_value, nil, 'test_column')
87
+ expect(value).to be_nil
88
+ end
89
+ it 'return value' do
90
+ value = @content_type.send(:convert_type_value, 'value', 'just_value')
91
+ expect(value).to eq 'value'
92
+ end
93
+ end
94
+
95
+ context 'boolean_column' do
96
+ it 'return true' do
97
+ @exporter.boolean_columns << ['test_column']
98
+ value = @content_type.send(:boolean_column?, 'test_column')
99
+ expect(value).to be true
100
+ end
101
+ it 'return false' do
102
+ value = @content_type.send(:boolean_column?, 'some_column')
103
+ expect(value).to be false
104
+ end
105
+ end
106
+
107
+ it 'link_asset_to_content_type' do
108
+ file_asset_id = 22
109
+ value = @content_type.send(:link_asset_to_content_type, file_asset_id)
110
+ expect(value).to include(type: 'File', id: "file_#{file_asset_id}")
111
+ end
112
+
113
+ it 'get_file_id' do
114
+ expect_any_instance_of(ContentType).to receive(:file_id) { 1 }
115
+ related_row = [json_fixture('database_rows/content_type_article')]
116
+ value = @content_type.send(:get_file_id, related_row, 'table_name')
117
+ expect(value).to include(type: 'File', id: 'file_1')
118
+ end
119
+
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require './lib/drupal/export'
3
+ require './spec/support/shared_configuration.rb'
4
+
5
+ module Contentful
6
+ module Exporter
7
+ module Drupal
8
+ describe Export do
9
+
10
+ include_context 'shared_configuration'
11
+
12
+ before do
13
+ @exporter = Export.new(@config)
14
+ end
15
+
16
+ it 'initialize' do
17
+ expect(@exporter.config).to be_kind_of Contentful::Configuration
18
+ expect(@exporter.boolean_columns).to be_a Array
19
+ end
20
+
21
+ it 'save_data_as_json' do
22
+ expect_any_instance_of(Export).to receive(:tags)
23
+ expect_any_instance_of(Export).to receive(:vocabularies)
24
+ expect_any_instance_of(Export).to receive(:users)
25
+ expect_any_instance_of(Export).to receive(:content_types)
26
+ expect_any_instance_of(Export).to receive(:files)
27
+ @exporter.save_data_as_json
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require './lib/drupal/file_managed'
3
+ require './lib/drupal/export'
4
+ require './spec/support/shared_configuration.rb'
5
+ require './spec/support/db_rows_json.rb'
6
+
7
+ module Contentful
8
+ module Exporter
9
+ module Drupal
10
+ describe FileManaged do
11
+
12
+ include_context 'shared_configuration'
13
+
14
+ before do
15
+ exporter = Export.new(@config)
16
+ @file = FileManaged.new(exporter, @config)
17
+ @row = json_fixture('database_rows/image')
18
+ end
19
+
20
+ it 'initialize' do
21
+ expect(@file.config).to be_a Contentful::Configuration
22
+ expect(@file.exporter).to be_a Contentful::Exporter::Drupal::Export
23
+ end
24
+
25
+ it 'save_files_as_json' do
26
+ expect_any_instance_of(Contentful::Configuration).to receive(:db) { {file_managed: [json_fixture('database_rows/image')]} }
27
+ expect_any_instance_of(FileManaged).to receive(:extract_data) { json_fixture('json_responses/image') }
28
+ @file.save_files_as_json
29
+ end
30
+
31
+ it 'extract_data' do
32
+ expect_any_instance_of(FileManaged).to receive_message_chain(:map_fields) { json_fixture('json_responses/image') }
33
+ @file.send(:extract_data, @row)
34
+ file = asset_fixture('file/file_4')
35
+ expect(file).to include(id: 'file_4', title: 'ruby.png', url: 'http://example_hostname.com/sites/default/files/ruby.png')
36
+ end
37
+
38
+ it 'map fields' do
39
+ result = @file.send(:map_fields, @row)
40
+ expect(result).to include(id: 'file_1', title: 'Screen Shot 2014-11-27 at 12.34.47 PM.png', url: 'http://example_hostname.com/sites/default/files/field/image/Screen%20Shot%202014-11-27%20at%2012.34.47%20PM.png')
41
+ end
42
+
43
+ it 'id' do
44
+ file_id = @row[:fid]
45
+ id = @file.send(:id, file_id)
46
+ expect(id).to eq "file_#{file_id}"
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require './lib/drupal/tag'
3
+ require './lib/drupal/export'
4
+ require './spec/support/shared_configuration.rb'
5
+ require './spec/support/db_rows_json.rb'
6
+
7
+ module Contentful
8
+ module Exporter
9
+ module Drupal
10
+ describe Tag do
11
+
12
+ include_context 'shared_configuration'
13
+
14
+ before do
15
+ exporter = Export.new(@config)
16
+ @tag = Tag.new(exporter, @config)
17
+ @row = json_fixture('database_rows/tag')
18
+ end
19
+
20
+ it 'initialize' do
21
+ expect(@tag.config).to be_a Contentful::Configuration
22
+ expect(@tag.exporter).to be_a Contentful::Exporter::Drupal::Export
23
+ end
24
+
25
+ it 'save_tags_as_json' do
26
+ expect_any_instance_of(Contentful::Configuration).to receive(:db) { {taxonomy_term_data: [json_fixture('database_rows/tag')]} }
27
+ expect_any_instance_of(Tag).to receive(:extract_data) { json_fixture('json_responses/tag') }
28
+ @tag.save_tags_as_json
29
+ end
30
+
31
+ it 'extract_data' do
32
+ expect_any_instance_of(Tag).to receive_message_chain(:map_fields) { json_fixture('json_responses/tag') }
33
+ @tag.send(:extract_data, @row)
34
+ tag_fixture = entry_fixture('tag/tag_1')
35
+ expect(tag_fixture).to include(id: 'tag_1', name: 'article tag', description: 'desc')
36
+ expect(tag_fixture[:vocabulary]).to include(type: 'EntryVocabulary', id: 'vocabulary_1')
37
+ end
38
+
39
+ it 'map_fields' do
40
+ expect_any_instance_of(Tag).to receive(:vocabulary) { {type: 'EntryVocabulary', id: 'vocabulary_1'} }
41
+ tag = @tag.send(:map_fields, @row)
42
+ expect(tag).to include(id: 'tag_1', name: 'article tag', description: 'desc')
43
+ expect(tag[:vocabulary]).to include(type: 'EntryVocabulary', id: 'vocabulary_1')
44
+ end
45
+
46
+ it 'id' do
47
+ tag_id = @tag.send(:id, @row[:tid])
48
+ expect(tag_id).to eq 'tag_1'
49
+ end
50
+
51
+ it 'vocabulary' do
52
+ expect_any_instance_of(Tag).to receive(:tag_vocabulary).with(1).and_return(json_fixture('database_rows/vocabulary'))
53
+ vocabulary = @tag.send(:vocabulary, @row[:vid])
54
+ expect(vocabulary).to include(type: 'EntryVocabulary', id: 'vocabulary_3')
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require './lib/drupal/user'
3
+ require './lib/drupal/export'
4
+ require './spec/support/shared_configuration.rb'
5
+ require './spec/support/db_rows_json.rb'
6
+
7
+ module Contentful
8
+ module Exporter
9
+ module Drupal
10
+ describe User do
11
+
12
+ include_context 'shared_configuration'
13
+
14
+ before do
15
+ exporter = Export.new(@config)
16
+ @user = User.new(exporter, @config)
17
+ @row = json_fixture('database_rows/user')
18
+ end
19
+
20
+ it 'initialize' do
21
+ expect(@user.config).to be_a Contentful::Configuration
22
+ expect(@user.exporter).to be_a Contentful::Exporter::Drupal::Export
23
+ end
24
+
25
+ it 'save_users_as_json' do
26
+ expect_any_instance_of(Contentful::Configuration).to receive_message_chain(:db) { {users: [json_fixture('database_rows/user')]} }
27
+ @user.save_users_as_json
28
+ end
29
+
30
+ it 'extract_data' do
31
+ @user.send(:extract_data, @row)
32
+ user = entry_fixture('user/user_1')
33
+ expect(user).to include(id: 'user_1')
34
+ end
35
+
36
+ it 'map_fields' do
37
+ user = @user.send(:map_fields, @row)
38
+ expect(user).to include(id: 'user_1', email: 'useremail@gmail.com', name: 'username', created_at: 'Tue, 02 Dec 2014 11:45:50 +0100')
39
+ end
40
+
41
+ it 'id' do
42
+ tag_id = @user.send(:id, @row[:uid])
43
+ expect(tag_id).to eq 'user_1'
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end