mercator_legacy_importer 0.0.1 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +22 -1
  3. data/app/models/mercator_legacy_importer/asset.rb +6 -3
  4. data/app/models/mercator_legacy_importer/attachable.rb +7 -4
  5. data/app/models/mercator_legacy_importer/category.rb +10 -7
  6. data/app/models/mercator_legacy_importer/category_translation.rb +9 -6
  7. data/app/models/mercator_legacy_importer/cms_node.rb +8 -5
  8. data/app/models/mercator_legacy_importer/cms_node_translation.rb +9 -6
  9. data/app/models/mercator_legacy_importer/connector.rb +8 -5
  10. data/app/models/mercator_legacy_importer/content.rb +7 -4
  11. data/app/models/mercator_legacy_importer/content_item.rb +7 -4
  12. data/app/models/mercator_legacy_importer/country.rb +6 -3
  13. data/app/models/mercator_legacy_importer/page_template.rb +9 -6
  14. data/app/models/mercator_legacy_importer/product.rb +12 -9
  15. data/app/models/mercator_legacy_importer/product_overview_property.rb +6 -3
  16. data/app/models/mercator_legacy_importer/product_property.rb +8 -5
  17. data/app/models/mercator_legacy_importer/product_relation.rb +6 -3
  18. data/app/models/mercator_legacy_importer/product_supply.rb +6 -3
  19. data/app/models/mercator_legacy_importer/product_translation.rb +10 -7
  20. data/app/models/mercator_legacy_importer/property.rb +12 -9
  21. data/app/models/mercator_legacy_importer/property_translation.rb +9 -6
  22. data/app/models/mercator_legacy_importer/recommendation.rb +9 -7
  23. data/app/models/mercator_legacy_importer/recommendation_translation.rb +10 -7
  24. data/app/models/mercator_legacy_importer/user.rb +6 -3
  25. data/app/views/layouts/mercator_legacy_importer/application.html.erb +10 -11
  26. data/db/migrate/20131202162757_add_legacy_ids.rb +10 -6
  27. data/lib/mercator_legacy_importer/version.rb +2 -2
  28. data/lib/tasks/categories.rake +43 -0
  29. data/lib/tasks/categorizations.rake +43 -0
  30. data/lib/tasks/category_images.rake +42 -34
  31. data/lib/tasks/cms_node_images.rake +91 -81
  32. data/lib/tasks/content_elements.rake +66 -44
  33. data/lib/tasks/countries.rake +16 -10
  34. data/lib/tasks/features.rake +25 -17
  35. data/lib/tasks/page_template.rake +16 -9
  36. data/lib/tasks/product_images.rake +25 -8
  37. data/lib/tasks/product_relations.rake +21 -13
  38. data/lib/tasks/products.rake +52 -39
  39. data/lib/tasks/properties.rake +45 -36
  40. data/lib/tasks/recommendations.rake +30 -19
  41. data/lib/tasks/remaining_assets.rake +34 -26
  42. data/lib/tasks/remaining_images.rake +34 -26
  43. data/lib/tasks/supply_relations.rake +23 -13
  44. data/lib/tasks/unlinked_content_items.rake +24 -18
  45. data/lib/tasks/users.rake +43 -10
  46. data/lib/tasks/webpages.rake +34 -0
  47. metadata +30 -39
  48. data/app/helpers/mercator_legacy_importer/application_helper.rb +0 -4
  49. data/config/database.yml +0 -13
  50. data/db/migrate/20131202164442_products_add_legacy_id.rb +0 -9
  51. data/db/migrate/20140103154252_add_legacy_id_to_page.rb +0 -9
  52. data/db/migrate/20140103161205_add_legacy_id_to_page_template.rb +0 -9
  53. data/db/migrate/20140104094617_add_legacy_id_to_feature.rb +0 -9
  54. data/db/migrate/20140107090420_add_legacy_id_to_content_elements.rb +0 -9
  55. data/lib/tasks/categories.rb +0 -32
  56. data/lib/tasks/categorizations.rb +0 -35
  57. data/lib/tasks/mercator_legacy_importer_tasks.rake +0 -34
  58. data/lib/tasks/pages.rake +0 -27
  59. data/lib/tasks/unlinked_content_elements.rake +0 -60
@@ -1,14 +1,20 @@
1
- def import_countries
2
- puts "\n\nCountries:"
1
+ # encoding: utf-8
3
2
 
