summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2014-05-24 10:17:18 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2014-05-24 10:17:18 +0000
commit9ea1ae48dbed80374ced4c5c803e0f83e8b31a08 (patch)
treee20fe73b31b3a9694dd54b5e66ad9ee3f88ef975 /lib/plugins
parente22c5c3f80df692cad6397dc41c9dfcb6171e5b3 (diff)
downloadredmine-9ea1ae48dbed80374ced4c5c803e0f83e8b31a08.tar.gz
redmine-9ea1ae48dbed80374ced4c5c803e0f83e8b31a08.zip
awesome_nested_set: import git 2-1-stable branch revision 8eaab19868f326 (#6579)
https://github.com/collectiveidea/awesome_nested_set/commit/8eaab19868f326 git-svn-id: http://svn.redmine.org/redmine/trunk@13145 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb4
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb2
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb3
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb2
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb25
5 files changed, 28 insertions, 8 deletions
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb
index 9b6a733c8..aba32cb96 100644
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb
+++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb
@@ -51,6 +51,10 @@ module CollectiveIdea #:nodoc:
connection.quote_column_name(order_column)
end
+ def quoted_order_column_full_name
+ "#{quoted_table_name}.#{quoted_order_column_name}"
+ end
+
def quoted_left_column_full_name
"#{quoted_table_name}.#{quoted_left_column_name}"
end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb
index e8d1e1844..abd1fc013 100644
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb
+++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb
@@ -72,7 +72,7 @@ module CollectiveIdea #:nodoc:
end
def nested_set_scope(options = {})
- options = {:order => quoted_order_column_name}.merge(options)
+ options = {:order => quoted_order_column_full_name}.merge(options)
order(options.delete(:order)).scoped options
end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb
index 501b311e3..bb21d055a 100644
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb
+++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb
@@ -19,6 +19,9 @@ module CollectiveIdea #:nodoc:
# update lefts and rights for remaining nodes
update_siblings_for_remaining_nodes
+ # Reload is needed because children may have updated their parent (self) during deletion.
+ reload
+
# Don't allow multiple calls to destroy to corrupt the set
self.skip_before_destroy = true
end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
index 0b84673f1..2772dff5c 100644
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
+++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
@@ -17,7 +17,7 @@ module CollectiveIdea
def no_duplicates_for_columns?
[quoted_left_column_full_name, quoted_right_column_full_name].all? do |column|
# No duplicates
- select("#{scope_string}#{column}, COUNT(#{column})").
+ select("#{scope_string}#{column}, COUNT(#{column}) as _count").
group("#{scope_string}#{column}").
having("COUNT(#{column}) > 1").
first.nil?
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb
index afc1152de..c65e05e88 100644
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb
+++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb
@@ -24,8 +24,9 @@ module CollectiveIdea #:nodoc:
lock_nodes_between! a, d
- nested_set_scope.where(where_statement(a, d)).
- update_all(conditions(a, b, c, d))
+ nested_set_scope.where(where_statement(a, d)).update_all(
+ conditions(a, b, c, d)
+ )
end
private
@@ -44,11 +45,23 @@ module CollectiveIdea #:nodoc:
end
def conditions(a, b, c, d)
+ _conditions = case_condition_for_direction(:quoted_left_column_name) +
+ case_condition_for_direction(:quoted_right_column_name) +
+ case_condition_for_parent
+
+ # We want the record to be 'touched' if it timestamps.
+ if @instance.respond_to?(:updated_at)
+ _conditions << ", updated_at = :timestamp"
+ end
+
[
- case_condition_for_direction(:quoted_left_column_name) +
- case_condition_for_direction(:quoted_right_column_name) +
- case_condition_for_parent,
- {:a => a, :b => b, :c => c, :d => d, :id => instance.id, :new_parent => new_parent}
+ _conditions,
+ {
+ :a => a, :b => b, :c => c, :d => d,
+ :id => instance.id,
+ :new_parent => new_parent,
+ :timestamp => Time.now.utc
+ }
]
end