diff --git a/app/models/site.rb b/app/models/site.rb index 64a47b0c..b1b7a04e 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -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 diff --git a/bricks/zena/zena/migrate/20131104210011_rebuild_fullpath_after_change.rb b/bricks/zena/zena/migrate/20131104210011_rebuild_fullpath_after_change.rb new file mode 100644 index 00000000..6869920c --- /dev/null +++ b/bricks/zena/zena/migrate/20131104210011_rebuild_fullpath_after_change.rb @@ -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 diff --git a/lib/zena/foxy_parser.rb b/lib/zena/foxy_parser.rb index 489947e3..3be1c1f3 100644 --- a/lib/zena/foxy_parser.rb +++ b/lib/zena/foxy_parser.rb @@ -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 @@ -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'] diff --git a/lib/zena/use/ancestry.rb b/lib/zena/use/ancestry.rb index 9a531974..8689ecd1 100644 --- a/lib/zena/use/ancestry.rb +++ b/lib/zena/use/ancestry.rb @@ -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}'} @@ -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 @@ -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 @@ -164,7 +171,7 @@ def rebuild_fullpath if parent = parent(false) path = parent.fullpath.split('/') + [zip] else - path = [] + path = [zip] end self.fullpath = path.join('/') end @@ -172,7 +179,7 @@ def rebuild_fullpath 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 @@ -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 @@ -215,6 +222,7 @@ def rebuild_children_fullpath end true end + end # ModelMethods end # Ancestry end # Use diff --git a/lib/zena/use/urls.rb b/lib/zena/use/urls.rb index dfed68ab..c8922f85 100644 --- a/lib/zena/use/urls.rb +++ b/lib/zena/use/urls.rb @@ -599,7 +599,7 @@ def make_href(remote_target = nil, opts = {}) end method = "#{method}(#{method_args.join(', ')})" - + ::RubyLess.translate(self, method) end diff --git a/test/integration/query_node/relations.yml b/test/integration/query_node/relations.yml index bc7c39e5..b672139b 100644 --- a/test/integration/query_node/relations.yml +++ b/test/integration/query_node/relations.yml @@ -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 diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index ac371eb2..b3c33408 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -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 diff --git a/test/unit/site_test.rb b/test/unit/site_test.rb index 889f3381..ffdc3183 100644 --- a/test/unit/site_test.rb +++ b/test/unit/site_test.rb @@ -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 @@ -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 diff --git a/test/unit/zena/use/ancestry_test.rb b/test/unit/zena/use/ancestry_test.rb index 49282c4d..76f32b95 100644 --- a/test/unit/zena/use/ancestry_test.rb +++ b/test/unit/zena/use/ancestry_test.rb @@ -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 @@ -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 diff --git a/zena.gemspec b/zena.gemspec index 641389b3..07f82b2a 100644 --- a/zena.gemspec +++ b/zena.gemspec @@ -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", @@ -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, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, ["= 2.1.9"]) s.add_runtime_dependency(%q, ["= 0.7.0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, ["= 2.0.0"]) + s.add_runtime_dependency(%q, ["= 0.8.0"]) + s.add_runtime_dependency(%q, ["= 1.5.1"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, ["= 3.0.4"]) + s.add_runtime_dependency(%q, ["= 2.3.4"]) s.add_runtime_dependency(%q, ["= 2.3.18"]) s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, ["~> 2.3.12"]) + s.add_runtime_dependency(%q, ["= 2.1.9"]) s.add_runtime_dependency(%q, ["= 0.3.8"]) - s.add_runtime_dependency(%q, ["= 2.3.4"]) - s.add_runtime_dependency(%q, ["= 0.1.2"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, ["= 1.5.1"]) + s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, ["= 0.3.1"]) + s.add_runtime_dependency(%q, ["= 0.8.11"]) + s.add_runtime_dependency(%q, ["= 1.2.3"]) + s.add_runtime_dependency(%q, ["= 2.1.0"]) s.add_runtime_dependency(%q, ["= 1.0.3"]) - s.add_runtime_dependency(%q, ["= 2.10.3"]) + s.add_runtime_dependency(%q, ["= 0.1.2"]) s.add_runtime_dependency(%q, ["~> 0.4.16"]) - s.add_runtime_dependency(%q, ["= 1.2.2"]) - s.add_runtime_dependency(%q, ["= 2.1.0"]) - s.add_runtime_dependency(%q, ["~> 2.3.12"]) - s.add_runtime_dependency(%q, ["= 3.0.4"]) - s.add_runtime_dependency(%q, ["= 0.8.11"]) - s.add_runtime_dependency(%q, ["= 0.3.1"]) s.add_runtime_dependency(%q, ["= 1.0.0"]) - s.add_runtime_dependency(%q, ["= 0.8.0"]) + s.add_runtime_dependency(%q, ["= 2.10.3"]) else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 2.1.9"]) s.add_dependency(%q, ["= 0.7.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["= 2.0.0"]) + s.add_dependency(%q, ["= 0.8.0"]) + s.add_dependency(%q, ["= 1.5.1"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["= 3.0.4"]) + s.add_dependency(%q, ["= 2.3.4"]) s.add_dependency(%q, ["= 2.3.18"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 2.3.12"]) + s.add_dependency(%q, ["= 2.1.9"]) s.add_dependency(%q, ["= 0.3.8"]) - s.add_dependency(%q, ["= 2.3.4"]) - s.add_dependency(%q, ["= 0.1.2"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 1.5.1"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["= 0.3.1"]) + s.add_dependency(%q, ["= 0.8.11"]) + s.add_dependency(%q, ["= 1.2.3"]) + s.add_dependency(%q, ["= 2.1.0"]) s.add_dependency(%q, ["= 1.0.3"]) - s.add_dependency(%q, ["= 2.10.3"]) + s.add_dependency(%q, ["= 0.1.2"]) s.add_dependency(%q, ["~> 0.4.16"]) - s.add_dependency(%q, ["= 1.2.2"]) - s.add_dependency(%q, ["= 2.1.0"]) - s.add_dependency(%q, ["~> 2.3.12"]) - s.add_dependency(%q, ["= 3.0.4"]) - s.add_dependency(%q, ["= 0.8.11"]) - s.add_dependency(%q, ["= 0.3.1"]) s.add_dependency(%q, ["= 1.0.0"]) - s.add_dependency(%q, ["= 0.8.0"]) + s.add_dependency(%q, ["= 2.10.3"]) end else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 2.1.9"]) s.add_dependency(%q, ["= 0.7.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, ["= 2.0.0"]) + s.add_dependency(%q, ["= 0.8.0"]) + s.add_dependency(%q, ["= 1.5.1"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["= 3.0.4"]) + s.add_dependency(%q, ["= 2.3.4"]) s.add_dependency(%q, ["= 2.3.18"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["~> 2.3.12"]) + s.add_dependency(%q, ["= 2.1.9"]) s.add_dependency(%q, ["= 0.3.8"]) - s.add_dependency(%q, ["= 2.3.4"]) - s.add_dependency(%q, ["= 0.1.2"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["= 1.5.1"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, ["= 0.3.1"]) + s.add_dependency(%q, ["= 0.8.11"]) + s.add_dependency(%q, ["= 1.2.3"]) + s.add_dependency(%q, ["= 2.1.0"]) s.add_dependency(%q, ["= 1.0.3"]) - s.add_dependency(%q, ["= 2.10.3"]) + s.add_dependency(%q, ["= 0.1.2"]) s.add_dependency(%q, ["~> 0.4.16"]) - s.add_dependency(%q, ["= 1.2.2"]) - s.add_dependency(%q, ["= 2.1.0"]) - s.add_dependency(%q, ["~> 2.3.12"]) - s.add_dependency(%q, ["= 3.0.4"]) - s.add_dependency(%q, ["= 0.8.11"]) - s.add_dependency(%q, ["= 0.3.1"]) s.add_dependency(%q, ["= 1.0.0"]) - s.add_dependency(%q, ["= 0.8.0"]) + s.add_dependency(%q, ["= 2.10.3"]) end end