4
- Legacy::Country.all.each do |legacy_country|
5
- country = Country.find_or_initialize_by_name_de(legacy_country.country_name)
6
- if country.update_attributes(name_en: legacy_country.country_name,
7
- code: legacy_country.country_a2,
8
- legacy_id: legacy_country.id)
9
- print "C"
10
- else
11
- puts "\nFAILURE: Country: " + country.errors.first.to_s
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:countries
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:countries RAILS_ENV=production'
6
+ desc "Import countries from legacy webshop"
7
+ task :countries => :environment do
8
+
9
+ MercatorLegacyImporter::Country.all.each do |legacy_country|
10
+ country = Country.find_or_initialize_by_name_de(legacy_country.country_name)
11
+ if country.update_attributes(name_en: legacy_country.country_name,
12
+ code: legacy_country.country_a2,
13
+ legacy_id: legacy_country.id)
14
+ print "C"
15
+ else
16
+ puts "\nFAILURE: Country: " + country.errors.first.to_s
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -1,21 +1,29 @@
1
- def import_features
2
- puts "\n\nFeatures:"
1
+ # encoding: utf-8
3
2
 
4
- n=1
5
- Legacy::ProductOverviewProperty.all.each do |legacy_product_overview_property|
6
- legacy_product = Product.find_by_legacy_id(legacy_product_overview_property.product_id)
7
- unless legacy_product
8
- puts "\nFAILURE: Product not found: " + legacy_product_overview_property.product_id.to_s
9
- next
10
- end
11
- feature = Feature.create(text_de: legacy_product_overview_property.description,
12
- position: ( legacy_product_overview_property.order || n = n + 1 ),
13
- product_id: legacy_product.id,
14
- legacy_id: legacy_product_overview_property.id)
15
- if feature.save
16
- print "F"
17
- else
18
- puts "\nFAILURE: Feature: " + feature.errors.first.to_s
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:features
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:features RAILS_ENV=production'
6
+ desc "Import features from legacy webshop"
7
+ task :features => :environment do
8
+
9
+ puts "\n\nFeatures:"
10
+
11
+ n=1
12
+ MercatorLegacyImporter::ProductOverviewProperty.all.each do |legacy_product_overview_property|
13
+ legacy_product = Product.find_by_legacy_id(legacy_product_overview_property.product_id)
14
+ unless legacy_product
15
+ puts "\nFAILURE: Product not found: " + legacy_product_overview_property.product_id.to_s
16
+ next
17
+ end
18
+ feature = Feature.create(text_de: legacy_product_overview_property.description,
19
+ position: ( legacy_product_overview_property.order || n = n + 1 ),
20
+ product_id: legacy_product.id,
21
+ legacy_id: legacy_product_overview_property.id)
22
+ if feature.save
23
+ print "F"
24
+ else
25
+ puts "\nFAILURE: Feature: " + feature.errors.first.to_s
26
+ end
19
27
  end
20
28
  end
21
29
  end
@@ -1,13 +1,20 @@
1
- def import_page_templates
2
- puts "\n\nPage Templates:"
1
+ # encoding: utf-8
3
2
 
4
- Legacy::PageTemplate.all.each do |legacy_page_template|
5
- if page_template = PageTemplate.create(name: legacy_page_template.name,
6
- content: legacy_page_template.content,
7
- legacy_id: legacy_page_template.id)
8
- print "T"
9
- else
10
- puts "\nFAILURE: PageTemplate: " + page_template.errors.first.to_s
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:page_templates
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:page_templates RAILS_ENV=production'
6
+ desc "Import page_templates from legacy webshop"
7
+ task :page_templates => :environment do
8
+ puts "\n\nPage Templates:"
9
+
10
+ MercatorLegacyImporter::PageTemplate.all.each do |legacy_page_template|
11
+ if page_template = PageTemplate.create(name: legacy_page_template.name,
12
+ content: legacy_page_template.content,
13
+ legacy_id: legacy_page_template.id)
14
+ print "T"
15
+ else
16
+ puts "\nFAILURE: PageTemplate: " + page_template.errors.first.to_s
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -1,11 +1,27 @@
1
- def import_product_images
2
- require 'net/http'
3
- puts "\n\nProduct Images:"
1
+ # encoding: utf-8
2
+
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:product_images
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:product_images RAILS_ENV=production'
6
+ desc "Import product_images from legacy webshop"
7
+ task :product_images => :environment do
8
+
9
+ require 'net/http'
10
+ puts "\n\nProduct Images:"
11
+
12
+ Net::HTTP.start("www.iv-shop.at") do |http|
13
+ MercatorLegacyImporter::Product.all.each do |legacy_product|
14
+ unless legacy_product.image_file_name || legacy_product.overview_file_name
15
+ print "x"
16
+ next
17
+ end
4
18
 
