Skip to content

Commit

Permalink
Modified fullpath content to store root node zip to uniformize conten…
Browse files Browse the repository at this point in the history
…t. Fixes in home for root node.
  • Loading branch information
gaspard committed Nov 4, 2013
1 parent 543f6bd commit 168404c
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 75 deletions.
9 changes: 2 additions & 7 deletions app/models/site.rb
Expand Up @@ -525,15 +525,10 @@ def rebuild_fullpath(parent_id = nil, parent_fullpath = "", parent_basepath = ""
rec = Zena::Db.fetch_attributes(['id', 'fullpath', 'basepath', 'custom_base', 'zip'], 'nodes', "parent_id #{parent_id ? "= #{parent_id}" : "IS NULL"} AND site_id = #{self.id} ORDER BY id ASC LIMIT #{batch_size} OFFSET #{i * batch_size}")
break if rec.empty?
rec.each do |rec|
if parent_id
rec['fullpath'] = parent_fullpath == '' ? rec['zip'] : "#{parent_fullpath}/#{rec['zip']}"
else
# root node
rec['fullpath'] = ''
end
rec['fullpath'] = parent_fullpath == '' ? rec['zip'] : "#{parent_fullpath}/#{rec['zip']}"

if rec['custom_base'] == Zena::Db::TRUE_RESULT
rec['basepath'] = rec['fullpath']
rec['basepath'] = Zena::Use::Ancestry.basepath_from_fullpath(rec['fullpath'])
else
rec['basepath'] = parent_basepath
end
Expand Down
@@ -0,0 +1,10 @@
class RebuildFullpathAfterChange < ActiveRecord::Migration
def self.up
Site.master_sites.each do |site|
site.rebuild_fullpath
end
end

def self.down
end
end
4 changes: 2 additions & 2 deletions lib/zena/foxy_parser.rb
Expand Up @@ -438,7 +438,7 @@ def make_paths(node, name)
begin
eval(klass).kpath =~ /^#{Page.kpath}/
if node['custom_base']
node['basepath'] = node['fullpath']
node['basepath'] = node['fullpath'].split('/')[1..-1].join('/')
else
node['basepath'] = parent['basepath']
end
Expand All @@ -447,8 +447,8 @@ def make_paths(node, name)
end
else
# If we do not quote the content, FoxyParser will insert NULL.
node['fullpath'] = "#{node['zip']}"
node['basepath'] = "''"
node['fullpath'] = "''"
end
end
node['fullpath']
Expand Down
20 changes: 14 additions & 6 deletions lib/zena/use/ancestry.rb
Expand Up @@ -2,6 +2,11 @@ module Zena
module Use
# This module handles the creation and maintenance of a 'fullpath' and cached project/section_id.
module Ancestry

def self.basepath_from_fullpath(fullpath)
fullpath.split('/')[1..-1].join('/')
end

module ClassMethods
def title_join
%Q{INNER JOIN idx_nodes_ml_strings AS id1 ON id1.node_id = nodes.id AND id1.key = 'title' AND id1.lang = '#{visitor.lang}'}
Expand Down Expand Up @@ -103,7 +108,7 @@ def ancestors(start=[])
elsif parent_id.nil?
[]
else
path = fullpath.split('/')[0..-2]
path = fullpath.split('/')[1..-2]
[current_site.root_node].compact + (secure(Node) { Node.fullpath_map(path, :node) } || [])
end
end
Expand Down Expand Up @@ -137,8 +142,10 @@ def pseudo_id(root_node, sym)
end

# (slow). Transform a list of zips into a fullpath.
def fullpath_as_title(path = fullpath)
if path == self.fullpath
def fullpath_as_title(path = nil)
if !path
# When using fullpath, we remove first element (root)
path = fullpath.split('/')[1..-1]
# secure returns nil instead of [] so we fix this.
@fullpath_as_title ||= secure(Node) { Node.fullpath_map(path, :title) } || []
else
Expand All @@ -164,15 +171,15 @@ def rebuild_fullpath
if parent = parent(false)
path = parent.fullpath.split('/') + [zip]
else
path = []
path = [zip]
end
self.fullpath = path.join('/')
end

def rebuild_basepath
return unless new_record? || parent_id_changed? || custom_base_changed? || basepath.nil?
if custom_base
self[:basepath] = self.fullpath
self[:basepath] = Ancestry.basepath_from_fullpath(self.fullpath)
elsif parent = parent(false)
self[:basepath] = parent.basepath || ""
else
Expand All @@ -199,7 +206,7 @@ def rebuild_children_fullpath
list.each do |rec|
rec['fullpath'].sub!(fullpath_re, fullpath_new) if fullpath_re
if rec['custom_base'] == Zena::Db::TRUE_RESULT
rec['basepath'] = rec['fullpath']
rec['basepath'] = Ancestry.basepath_from_fullpath(rec['fullpath'])
bases << rec['basepath']
else
while rec['fullpath'].size <= bases.last.size
Expand All @@ -215,6 +222,7 @@ def rebuild_children_fullpath
end
true
end

end # ModelMethods
end # Ancestry
end # Use
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/urls.rb
Expand Up @@ -599,7 +599,7 @@ def make_href(remote_target = nil, opts = {})
end

method = "#{method}(#{method_args.join(', ')})"

::RubyLess.translate(self, method)
end

Expand Down
4 changes: 2 additions & 2 deletions test/integration/query_node/relations.yml
Expand Up @@ -93,5 +93,5 @@ having_on_relation_count:

# TODO: change how fullpath is built should solve this issue.
in_home:
src: "documents in home"
res: bird, flower
src: "images in home"
res: it's a lake, bird, flower, Autumn Tree
2 changes: 1 addition & 1 deletion test/unit/note_test.rb
Expand Up @@ -7,7 +7,7 @@ def test_create_simplest
test_page = secure!(Note) { Note.create(:title => "yoba", :parent_id => nodes_id(:cleanWater), :inherit=>1 ) }
assert ! test_page.new_record? , "Not a new record"
assert_equal nodes_id(:cleanWater), test_page.parent[:id]
assert_equal "18/21/#{test_page.zip}", test_page.fullpath
assert_equal "11/18/21/#{test_page.zip}", test_page.fullpath
assert_equal '18/21', test_page.basepath
end

Expand Down
12 changes: 6 additions & 6 deletions test/unit/site_test.rb
Expand Up @@ -289,19 +289,19 @@ def test_rebuild_fullpath
opening = secure(Node) { nodes(:opening) }
cleanWater = secure(Node) { nodes(:cleanWater) }
art = secure(Node) { nodes(:art) }
assert_equal fullpath(:projects, :cleanWater, :status), status.fullpath
assert_equal fullpath(:zena, :projects, :cleanWater, :status), status.fullpath
assert_equal fullpath(:projects, :cleanWater), status.basepath
assert_equal false, status.custom_base

assert_equal fullpath(:projects, :cleanWater, :opening), opening.fullpath
assert_equal fullpath(:zena, :projects, :cleanWater, :opening), opening.fullpath
assert_equal fullpath(:projects, :cleanWater), opening.basepath
assert_equal false, opening.custom_base

assert_equal fullpath(:projects, :cleanWater), cleanWater.fullpath
assert_equal fullpath(:zena, :projects, :cleanWater), cleanWater.fullpath
assert_equal fullpath(:projects, :cleanWater), cleanWater.basepath
assert_equal true, cleanWater.custom_base

assert_equal fullpath(:collections, :art), art.fullpath
assert_equal fullpath(:zena, :collections, :art), art.fullpath
assert_equal '', art.basepath
assert_equal false, art.custom_base
end
Expand All @@ -317,10 +317,10 @@ def test_rebuild_fullpath

should 'not alter fullpath' do
node = secure!(Node) { nodes(:status) }
assert_equal fullpath(:projects, :cleanWater, :status), node.fullpath
assert_equal fullpath(:zena, :projects, :cleanWater, :status), node.fullpath
subject.clear_cache
node = secure!(Node) { nodes(:status) }
assert_equal fullpath(:projects, :cleanWater, :status), node.fullpath
assert_equal fullpath(:zena, :projects, :cleanWater, :status), node.fullpath
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/unit/zena/use/ancestry_test.rb
Expand Up @@ -68,12 +68,12 @@ class AncestryTest < Zena::Unit::TestCase
end

should 'rebuild fullpath in new parent' do
assert_equal fullpath(:people, :lion, :secret), subject.fullpath
assert_equal fullpath(:zena, :people, :lion, :secret), subject.fullpath
end

should 'rebuild children fullpath' do
assert_equal fullpath(:people, :lion, :secret, :talk), nodes(:talk).fullpath
assert_equal fullpath(:people, :lion, :secret, :proposition), nodes(:proposition).fullpath
assert_equal fullpath(:zena, :people, :lion, :secret, :talk), nodes(:talk).fullpath
assert_equal fullpath(:zena, :people, :lion, :secret, :proposition), nodes(:proposition).fullpath
end

context 'with custom_base set' do
Expand Down Expand Up @@ -188,12 +188,12 @@ class AncestryTest < Zena::Unit::TestCase
end

should 'build fullpath' do
assert_equal [nodes_zip(:projects), subject.zip].join('/'), subject.fullpath
assert_equal [nodes_zip(:zena), nodes_zip(:projects), subject.zip].join('/'), subject.fullpath
end

should 'build basepath' do
err subject
assert_equal [nodes_zip(:projects), subject.zip].join('/'), subject.fullpath
assert_equal [nodes_zip(:zena), nodes_zip(:projects), subject.zip].join('/'), subject.fullpath
end
end # creating a node

Expand Down
92 changes: 47 additions & 45 deletions zena.gemspec
Expand Up @@ -408,6 +408,8 @@ Gem::Specification.new do |s|
"bricks/zena/zena/migrate/20130829093753_add_versioned_flag_to_column.rb",
"bricks/zena/zena/migrate/20130903084909_count_login_attempts.rb",
"bricks/zena/zena/migrate/20130903150356_longer_names_for_acl.rb",
"bricks/zena/zena/migrate/20131104153126_index_fullpath.rb",
"bricks/zena/zena/migrate/20131104210011_rebuild_fullpath_after_change.rb",
"config/boot.rb",
"config/bricks.yml",
"config/database_example.yml",
Expand Down Expand Up @@ -2229,84 +2231,84 @@ Gem::Specification.new do |s|
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_runtime_dependency(%q<open4>, [">= 0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_runtime_dependency(%q<yamltest>, ["= 0.7.0"])
s.add_runtime_dependency(%q<gem_plugin>, [">= 0"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_runtime_dependency(%q<json>, ["= 1.5.1"])
s.add_runtime_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_runtime_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_runtime_dependency(%q<property>, ["= 2.3.4"])
s.add_runtime_dependency(%q<rails>, ["= 2.3.18"])
s.add_runtime_dependency(%q<daemons>, [">= 0"])
s.add_runtime_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_runtime_dependency(%q<httmultiparty>, ["= 0.3.8"])
s.add_runtime_dependency(%q<property>, ["= 2.3.4"])
s.add_runtime_dependency(%q<differ>, ["= 0.1.2"])
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
s.add_runtime_dependency(%q<json>, ["= 1.5.1"])
s.add_runtime_dependency(%q<open4>, [">= 0"])
s.add_runtime_dependency(%q<tzinfo>, [">= 0"])
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
s.add_runtime_dependency(%q<versions>, ["= 0.3.1"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_runtime_dependency(%q<querybuilder>, ["= 1.2.3"])
s.add_runtime_dependency(%q<gettext>, ["= 2.1.0"])
s.add_runtime_dependency(%q<ruby-recaptcha>, ["= 1.0.3"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_runtime_dependency(%q<differ>, ["= 0.1.2"])
s.add_runtime_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_runtime_dependency(%q<querybuilder>, ["= 1.2.2"])
s.add_runtime_dependency(%q<gettext>, ["= 2.1.0"])
s.add_runtime_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_runtime_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_runtime_dependency(%q<versions>, ["= 0.3.1"])
s.add_runtime_dependency(%q<syntax>, ["= 1.0.0"])
s.add_runtime_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
else
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<open4>, [">= 0"])
s.add_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_dependency(%q<yamltest>, ["= 0.7.0"])
s.add_dependency(%q<gem_plugin>, [">= 0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_dependency(%q<json>, ["= 1.5.1"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<property>, ["= 2.3.4"])
s.add_dependency(%q<rails>, ["= 2.3.18"])
s.add_dependency(%q<daemons>, [">= 0"])
s.add_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_dependency(%q<httmultiparty>, ["= 0.3.8"])
s.add_dependency(%q<property>, ["= 2.3.4"])
s.add_dependency(%q<differ>, ["= 0.1.2"])
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<json>, ["= 1.5.1"])
s.add_dependency(%q<open4>, [">= 0"])
s.add_dependency(%q<tzinfo>, [">= 0"])
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<versions>, ["= 0.3.1"])
s.add_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_dependency(%q<querybuilder>, ["= 1.2.3"])
s.add_dependency(%q<gettext>, ["= 2.1.0"])
s.add_dependency(%q<ruby-recaptcha>, ["= 1.0.3"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<differ>, ["= 0.1.2"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<querybuilder>, ["= 1.2.2"])
s.add_dependency(%q<gettext>, ["= 2.1.0"])
s.add_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_dependency(%q<versions>, ["= 0.3.1"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
s.add_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
end
else
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<open4>, [">= 0"])
s.add_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_dependency(%q<yamltest>, ["= 0.7.0"])
s.add_dependency(%q<gem_plugin>, [">= 0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_dependency(%q<json>, ["= 1.5.1"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<property>, ["= 2.3.4"])
s.add_dependency(%q<rails>, ["= 2.3.18"])
s.add_dependency(%q<daemons>, [">= 0"])
s.add_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_dependency(%q<authlogic>, ["= 2.1.9"])
s.add_dependency(%q<httmultiparty>, ["= 0.3.8"])
s.add_dependency(%q<property>, ["= 2.3.4"])
s.add_dependency(%q<differ>, ["= 0.1.2"])
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<json>, ["= 1.5.1"])
s.add_dependency(%q<open4>, [">= 0"])
s.add_dependency(%q<tzinfo>, [">= 0"])
s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<versions>, ["= 0.3.1"])
s.add_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_dependency(%q<querybuilder>, ["= 1.2.3"])
s.add_dependency(%q<gettext>, ["= 2.1.0"])
s.add_dependency(%q<ruby-recaptcha>, ["= 1.0.3"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
s.add_dependency(%q<differ>, ["= 0.1.2"])
s.add_dependency(%q<fast_gettext>, ["~> 0.4.16"])
s.add_dependency(%q<querybuilder>, ["= 1.2.2"])
s.add_dependency(%q<gettext>, ["= 2.1.0"])
s.add_dependency(%q<will_paginate>, ["~> 2.3.12"])
s.add_dependency(%q<RedCloth>, ["= 3.0.4"])
s.add_dependency(%q<rubyless>, ["= 0.8.11"])
s.add_dependency(%q<versions>, ["= 0.3.1"])
s.add_dependency(%q<syntax>, ["= 1.0.0"])
s.add_dependency(%q<safe_yaml>, ["= 0.8.0"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
end
end

0 comments on commit 168404c

Please sign in to comment.