This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
2012-05-11 08:16:09 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
namespace :items do
|
|
|
|
task :tree_changes => :environment do
|
|
|
|
Item.all.each do |item|
|
2012-05-11 09:56:26 +00:00
|
|
|
item.position -= item.position > 5 ? 2 : 1
|
2012-05-11 08:16:09 +00:00
|
|
|
item.parent_ids = ancestors(item)
|
|
|
|
item.rename(:full_name, :path)
|
|
|
|
item.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ancestors(item)
|
|
|
|
node, nodes = item, []
|
|
|
|
nodes << node = node.parent while !node.parent.blank? rescue nil
|
|
|
|
nodes.reverse
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|