5
- Net::HTTP.start("www.iv-shop.at") do |http|
6
- Legacy::Product.all.each do |legacy_product|
7
- if legacy_product.image_file_name || legacy_product.overview_file_name
8
19
  product = Product.find_by_legacy_id(legacy_product.id)
20
+ if product.photo_file_name.present?
21
+ print "✔"
22
+ next
23
+ end
24
+
9
25
  filename = "/system/images/" + legacy_product.id.to_s +
10
26
  "/original/" + legacy_product.image_file_name.presence ||
11
27
  legacy_product.overview_file_name
@@ -13,13 +29,14 @@ def import_product_images
13
29
  data.class.class_eval { attr_accessor :original_filename }
14
30
  data.original_filename = legacy_product.image_file_name.presence || legacy_product.overview_file_name
15
31
  product.photo = data
32
+ product.photo_content_type = MIME::Types.type_for(data.original_filename).first.content_type
33
+
16
34
  if product.save
17
35
  print "P"
18
36
  else
19
37
  puts "\nFAILURE: Image: " + product.errors.first.to_s
38
+ # If image is missing on server, we get probable a content type mismatch error, e.g. html (error page) instead of png (image)
20
39
  end
21
- else
22
- print "."
23
40
  end
24
41
  end
25
42
  end
@@ -1,21 +1,29 @@
1
- def import_product_relations
2
- puts "\n\nProductRelations:"
1
+ # encoding: utf-8
3
2
 
4
- Legacy::ProductRelation.all.each do |legacy_product_relation|
5
- if product = Product.find_by(legacy_id: legacy_product_relation.product_id)
6
- if related_product = Product.find_by(legacy_id: legacy_product_relation.related_product_id)
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:product_relations
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:product_relations RAILS_ENV=production'
6
+ desc "Import product relations from legacy webshop"
7
+ task :product_relations => :environment do
7
8
 
8
- if productrelation = Productrelation.create(product_id: product.id,
9
- related_product_id: related_product.id)
10
- print "P"
9
+ puts "\n\nProductRelations:"
10
+
11
+ MercatorLegacyImporter::ProductRelation.all.each do |legacy_product_relation|
12
+ if product = Product.find_by(legacy_id: legacy_product_relation.product_id)
13
+ if related_product = Product.find_by(legacy_id: legacy_product_relation.related_product_id)
14
+
15
+ if productrelation = Productrelation.create(product_id: product.id,
16
+ related_product_id: related_product.id)
17
+ print "P"
18
+ else
19
+ puts "\nFAILURE: Productrelation: " + productrelation.errors.first.to_s
20
+ end
11
21
  else
12
- puts "\nFAILURE: Productrelation: " + productrelation.errors.first.to_s
22
+ puts "\n FAIILURE: Product not found"
13
23
  end
14
- else
15
- puts "\n FAIILURE: Product not found"
24
+ else
25
+ puts "\n FAIILURE: RelatedProduct not found"
16
26
  end
17
- else
18
- puts "\n FAIILURE: RelatedProduct not found"
19
27
  end
20
28
  end
21
29
  end
@@ -1,48 +1,61 @@
1
- def import_products
2
- puts "\n\nProducts:"
3
- Product.all.each do |product|
4
- product.delete
5
- end
6
- print "Products deleted."
7
-
8
- Legacy::Product.all.each do |legacy_product|
9
- legacy_product_de = legacy_product.product_translations.german.first
10
- legacy_product_en = legacy_product.product_translations.english.first
1
+ # encoding: utf-8
2
+ require 'string_extensions'
11
3
 
12
- if legacy_product_de && legacy_product_de.title.present?
13
- name_de = legacy_product_de.title
14
- else
15
- name_de = legacy_product.name
4
+ namespace :legacy_import do
5
+ # starten als: 'bundle exec rake legacy_import:products
6
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:products RAILS_ENV=production'
7
+ desc "Import products from legacy webshop"
8
+ task :products => :environment do
9
+ puts "\n\nProducts:"
10
+ Product.all.each do |product|
11
+ product.delete
16
12
  end
13
+ print "Products deleted."
17
14
 
18
- if legacy_product_de && legacy_product_de.long_description.present?
19
- description_de = legacy_product_de.long_description
20
- else
21
- description_de = "fehlt"
22
- end
15
+ MercatorLegacyImporter::Product.all.each do |legacy_product|
16
+ legacy_product_de = legacy_product.product_translations.german.first
17
+ legacy_product_en = legacy_product.product_translations.english.first
23
18
 
