Commit 254496ca84937e8705e07f5ce8e33d8a7a8c1914

Authored by MoisesMachado
1 parent d84b785b

ActionItem514: made a script to fix the product category hierachy


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2224 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 1 changed file with 23 additions and 0 deletions   Show diff stats
script/fix_categories.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +require File.dirname(__FILE__) + '/fbes_populate_helper.rb'
  2 +
  3 +cat_produtos = ProductCategory.find_by_path('produtos')
  4 +cat_produtos_diversos = cat_produtos.children.create!(:name => 'Produtos diversos', :environment => cat_produtos.environment)
  5 +cat_servicos = ProductCategory.find_by_path('servicos')
  6 +cat_servicos_diversos = cat_servicos.children.find_by_name('Prestação de serviços diversos')
  7 +cat_diversos = ProductCategory.find_by_path('producao-e-servicos-diversos')
  8 +
  9 +cat_to_produtos = ProductCategory.top_level_for(Environment.default).select{|pc|![cat_diversos, cat_servicos, cat_produtos].include?(pc)}
  10 +cat_to_servicos = cat_diversos.children.select{|pc| ["Ação comunitária","Carro alugado","Carro de som","Distribuiçao de água","Em fase de implantação","Ilegível","Mensalidades","Pistas skate"].include?(pc.name)}
  11 +cat_to_produtos += (cat_diversos.children - cat_to_servicos)
  12 +
  13 +cat_to_produtos.each do |cat|
  14 + cat.parent = cat_produtos_diversos
  15 + cat.save!
  16 +end
  17 +
  18 +cat_to_produtos.each do |cat|
  19 + cat.parent = cat_servicos_diversos
  20 + cat.save!
  21 +end
  22 +
  23 +cat_diversos.destroy
... ...