mercator_legacy_importer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +674 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/mercator_legacy_importer/application.js +13 -0
  6. data/app/assets/stylesheets/mercator_legacy_importer/application.css +13 -0
  7. data/app/controllers/mercator_legacy_importer/application_controller.rb +4 -0
  8. data/app/helpers/mercator_legacy_importer/application_helper.rb +4 -0
  9. data/app/models/mercator_legacy_importer/asset.rb +4 -0
  10. data/app/models/mercator_legacy_importer/attachable.rb +6 -0
  11. data/app/models/mercator_legacy_importer/category.rb +10 -0
  12. data/app/models/mercator_legacy_importer/category_translation.rb +8 -0
  13. data/app/models/mercator_legacy_importer/cms_node.rb +7 -0
  14. data/app/models/mercator_legacy_importer/cms_node_translation.rb +8 -0
  15. data/app/models/mercator_legacy_importer/connector.rb +7 -0
  16. data/app/models/mercator_legacy_importer/content.rb +6 -0
  17. data/app/models/mercator_legacy_importer/content_item.rb +6 -0
  18. data/app/models/mercator_legacy_importer/country.rb +4 -0
  19. data/app/models/mercator_legacy_importer/page_template.rb +8 -0
  20. data/app/models/mercator_legacy_importer/product.rb +12 -0
  21. data/app/models/mercator_legacy_importer/product_overview_property.rb +4 -0
  22. data/app/models/mercator_legacy_importer/product_property.rb +7 -0
  23. data/app/models/mercator_legacy_importer/product_relation.rb +4 -0
  24. data/app/models/mercator_legacy_importer/product_supply.rb +4 -0
  25. data/app/models/mercator_legacy_importer/product_translation.rb +8 -0
  26. data/app/models/mercator_legacy_importer/property.rb +13 -0
  27. data/app/models/mercator_legacy_importer/property_translation.rb +8 -0
  28. data/app/models/mercator_legacy_importer/recommendation.rb +10 -0
  29. data/app/models/mercator_legacy_importer/recommendation_translation.rb +8 -0
  30. data/app/models/mercator_legacy_importer/user.rb +4 -0
  31. data/app/views/layouts/mercator_legacy_importer/application.html.erb +14 -0
  32. data/config/database.yml +13 -0
  33. data/config/routes.rb +2 -0
  34. data/db/migrate/20131202162757_add_legacy_ids.rb +21 -0
  35. data/db/migrate/20131202164442_products_add_legacy_id.rb +9 -0
  36. data/db/migrate/20140103154252_add_legacy_id_to_page.rb +9 -0
  37. data/db/migrate/20140103161205_add_legacy_id_to_page_template.rb +9 -0
  38. data/db/migrate/20140104094617_add_legacy_id_to_feature.rb +9 -0
  39. data/db/migrate/20140107090420_add_legacy_id_to_content_elements.rb +9 -0
  40. data/lib/mercator_legacy_importer/engine.rb +5 -0
  41. data/lib/mercator_legacy_importer/version.rb +3 -0
  42. data/lib/mercator_legacy_importer.rb +4 -0
  43. data/lib/tasks/categories.rb +32 -0
  44. data/lib/tasks/categorizations.rb +35 -0
  45. data/lib/tasks/category_images.rake +49 -0
  46. data/lib/tasks/cms_node_images.rake +91 -0
  47. data/lib/tasks/content_elements.rake +64 -0
  48. data/lib/tasks/countries.rake +14 -0
  49. data/lib/tasks/features.rake +21 -0
  50. data/lib/tasks/mercator_legacy_importer_tasks.rake +34 -0
  51. data/lib/tasks/page_template.rake +13 -0
  52. data/lib/tasks/pages.rake +27 -0
  53. data/lib/tasks/product_images.rake +26 -0
  54. data/lib/tasks/product_relations.rake +21 -0
  55. data/lib/tasks/products.rake +48 -0
  56. data/lib/tasks/properties.rake +45 -0
  57. data/lib/tasks/recommendations.rake +28 -0
  58. data/lib/tasks/remaining_assets.rake +37 -0
  59. data/lib/tasks/remaining_images.rake +38 -0
  60. data/lib/tasks/supply_relations.rake +21 -0
  61. data/lib/tasks/unlinked_content_elements.rake +60 -0
  62. data/lib/tasks/unlinked_content_items.rake +26 -0
  63. data/lib/tasks/users.rake +13 -0
  64. data/test/dummy/README.rdoc +28 -0
  65. data/test/dummy/Rakefile +6 -0
  66. data/test/dummy/app/assets/javascripts/application.js +13 -0
  67. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  68. data/test/dummy/app/controllers/application_controller.rb +5 -0
  69. data/test/dummy/app/helpers/application_helper.rb +2 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/config/application.rb +23 -0
  75. data/test/dummy/config/boot.rb +5 -0
  76. data/test/dummy/config/database.yml +25 -0
  77. data/test/dummy/config/environment.rb +5 -0
  78. data/test/dummy/config/environments/development.rb +29 -0
  79. data/test/dummy/config/environments/production.rb +80 -0
  80. data/test/dummy/config/environments/test.rb +36 -0
  81. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  83. data/test/dummy/config/initializers/inflections.rb +16 -0
  84. data/test/dummy/config/initializers/mime_types.rb +5 -0
  85. data/test/dummy/config/initializers/secret_token.rb +12 -0
  86. data/test/dummy/config/initializers/session_store.rb +3 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/test/dummy/config/locales/en.yml +23 -0
  89. data/test/dummy/config/routes.rb +4 -0
  90. data/test/dummy/config.ru +4 -0
  91. data/test/dummy/public/404.html +58 -0
  92. data/test/dummy/public/422.html +58 -0
  93. data/test/dummy/public/500.html +57 -0
  94. data/test/dummy/public/favicon.ico +0 -0
  95. data/test/integration/navigation_test.rb +10 -0
  96. data/test/mercator_legacy_importer_test.rb +7 -0
  97. data/test/test_helper.rb +15 -0
  98. metadata +201 -0
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = MercatorLegacyImporter
2
+
3
+ This is am sample engine for importing data from a legacy MYSQL database.
4
+ Look into the models and the lib/tasks folder for examples for connecting to a database and importing data.
5
+
6
+ This project uses the GPL V3 license. See file LICENSE in the same directory for details about the GPL V3.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'MercatorLegacyImporter'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module MercatorLegacyImporter
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module MercatorLegacyImporter
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::Asset < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'assets'
4
+ end
@@ -0,0 +1,6 @@
1
+ class Legacy::Attachable < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'attachables'
4
+
5
+ belongs_to :asset
6
+ end
@@ -0,0 +1,10 @@
1
+ class Legacy::Category < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'categories'
4
+
5
+ # The following two lines fix the migration issues
6
+ hobo_model
7
+ fields
8
+
9
+ has_many :category_translations
10
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::CategoryTranslation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'category_translations'
4
+
5
+ belongs_to :category
6
+ scope :german, -> { where(locale: "de") }
7
+ scope :english, -> { where(locale: "en") }
8
+ end
@@ -0,0 +1,7 @@
1
+ class Legacy::CmsNode < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'cms_nodes'
4
+
5
+ has_many :cms_node_translations
6
+ has_many :connectors
7
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::CmsNodeTranslation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'cms_node_translations'
4
+
5
+ belongs_to :cms_node
6
+ scope :german, -> { where(locale: "de") }
7
+ scope :english, -> { where(locale: "en") }
8
+ end
@@ -0,0 +1,7 @@
1
+ class Legacy::Connector < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'connectors'
4
+
5
+ belongs_to :content
6
+ belongs_to :cms_node
7
+ end
@@ -0,0 +1,6 @@
1
+ class Legacy::Content < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'contents'
4
+
5
+ has_many :connectors
6
+ end
@@ -0,0 +1,6 @@
1
+ class Legacy::ContentItem < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'content_items'
4
+
5
+ belongs_to :content
6
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::Country < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'zones'
4
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::PageTemplate < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'page_templates'
4
+
5
+ # The following two lines fix the migration issues
6
+ hobo_model
7
+ fields
8
+ end
@@ -0,0 +1,12 @@
1
+ class Legacy::Product < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'products'
4
+
5
+ # The following two lines fix the migration issues
6
+ hobo_model
7
+ fields
8
+
9
+ has_many :product_translations
10
+ has_many :product_properties
11
+ has_many :properties , :through => :product_properties
12
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::ProductOverviewProperty < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'product_overview_properties'
4
+ end
@@ -0,0 +1,7 @@
1
+ class Legacy::ProductProperty < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'products_properties'
4
+
5
+ belongs_to :product
6
+ belongs_to :property
7
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::ProductRelation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'product_relations'
4
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::ProductSupply < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'product_supplies'
4
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::ProductTranslation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'product_translations'
4
+
5
+ belongs_to :product
6
+ scope :german, -> { where(locale: "de") }
7
+ scope :english, -> { where(locale: "en") }
8
+ end
@@ -0,0 +1,13 @@
1
+ class Legacy::Property < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'properties'
4
+
5
+ # The following two lines fix the migration issues
6
+ hobo_model
7
+ fields
8
+
9
+ has_many :property_translations
10
+
11
+ has_many :product_properties
12
+ has_many :products, :through => :product_properties
13
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::PropertyTranslation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'property_translations'
4
+
5
+ belongs_to :property
6
+ scope :german, -> { where(locale: "de") }
7
+ scope :english, -> { where(locale: "en") }
8
+ end
@@ -0,0 +1,10 @@
1
+ class Legacy::Recommendation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'recommendations'
4
+
5
+ # The following two lines fix the migration issues
6
+ hobo_model
7
+ fields
8
+
9
+ has_many :recommendation_translations
10
+ end
@@ -0,0 +1,8 @@
1
+ class Legacy::RecommendationTranslation < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'recommendation_translations'
4
+
5
+ belongs_to :recommendation
6
+ scope :german, -> { where(locale: "de") }
7
+ scope :english, -> { where(locale: "en") }
8
+ end
@@ -0,0 +1,4 @@
1
+ class Legacy::User < ActiveRecord::Base
2
+ establish_connection "import_development"
3
+ self.table_name = 'ivellio_vellin_customers'
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>MercatorLegacyImporter</title>
5
+ <%= stylesheet_link_tag "mercator_legacy_importer/application", media: "all" %>
6
+ <%= javascript_include_tag "mercator_legacy_importer/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ import_development:
2
+ adapter: mysql2
3
+ host: localhost
4
+ database: ivellio_vellin_development
5
+ username: <%= CONFIG[:legacy_database_user] %>
6
+ password: <%= CONFIG[:legacy_database_password] %>
7
+
8
+ import_production:
9
+ adapter: mysql2
10
+ host: localhost
11
+ database: ivellio_vellin_production
12
+ username: <%= CONFIG[:legacy_database_user] %>
13
+ password: <%= CONFIG[:legacy_database_password] %>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ MercatorLegacyImporter::Engine.routes.draw do
2
+ end
@@ -0,0 +1,21 @@
1
+ class AddLegacyIds < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :legacy_id, :integer
4
+
5
+ add_column :properties, :legacy_id, :integer
6
+
7
+ add_column :countries, :legacy_id, :integer
8
+
9
+ add_column :categories, :legacy_id, :integer
10
+ end
11
+
12
+ def self.down
13
+ remove_column :users, :legacy_id
14
+
15
+ remove_column :properties, :legacy_id
16
+
17
+ remove_column :countries, :legacy_id
18
+
19
+ remove_column :categories, :legacy_id
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class ProductsAddLegacyId < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :products, :legacy_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :products, :legacy_id
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddLegacyIdToPage < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :pages, :legacy_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :pages, :legacy_id
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddLegacyIdToPageTemplate < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :page_templates, :legacy_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :page_templates, :legacy_id
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddLegacyIdToFeature < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :features, :legacy_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :features, :legacy_id
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddLegacyIdToContentElements < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :content_elements, :legacy_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :content_elements, :legacy_id
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module MercatorLegacyImporter
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace MercatorLegacyImporter
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module MercatorLegacyImporter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "mercator_legacy_importer/engine"
2
+
3
+ module MercatorLegacyImporter
4
+ end
@@ -0,0 +1,32 @@
1
+ def import_categories
2
+ puts "\n\nCategories:"
3
+ Category.all.each do |category|
4
+ category.delete
5
+ end
6
+ print "Categories deleted."
7
+
8
+ Legacy::Category.all.each do |legacy_category|
9
+ legacy_category_de = legacy_category.category_translations.german.first
10
+ legacy_category_en = legacy_category.category_translations.english.first
11
+
12
+ category = Category.create(name_de: legacy_category_de.title && legacy_category.name)
13
+ parent = Category.find_by_legacy_id(legacy_category.parent_id)
14
+ if category.update_attributes(name_en: legacy_category_en.title,
15
+ description_de: legacy_category_de.short_description,
16
+ description_en: legacy_category_en.short_description,
17
+ long_description_de: legacy_category_de.long_description,
18
+ long_description_en: legacy_category_en.long_description,
19
+ position: legacy_category.position,
20
+ parent: ( parent if parent ) ,
21
+ legacy_id: legacy_category.id)
22
+ category.state = "active" if legacy_category.active == true
23
+ if category.save
24
+ print "C"
25
+ else
26
+ puts "\nFAILURE: Category " + category.errors.first.to_s
27
+ end
28
+ else
29
+ puts "\nFAILURE: Category " + category.errors.first.to_s
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ def import_categorizations
2
+ puts "\n\nCategorizations:"
3
+ Legacy::Product.all.each do |legacy_product|
4
+
5
+ unless product = Product.find_by_legacy_id(legacy_product.id) then
6
+ puts "\nFAILURE: Product " + legacy_product.id.to_s + " not found."
7
+ next
8
+ end
9
+
10
+ if legacy_product.article_group && legacy_product.article_group.length == 11
11
+ legacy_product.article_group = "00" + legacy_product.article_group[0..3] +
12
+ "00" + legacy_product.article_group[4..7] +
13
+ "00" + legacy_product.article_group[8..10] +
14
+ "-00000-00000"
15
+ end
16
+
17
+ unless legacy_category = Legacy::Category.find_by_category_product_group(legacy_product.article_group) then
18
+ puts "\nFAILURE: Legacy Category " + legacy_product.article_group.to_s + " not found."
19
+ next
20
+ end
21
+
22
+ unless category = Category.find_by_legacy_id(legacy_category.id) then
23
+ puts "\nFAILURE: Category " + legacy_category.id.to_s + " not found."
24
+ next
25
+ end
26
+
27
+ categorization = Categorization.find_or_initialize_by_product_id_and_category_id(product.id, category.id)
28
+ unless categorization.update_attributes(position: 1) then
29
+ puts "\nFAILURE: Categorization " + categorization.errors.first.to_s
30
+ next
31
+ end
32
+
33
+ print "…"
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ def import_category_images
2
+ require 'net/http'
3
+ puts "\n\nCategory Images:"
4
+
5
+ assets = []
6
+
7
+ Net::HTTP.start("www.iv-shop.at") do |http|
8
+ Legacy::Attachable.where(attachable_type: "Category").each do |legacy_attachable|
9
+
10
+ category = Category.where(legacy_id: legacy_attachable.attachable_id).first
11
+
12
+ unless category
13
+ puts "\nFAILURE: Category not found: " + legacy_attachable.attachable_id.to_s
14
+ next
15
+ end
16
+
17
+ unless legacy_attachable.asset
18
+ puts "\nFAILURE: Asset not found: " + legacy_attachable.asset_id.to_s
19
+ next
20
+ end
21
+
22
+ filename = "/system/datas/" + legacy_attachable.asset.id.to_s +
23
+ "/original/" + legacy_attachable.asset.data_file_name
24
+
25
+ data = StringIO.new(http.get(filename).body)
26
+
27
+ unless data
28
+ puts "\nFAILURE: Image not found " + filename
29
+ next
30
+ end
31
+
32
+ data.class.class_eval { attr_accessor :original_filename }
33
+ data.original_filename = legacy_attachable.asset.data_file_name
34
+ category.photo = data
35
+
36
+ if category.save
37
+ print "C"
38
+ assets << legacy_attachable.asset
39
+ legacy_attachable.delete()
40
+ else
41
+ puts "\nFAILURE: Category: " + category.first.to_s
42
+ end
43
+ end
44
+ end
45
+
46
+ assets.each do |asset|
47
+ asset.delete()
48
+ end
49
+ end
@@ -0,0 +1,91 @@
1
+ def import_cms_node_images
2
+ require 'net/http'
3
+ puts "\n\nCMS Node Images:"
4
+
5
+ @legacy_contents = []
6
+ @legacy_attachables = []
7
+
8
+ Net::HTTP.start("www.iv-shop.at") do |http|
9
+ # Legacy::CmsNode.where(name: "images").each do |legacy_cms_node|
10
+ Legacy::CmsNode.all.each do |legacy_cms_node|
11
+
12
+ page = Page.where(legacy_id: legacy_cms_node.parent_id).first
13
+
14
+ legacy_cms_node.connectors.each do |legacy_connector|
15
+ if legacy_connector.position != 1
16
+ @used_as = legacy_cms_node.name + legacy_connector.position.to_s
17
+ else
18
+ @used_as = legacy_cms_node.name
19
+ end
20
+
21
+ @locale = legacy_connector.locale
22
+
23
+ legacy_content = legacy_connector.content
24
+
25
+ legacy_id = legacy_cms_node.id
26
+
27
+ content_element = ContentElement.find_or_initialize_by(legacy_id: legacy_id)
28
+ content_element.markup = "html"
29
+ content_element.name_de = legacy_content.name if @locale == "de"
30
+ content_element.name_en = legacy_content.name if @locale == "en"
31
+
32
+ legacy_attachable = Legacy::Attachable.where(attachable_type: "Content", attachable_id: legacy_content.id).first
33
+ unless legacy_attachable
34
+ puts "\nFAILURE: Attachable not found " + legacy_content.id.to_s
35
+ next
36
+ end
37
+
38
+ filename = "/system/datas/" + legacy_attachable.asset_id.to_s +
39
+ "/original/" + legacy_content.name
40
+
41
+ data = StringIO.new(http.get(filename).body)
42
+
43
+ unless data
44
+ puts "\nFAILURE: Image not found " + filename
45
+ next
46
+ end
47
+
48
+ data.class.class_eval { attr_accessor :original_filename }
49
+ data.original_filename = legacy_attachable.asset.data_file_name
50
+ content_element.photo = data
51
+
52
+ Legacy::ContentItem.where(content_id: legacy_content.id).each do |legacy_content_item|
53
+
54
+ debugger unless ["text", "slogan", "content"].include?(legacy_content_item.key)
55
+
56
+ content_element.content_de = legacy_content_item.value if @locale == "de"
57
+ content_element.content_en = legacy_content_item.value if @locale == "en"
58
+ legacy_content_item.delete()
59
+ end
60
+
61
+ if content_element.save
62
+ print "C"
63
+ else
64
+ puts "\nFAILURE: ContentElement: " + content_element.errors.first.to_s
65
+ end
66
+
67
+ pcea = PageContentElementAssignment.find_or_initialize_by(used_as: @used_as,
68
+ page_id: page.id,
69
+ content_element_id: content_element.id)
70
+ if pcea.save
71
+ print "A"
72
+ else
73
+ puts "\nFAILURE: PageContentElementAssignment: " + pcea.errors.first.to_s
74
+ end
75
+
76
+ @legacy_contents << legacy_content
77
+ @legacy_attachables << legacy_attachable
78
+
79
+ legacy_connector.delete()
80
+ end
81
+ legacy_cms_node.delete()
82
+ end
83
+
84
+ @legacy_contents.each do |legacy_content|
85
+ legacy_content.delete()
86
+ end
87
+ @legacy_attachables.each do |legacy_attachable|
88
+ legacy_attachable.delete()
89
+ end
90
+ end
91
+ end