24
- if legacy_product_en && legacy_product_en.title.present?
25
- name_en = legacy_product_en.title
26
- else
27
- name_en = legacy_product.name
28
- end
19
+ if legacy_product_de && legacy_product_de.title.present?
20
+ title_de = legacy_product_de.title
21
+ else
22
+ title_de = legacy_product.name
23
+ end
29
24
 
30
- if legacy_product_en && legacy_product_en.long_description.present?
31
- description_en = legacy_product_en.long_description
32
- else
33
- description_en = "missing"
34
- end
25
+ if legacy_product_de && legacy_product_de.long_description.present?
26
+ description_de = legacy_product_de.long_description
27
+ else
28
+ description_de = "fehlt"
29
+ end
30
+
31
+ if legacy_product_en && legacy_product_en.title.present?
32
+ title_en = legacy_product_en.title
33
+ else
34
+ title_en = legacy_product.name
35
+ end
36
+
37
+ if legacy_product_en && legacy_product_en.long_description.present?
38
+ description_en = legacy_product_en.long_description
39
+ else
40
+ description_en = "missing"
41
+ end
35
42
 
36
- product = Product.create(number: legacy_product.article_number,
37
- name_de: name_de,
38
- name_en: name_en,
39
- description_de: description_de,
40
- description_en: description_en,
41
- legacy_id: legacy_product.id)
42
- if product.save
43
- print "P"
44
- else
45
- puts "\nFAILURE: Product: " + product.errors.first.to_s
43
+ product = Product.create(number: legacy_product.article_number,
44
+ title_de: title_de,
45
+ title_en: title_en,
46
+ description_de: description_de.fix_utf8,
47
+ description_en: description_en.fix_utf8,
48
+ legacy_id: legacy_product.id)
49
+ if product.save
50
+ print "P"
51
+ else
52
+ product.number = legacy_product.id.to_s + " - Duplikat von " + legacy_product.article_number
53
+ if product.save
54
+ print "P"
55
+ else
56
+ puts "\nFAILURE: Product " + legacy_product.article_number + ": " + product.errors.first.to_s
57
+ end
58
+ end
46
59
  end
47
60
  end
48
61
  end
@@ -1,44 +1,53 @@
1
- def import_properties
2
- # puts "\n\nProperty Groups and Properties:"
3
- # Property.all.each do |property|
4
- # property.delete
5
- # end
6
- # print "Properties deleted."
7
- # PropertyGroup.all.each do |property_group|
8
- # property_group.delete
9
- # end
10
- # print "Property Groups deleted."
1
+ # encoding: utf-8
11
2
 
12
- Legacy::Product.all.each do |legacy_product|
13
- product = Product.find_by_legacy_id(legacy_product.id)
14
- legacy_product.properties.each do |legacy_property|
15
- # next if legacy_property.id < 21050
16
- legacy_property_de = legacy_property.property_translations.german.first
17
- legacy_property_en = legacy_property.property_translations.english.first
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:properties
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:properties RAILS_ENV=production'
6
+ desc "Import properties from legacy webshop"
7
+ task :properties => :environment do
18
8
 
19
- property_group =
20
- PropertyGroup.find_or_initialize_by_name_de_and_product_id(
21
- legacy_property_de.group.presence || legacy_property_de.name,
22
- product.id)
23
- if property_group.update_attributes(name_en: legacy_property_en.group.presence ||
24
- legacy_property_en.name,
25
- position: 1)
26
- print "G"
9
+ puts "\n\nProperty Groups and Properties:"
10
+ Property.all.each do |property|
11
+ property.delete
12
+ end
13
+
14
+ print "Properties deleted."
15
+ PropertyGroup.all.each do |property_group|
16
+ property_group.delete
17
+ end
18
+ print "Property Groups deleted."
19
+
20
+ MercatorLegacyImporter::Product.all.each do |legacy_product|
21
+ product = Product.find_by_legacy_id(legacy_product.id)
22
+ legacy_product.properties.each do |legacy_property|
23
+ # next if legacy_property.id < 21050
24
+ legacy_property_de = legacy_property.property_translations.german.first
25
+ legacy_property_en = legacy_property.property_translations.english.first
26
+
27
+ property_group =
28
+ PropertyGroup.find_or_initialize_by_name_de_and_product_id(
29
+ legacy_property_de.group.presence || legacy_property_de.name,
30
+ product.id)
31
+ if property_group.update_attributes(name_en: legacy_property_en.group.presence ||
32
+ legacy_property_en.name,
33
+ position: 1)
34
+ print "G"
27
35
 
