workarea-magento_migrator 1.0.0.pre → 1.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 +4 -4
- data/.gitignore +2 -1
- data/Gemfile +5 -2
- data/config/data/catalog_category.yml +1 -3
- data/config/initializers/magento_db.rb +5 -0
- data/config/magento_db_config.yml +23 -0
- data/lib/tasks/catalog_catagories.rake +6 -2
- data/lib/workarea/magento_migrator/catalog_category.rb +34 -191
- data/lib/workarea/magento_migrator/magento_base.rb +0 -8
- data/lib/workarea/magento_migrator/sql_connection.rb +1 -1
- data/lib/workarea/magento_migrator/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b79282dc21e0e6f7d61b271ed7ea5a75c956fe25813f906083c1bb369ed0e5cc
|
4
|
+
data.tar.gz: 40744d2261823e59cb02969f965e344575a11b0fe4bf60ae0f9937b3e29337fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c9cfd8516502aa6d4394c05891336f87fb6e3d4879ca405af6736ff16089f7e0b821f4ebeb6a18ec476e3983e5f0e48184951e97b9592bdfc4cb39f32b2c803
|
7
|
+
data.tar.gz: 1280e0d35fb409d7304942692e4735fc16760aae3017f6ec4b665abdb3bbee8dbea6d36e27760d95b768aecf27e7fbef9b6dc2a8958a13ca65b9d5d1c7694532
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -11,6 +11,9 @@ gemspec
|
|
11
11
|
# Git. Remember to move these dependencies to your gemspec before releasing
|
12
12
|
# your gem to rubygems.org.
|
13
13
|
|
14
|
-
|
15
|
-
gem '
|
14
|
+
group :development, :test do
|
15
|
+
gem 'mysql2', '~> 0.5.3'
|
16
|
+
# To use a debugger
|
17
|
+
gem 'byebug',
|
18
|
+
end
|
16
19
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
columns:
|
2
2
|
eav:
|
3
3
|
- description
|
4
|
+
- bottom_content
|
4
5
|
- meta_description
|
5
6
|
- meta_keywords
|
6
7
|
- category_name_seo_long
|
@@ -28,7 +29,6 @@ columns:
|
|
28
29
|
- position
|
29
30
|
- level
|
30
31
|
- children_count
|
31
|
-
|
32
32
|
taxons:
|
33
33
|
- name
|
34
34
|
- position
|
@@ -51,5 +51,3 @@ columns:
|
|
51
51
|
- url_prefix
|
52
52
|
- is_active
|
53
53
|
- is_anchor
|
54
|
-
|
55
|
-
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
adapter: 'mysql2'
|
15
|
+
host: '127.0.0.1'
|
16
|
+
port: '3306'
|
17
|
+
username: 'root'
|
18
|
+
password: 'okkkkkkkk'
|
19
|
+
database: 'murals-pd'
|
20
|
+
batch_size: 10000
|
21
|
+
encoding: 'utf8'
|
22
|
+
pool: 5
|
23
|
+
timeout: 5000
|
@@ -9,8 +9,12 @@ namespace :magento_migrator do
|
|
9
9
|
puts Workarea::MagentoMigrator::CatalogCategory.select_query
|
10
10
|
end
|
11
11
|
|
12
|
-
task :
|
13
|
-
Workarea::MagentoMigrator::CatalogCategory.
|
12
|
+
task :content_pages_query => :environment do
|
13
|
+
puts Workarea::MagentoMigrator::CatalogCategory.select_content_pages_query
|
14
|
+
end
|
15
|
+
|
16
|
+
task :categories_content => :environment do
|
17
|
+
puts Workarea::MagentoMigrator::CatalogCategory.categories_content
|
14
18
|
end
|
15
19
|
|
16
20
|
task :import_catagories => :environment do
|
@@ -11,224 +11,67 @@ module Workarea
|
|
11
11
|
@@table_name ||= 'catalog_category'
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def select_content_pages_query
|
15
15
|
select_query = "SELECT #{select_columns} FROM #{table_name}_entity e #{join_clause} "
|
16
16
|
select_query += "\nwhere e.entity_id not in (#{ids_to_include}) and e.parent_id>1 and e.level >1"
|
17
17
|
end
|
18
18
|
|
19
19
|
def catalog_category_menu
|
20
|
-
client.query(
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_taxons
|
24
|
-
cc_menu = {}
|
25
|
-
(2..6).to_a.each do |level|
|
26
|
-
statement = client.prepare(MENU_QUERY)
|
27
|
-
res = statement.execute(level, level-1)
|
28
|
-
res.to_a.map{|ccm| ccm['name']}
|
29
|
-
end
|
30
|
-
|
31
|
-
cc_menu
|
20
|
+
client.query(select_content_pages_query).to_a
|
32
21
|
end
|
33
22
|
|
34
23
|
def import_content_pages
|
35
|
-
File.open("#{
|
24
|
+
File.open("#{Rails.root.to_s}/data/content_pages.json", "w"){ |f|
|
36
25
|
f.write(JSON.pretty_generate(catalog_category_menu))
|
37
26
|
}
|
38
27
|
end
|
39
28
|
|
40
|
-
def
|
41
|
-
File.open("#{
|
42
|
-
f.write(JSON.pretty_generate(
|
29
|
+
def import_catagories
|
30
|
+
File.open("#{Rails.root.to_s}/data/categories.json", "w"){ |f|
|
31
|
+
f.write(JSON.pretty_generate(categories.to_a))
|
32
|
+
}
|
33
|
+
File.open("#{Rails.root.to_s}/data/soft_categories.json", "w"){ |f|
|
34
|
+
f.write(JSON.pretty_generate(soft_categories.to_a))
|
43
35
|
}
|
44
36
|
end
|
45
37
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
def delete_all
|
64
|
-
Workarea::Navigation::Taxon.delete_all
|
65
|
-
Workarea::Navigation::Menu.delete_all
|
66
|
-
Workarea::Catalog::Category.delete_all
|
67
|
-
Workarea::Content::Page.delete_all
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_navigation_taxons(menu)
|
71
|
-
menu.each do |top_level, sub_menu|
|
72
|
-
page = Workarea::Content::Page.find_by(name: top_level)
|
73
|
-
|
74
|
-
begin
|
75
|
-
puts "creating taxon and menu for #{top_level} content::page"
|
76
|
-
taxon = Workarea::Navigation::Taxon.root.children.create!(navigable: page)
|
77
|
-
menu = Workarea::Navigation::Menu.create!(taxon: taxon)
|
78
|
-
|
79
|
-
puts "creating content and content block for menu: #{top_level}"
|
80
|
-
content = Workarea::Content.for(menu)
|
81
|
-
content.blocks.create!(type: 'taxonomy', data: { start: taxon.id, show_starting_taxon: false } )
|
82
|
-
|
83
|
-
sub_menus = sub_menu.keys
|
84
|
-
next if sub_menus.blank?
|
85
|
-
puts 'Create submenu for :'
|
86
|
-
puts sub_menus.inspect
|
87
|
-
|
88
|
-
categories = Workarea::Catalog::Category.any_in(name: sub_menus)
|
89
|
-
content_pages = Workarea::Content::Page.any_in(name: sub_menus)
|
90
|
-
puts "Categories: #{categories.map(&:name).inspect}"
|
91
|
-
puts "content_pages: #{categories.map(&:name).inspect}"
|
92
|
-
|
93
|
-
next if categories.blank? && content_pages.blank?
|
94
|
-
|
95
|
-
categories.each do |category|
|
96
|
-
taxon.children.create!(navigable: category)
|
97
|
-
end
|
98
|
-
|
99
|
-
content_pages.each do |content_page|
|
100
|
-
begin
|
101
|
-
taxon.children.create!(navigable: content_page)
|
102
|
-
rescue Exception => e
|
103
|
-
puts e.message
|
104
|
-
puts content_page.inspect
|
105
|
-
puts taxon.inspect
|
106
|
-
end
|
107
|
-
end
|
108
|
-
rescue => e
|
109
|
-
puts e.message
|
110
|
-
puts "Error creating taxon for main: #{top_level}"
|
111
|
-
end
|
38
|
+
def categories_content
|
39
|
+
{home_categories: 9, business_categories: 10, shop_murals_categories: 8}.each do |category_name, id|
|
40
|
+
categories = client.query(content_categories_query(id)).to_a
|
41
|
+
categories_content = categories.map { |cat|
|
42
|
+
{
|
43
|
+
name: cat['name'],
|
44
|
+
slug: cat['url_key'],
|
45
|
+
h1_tag: cat['h1_tag'],
|
46
|
+
bottom_content: (cat['bottom_content'] || ''),
|
47
|
+
description: (cat['description'] || '')
|
48
|
+
}
|
49
|
+
}
|
50
|
+
File.open("#{Rails.root.to_s}/data/#{category_name}.json", "w"){ |f|
|
51
|
+
f.write(JSON.pretty_generate(categories_content))
|
52
|
+
}
|
112
53
|
end
|
113
54
|
end
|
114
55
|
|
115
|
-
|
116
|
-
|
117
|
-
taxons.each do |taxon|
|
118
|
-
page = Workarea::Content::Page.where(name: taxon['name']).first
|
119
|
-
if page.blank?
|
120
|
-
page = Workarea::Content::Page.create!(page_attrs(taxon))
|
121
|
-
end
|
122
|
-
content = Workarea::Content.for(page)
|
123
|
-
|
124
|
-
next if content.blocks.presence
|
125
|
-
|
126
|
-
sub_taxons = taxons.select{|t| t['parent_id'] == taxon['entity_id']}
|
127
|
-
next if sub_taxons.blank?
|
128
|
-
|
129
|
-
begin
|
130
|
-
sub_taxons.each do |sub_taxon|
|
131
|
-
category = Workarea::Catalog::Category.where(name: sub_taxon['name']).first
|
132
|
-
if category
|
133
|
-
content.blocks.build(type: :category_summary, data: {category: category.id} )
|
134
|
-
else
|
135
|
-
Workarea::Content::Page.create!(page_attrs(sub_taxon))
|
136
|
-
end
|
137
|
-
end
|
138
|
-
rescue Exception => e
|
139
|
-
puts '*' * 100
|
140
|
-
puts e.message
|
141
|
-
end
|
142
|
-
|
143
|
-
content.save!
|
144
|
-
end
|
56
|
+
def content_categories_query(parent_id)
|
57
|
+
"SELECT #{select_columns} FROM #{table_name}_entity e #{join_clause} where e.parent_id=#{parent_id} and v19.value=1 order by e.position asc"
|
145
58
|
end
|
146
59
|
|
147
|
-
def create_categories(category_data)
|
148
|
-
Sidekiq::Callbacks.disable do
|
149
|
-
category_data.each do |category_attr|
|
150
|
-
next if Workarea::Catalog::Category.where(name: category_attr['name']).first.present?
|
151
60
|
|
152
|
-
|
153
|
-
|
154
|
-
product_rules: [],
|
155
|
-
default_sort: Search::CategoryBrowse.available_sorts.sample
|
156
|
-
)
|
157
|
-
end
|
158
|
-
end
|
61
|
+
def categories
|
62
|
+
client.query(categories_query).to_a
|
159
63
|
end
|
160
64
|
|
161
|
-
def
|
162
|
-
|
65
|
+
def soft_categories
|
66
|
+
client.query(soft_categories_query).to_a
|
163
67
|
end
|
164
68
|
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
l2ms = taxons.select{|t| t['level'] == 2 }
|
169
|
-
l2ms = l2ms.flatten.compact.sort_by{|a| a['position']}
|
170
|
-
|
171
|
-
l2ms.each do |l2m|
|
172
|
-
|
173
|
-
l3ms = taxons.select{|t| t['level'] == 3 && t['parent_id'] == l2m['entity_id'] }
|
174
|
-
l3ms = l3ms.flatten.compact.sort_by{|a| a['position']}
|
175
|
-
|
176
|
-
if l3ms.blank?
|
177
|
-
menus[l2m['name']] = {}
|
178
|
-
next
|
179
|
-
else
|
180
|
-
menus[l2m['name']] = {}
|
181
|
-
l3ms.map{|l3m| menus[l2m['name']][l3m['name']] = {}}
|
182
|
-
|
183
|
-
l3ms.each do |l3m|
|
184
|
-
|
185
|
-
l4ms = taxons.select{|t| t['level'] == 4 && t['parent_id'] == l3m['entity_id']}
|
186
|
-
l4ms = l4ms.flatten.compact.sort_by{|a| a['position']}
|
187
|
-
|
188
|
-
if l4ms.blank?
|
189
|
-
menus[l2m['name']][l3m['name']] = {} if menus[l2m['name']].present?
|
190
|
-
next
|
191
|
-
else
|
192
|
-
|
193
|
-
menus[l2m['name']][l3m['name']] = {}
|
194
|
-
l4ms.each{|l4m| menus[l2m['name']][l3m['name']][l4m['name']]={}}
|
195
|
-
|
196
|
-
l4ms.each do |l4m|
|
197
|
-
|
198
|
-
l5ms = taxons.select{|t| t['level'] == 5 && t['parent_id'] == l4m['entity_id']}
|
199
|
-
l5ms = l5ms.flatten.compact.sort_by{|a| a['position']}
|
200
|
-
|
201
|
-
if l5ms.blank?
|
202
|
-
menus[l2m['name']][l3m['name']][l4m['name']] = {}
|
203
|
-
next
|
204
|
-
else
|
205
|
-
l5ms.each {|l5m| menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']]={}}
|
206
|
-
|
207
|
-
l5ms.each do |l5m|
|
208
|
-
l6ms = taxons.select{|t| t['level'] == 6 && t['parent_id'] == l5m['entity_id']}
|
209
|
-
l6ms = l6ms.flatten.compact.sort_by{|a| a['position']}
|
210
|
-
|
211
|
-
if l6ms.blank?
|
212
|
-
menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']] = {}
|
213
|
-
next
|
214
|
-
else
|
215
|
-
l6ms.each{|l6m| menus[l2m['name']][l3m['name']][l4m['name']][l5m['name']][l6m['name']]={}}
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
menus
|
69
|
+
def soft_categories_query
|
70
|
+
" #{select_query} and e.children_count > 0 order by e.parent_id asc "
|
226
71
|
end
|
227
72
|
|
228
|
-
def
|
229
|
-
|
230
|
-
f.write(JSON.pretty_generate(all.to_a))
|
231
|
-
}
|
73
|
+
def categories_query
|
74
|
+
" #{select_query} and e.children_count = 0 order by e.parent_id asc "
|
232
75
|
end
|
233
76
|
|
234
77
|
end # class self declaration
|
@@ -28,14 +28,6 @@ module Workarea
|
|
28
28
|
"SELECT attribute_code, backend_type FROM eav_attribute WHERE entity_type_id = ? and backend_type = ?"
|
29
29
|
end
|
30
30
|
|
31
|
-
# def ids_to_include
|
32
|
-
# raise NotImplementedError, "subclass did not define #ids_to_include"
|
33
|
-
# end
|
34
|
-
|
35
|
-
# def table_name
|
36
|
-
# raise NotImplementedError, "subclass did not define #table_name"
|
37
|
-
# end
|
38
|
-
|
39
31
|
def select_query
|
40
32
|
select_query = "SELECT #{select_columns} FROM #{table_name}_entity e #{join_clause} "
|
41
33
|
select_query += "\nwhere e.entity_id in (#{ids_to_include})"
|
@@ -46,7 +46,7 @@ module Workarea
|
|
46
46
|
REQUIRED_FIELDS = %w{host adapter database}
|
47
47
|
|
48
48
|
def initialize()
|
49
|
-
@magento_db_config =
|
49
|
+
@magento_db_config = YAML.load_file("#{MagentoMigrator::Engine.root}/config/magento_db_config.yml")[Rails.env]
|
50
50
|
@magento_db_config['batch_size'] ||= 10000
|
51
51
|
setup_mysql_client
|
52
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workarea-magento_migrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gajendra Jena
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: workarea
|
@@ -82,7 +82,9 @@ files:
|
|
82
82
|
- bin/rails
|
83
83
|
- config/data/catalog_category.yml
|
84
84
|
- config/data/catalog_product.yml
|
85
|
+
- config/initializers/magento_db.rb
|
85
86
|
- config/initializers/workarea.rb
|
87
|
+
- config/magento_db_config.yml
|
86
88
|
- config/routes.rb
|
87
89
|
- data/categories.json
|
88
90
|
- data/content_pages.json
|
@@ -151,6 +153,7 @@ files:
|
|
151
153
|
- test/teaspoon_env.rb
|
152
154
|
- test/test_helper.rb
|
153
155
|
- test/workarea/magento_migrator/catalog_product_test.rb
|
156
|
+
- workarea-magento_migrator-1.0.0.pre.gem
|
154
157
|
- workarea-magento_migrator.gemspec
|
155
158
|
homepage: ''
|
156
159
|
licenses:
|
@@ -167,9 +170,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
170
|
version: '0'
|
168
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
172
|
requirements:
|
170
|
-
- - "
|
173
|
+
- - ">="
|
171
174
|
- !ruby/object:Gem::Version
|
172
|
-
version:
|
175
|
+
version: '0'
|
173
176
|
requirements: []
|
174
177
|
rubygems_version: 3.0.6
|
175
178
|
signing_key:
|