28
- property = Property.create(name_de: legacy_property_de.name,
29
- property_group_id: property_group.id,
30
- name_en: legacy_property_en.name,
31
- description_de: legacy_property.presentation_value,
32
- description_en: legacy_property.presentation_value,
33
- position: 1,
34
- legacy_id: legacy_property.id)
35
- if property.save
36
- print "p"
36
+ property = Property.create(name_de: legacy_property_de.name,
37
+ property_group_id: property_group.id,
38
+ name_en: legacy_property_en.name,
39
+ description_de: legacy_property.presentation_value,
40
+ description_en: legacy_property.presentation_value,
41
+ position: 1,
42
+ legacy_id: legacy_property.id)
43
+ if property.save
44
+ print "p"
45
+ else
46
+ puts "\nFAILURE: Property: " + property.errors.first.to_s
47
+ end
37
48
  else
38
- puts "\nFAILURE: Property: " + property.errors.first.to_s
49
+ puts "\nFAILURE: PropertyGroup: " + property_group.errors.first.to_s
39
50
  end
40
- else
41
- puts "\nFAILURE: PropertyGroup: " + property_group.errors.first.to_s
42
51
  end
43
52
  end
44
53
  end
@@ -1,28 +1,39 @@
1
- def import_recommendations
2
- puts "\n\nRecommendations:"
1
+ # encoding: utf-8
3
2
 
4
- Legacy::Recommendation.all.each do |legacy_recommendation|
5
- legacy_reason_de = legacy_recommendation.recommendation_translations.german.first
6
- legacy_reason_en = legacy_recommendation.recommendation_translations.english.first
3
+ namespace :legacy_import do
4
+ # starten als: 'bundle exec rake legacy_import:recommendations
5
+ # in Produktivumgebungen: 'bundle exec rake legacy_import:recommendations RAILS_ENV=production'
6
+ desc "Import recommendations from legacy webshop"
7
+ task :recommendations => :environment do
8
+ puts "\n\nRecommendations:"
7
9
 
8
- next if legacy_recommendation.from_product_id.nil?
9
- if product = Product.find_by(legacy_id: legacy_recommendation.from_product_id)
10
- next if legacy_recommendation.for_product_id.blank?
11
- if recommendation = Product.find_by(number: legacy_recommendation.for_product_id)
10
+ Recommendation.all.each do |recommendation|
11
+ recommendation.delete
12
+ end
13
+ print "Recommendations deleted."
14
+
15
+ MercatorLegacyImporter::Recommendation.all.each do |legacy_recommendation|
16
+ legacy_reason_de = legacy_recommendation.recommendation_translations.german.first
17
+ legacy_reason_en = legacy_recommendation.recommendation_translations.english.first
12
18
 
13
- if recommendation = Recommendation.create(product_id: product.id,
14
- recommended_product_id: recommendation.id,
15
- reason_de: legacy_reason_de.description,
16
- reason_en: legacy_reason_en.description)
17
- print "R"
19
+ next if legacy_recommendation.from_product_id.nil?
20
+ if product = Product.find_by(legacy_id: legacy_recommendation.from_product_id)
21
+ next if legacy_recommendation.for_product_id.blank?
22
+ if recommendation = Product.find_by(number: legacy_recommendation.for_product_id)
23
+ if recommendation = Recommendation.create(product_id: product.id,
24
+ recommended_product_id: recommendation.id,
25
+ reason_de: legacy_reason_de.description.fix_utf8,
26
+ reason_en: legacy_reason_en.description.fix_utf8)
27
+ print "R"
28
+ else
29
+ puts "\nFAILURE: Recommendation: " + recommendation.errors.first.to_s
30
+ end
18
31
  else
19
- puts "\nFAILURE: Recommendation: " + recommendation.errors.first.to_s
32
+ puts "\n FAIILURE: Recommended product not found: " + legacy_recommendation.for_product_id
20
33
  end
21
- else
22
- puts "\n FAIILURE: Recommended product not found: " + legacy_recommendation.for_product_id
34
+ else
35
+ puts "\n FAIILURE: Product not found: " + legacy_recommendation.from_product_id.to_s
23
36
  end
24
- else
25
- puts "\n FAIILURE: Product not found: " + legacy_recommendation.from_product_id.to_s
26
37
  end
27
38
  end
28
39
  end