Ticket #10: sti-fix.patch

File sti-fix.patch, 16.0 kB (added by tolsen@limewire.com, 2 years ago)

patch of fix #10

  • vendor/plugins/better_nested_set/lib/better_nested_set.rb

    old new  
    8686               :left_column    => (options[:left_column]   || 'lft'), 
    8787               :right_column   => (options[:right_column]  || 'rgt'), 
    8888               :scope          => (options[:scope] || '1 = 1'), 
    89                :text_column    => (options[:text_column] || columns.collect{|c| (c.type == :string) ? c.name : nil }.compact.first) 
     89               :text_column    => (options[:text_column] || columns.collect{|c| (c.type == :string) ? c.name : nil }.compact.first), 
     90               :class          => self 
    9091              } ) 
    9192                
    9293          class_inheritable_reader :acts_as_nested_set_options 
     
    112113          extend SymetrieCom::Acts::NestedSet::ClassMethods 
    113114           
    114115          # adds the helper for the class 
    115 #          ActionView::Base.send(:define_method, "#{Inflector.underscore(self.class)}_options_for_select") { special=nil 
    116 #              "#{acts_as_nested_set_options[:text_column]} || "#{self.class} id #{id}" 
     116#          ActionView::Base.send(:define_method, "#{Inflector.underscore(acts_as_nested_set_options[:class])}_options_for_select") { special=nil 
     117#              "#{acts_as_nested_set_options[:text_column]} || "#{acts_as_nested_set_options[:class]} id #{id}" 
    117118#            } 
    118119           
    119120        end         
     
    136137 
    137138        # on creation, set automatically lft and rgt to the end of the tree 
    138139        def before_create 
    139           maxright = self.class.maximum(acts_as_nested_set_options[:right_column], :conditions => acts_as_nested_set_options[:scope]) || 0 
     140          maxright = acts_as_nested_set_options[:class].maximum(acts_as_nested_set_options[:right_column], :conditions => acts_as_nested_set_options[:scope]) || 0 
    140141          # adds the new node to the right of all existing nodes 
    141142          self[acts_as_nested_set_options[:left_column]] = maxright+1 
    142143          self[acts_as_nested_set_options[:right_column]] = maxright+2 
     
    198199              child[acts_as_nested_set_options[:left_column]] = right_bound 
    199200              child[acts_as_nested_set_options[:right_column]] = right_bound + 1 
    200201              self[acts_as_nested_set_options[:right_column]] += 2 
    201               self.class.transaction { 
    202                 self.class.update_all( "#{acts_as_nested_set_options[:left_column]} = (#{acts_as_nested_set_options[:left_column]} + 2)",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} >= #{right_bound}" ) 
    203                 self.class.update_all( "#{acts_as_nested_set_options[:right_column]} = (#{acts_as_nested_set_options[:right_column]} + 2)",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:right_column]} >= #{right_bound}" ) 
     202              acts_as_nested_set_options[:class].transaction { 
     203                acts_as_nested_set_options[:class].update_all( "#{acts_as_nested_set_options[:left_column]} = (#{acts_as_nested_set_options[:left_column]} + 2)",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} >= #{right_bound}" ) 
     204                acts_as_nested_set_options[:class].update_all( "#{acts_as_nested_set_options[:right_column]} = (#{acts_as_nested_set_options[:right_column]} + 2)",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:right_column]} >= #{right_bound}" ) 
    204205                self.save 
    205206                child.save 
    206207              } 
     
    210211         
    211212        # Returns root 
    212213        def root 
    213             self.class.find(:first, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)") 
     214            acts_as_nested_set_options[:class].find(:first, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)") 
    214215        end 
    215216                 
    216217        # Returns roots when multiple roots (or virtual root, which is the same) 
    217218        def roots 
    218             self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)", :order => "#{acts_as_nested_set_options[:left_column]}") 
     219            acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:parent_column]} IS NULL)", :order => "#{acts_as_nested_set_options[:left_column]}") 
    219220        end 
    220221                 
    221222        # Returns the parent 
    222223        def parent 
    223             self.class.find(self[acts_as_nested_set_options[:parent_column]]) if self[acts_as_nested_set_options[:parent_column]] 
     224            acts_as_nested_set_options[:class].find(self[acts_as_nested_set_options[:parent_column]]) if self[acts_as_nested_set_options[:parent_column]] 
    224225        end 
    225226         
    226227        # Returns an array of all parents  
    227228        # Maybe 'full_outline' would be a better name, but we prefer to mimic the Tree class 
    228229        def ancestors 
    229             self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column] ) 
     230            acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column] ) 
    230231        end 
    231232         
    232233        # Returns the array of all parents and self 
     
    244245            if self[acts_as_nested_set_options[:parent_column]].nil? || self[acts_as_nested_set_options[:parent_column]].zero? 
    245246                [self] 
    246247            else 
    247                 self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} and #{acts_as_nested_set_options[:parent_column]} = #{self[acts_as_nested_set_options[:parent_column]]}", :order => acts_as_nested_set_options[:left_column]) 
     248                acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} and #{acts_as_nested_set_options[:parent_column]} = #{self[acts_as_nested_set_options[:parent_column]]}", :order => acts_as_nested_set_options[:left_column]) 
    248249            end 
    249250        end 
    250251         
     
    252253        # root level is 0 
    253254        def level 
    254255            return 0 if self[acts_as_nested_set_options[:parent_column]].nil? 
    255             self.class.count("#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})") 
     256            acts_as_nested_set_options[:class].count("#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} < #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} > #{self[acts_as_nested_set_options[:right_column]]})") 
    256257        end                                   
    257258                                            
    258259        # Returns the number of nested children of this object. 
     
    264265        # Pass :exclude => item, or id, or [items or id] to exclude some parts of the tree 
    265266        def full_set(special=nil) 
    266267          return [self] if new_record? or self[acts_as_nested_set_options[:right_column]]-self[acts_as_nested_set_options[:left_column]] == 1 
    267 #          self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} BETWEEN #{self[acts_as_nested_set_options[:left_column]]} and #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
     268#          acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} BETWEEN #{self[acts_as_nested_set_options[:left_column]]} and #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
    268269          [self] + all_children(special) 
    269270        end 
    270271                   
     
    276277              # exclude some items and all their children 
    277278              special[:exclude] = [special[:exclude]] if !special[:exclude].is_a?(Array) 
    278279              # get objects for ids 
    279               special[:exclude].collect! {|s| s.is_a?(self.class) ? s : self.class.find(s)} 
     280              special[:exclude].collect! {|s| s.is_a?(acts_as_nested_set_options[:class]) ? s : acts_as_nested_set_options[:class].find(s)} 
    280281              # get all subtrees and flatten the list 
    281282              exclude_list = special[:exclude].map{|e| e.full_set.map{|ee| ee.id}}.flatten.uniq.join(',') 
    282283              if exclude_list.blank? 
    283                 self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
     284                acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
    284285              else 
    285                 self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND id NOT IN (#{exclude_list}) AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
     286                acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND id NOT IN (#{exclude_list}) AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
    286287              end 
    287288            end 
    288289          else 
    289             self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
     290            acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND (#{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]}) and (#{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]})", :order => acts_as_nested_set_options[:left_column]) 
    290291          end 
    291292        end 
    292293 
    293294        # Returns a set of only this entry's immediate children 
    294295        def children 
    295             self.class.find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:parent_column]} = #{self.id}", :order => acts_as_nested_set_options[:left_column]) 
     296            acts_as_nested_set_options[:class].find(:all, :conditions => "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:parent_column]} = #{self.id}", :order => acts_as_nested_set_options[:left_column]) 
    296297        end 
    297298                                       
    298299        # Prunes a branch off of the tree, shifting all of the elements on the right 
     
    301302          return if self[acts_as_nested_set_options[:right_column]].nil? || self[acts_as_nested_set_options[:left_column]].nil? 
    302303          dif = self[acts_as_nested_set_options[:right_column]] - self[acts_as_nested_set_options[:left_column]] + 1 
    303304 
    304           self.class.transaction { 
    305             self.class.delete_all( "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]}" ) 
    306             self.class.update_all( "#{acts_as_nested_set_options[:left_column]} = (#{acts_as_nested_set_options[:left_column]} - #{dif})",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} >= #{self[acts_as_nested_set_options[:right_column]]}" ) 
    307             self.class.update_all( "#{acts_as_nested_set_options[:right_column]} = (#{acts_as_nested_set_options[:right_column]} - #{dif} )",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:right_column]} >= #{self[acts_as_nested_set_options[:right_column]]}" ) 
     305          acts_as_nested_set_options[:class].transaction { 
     306            acts_as_nested_set_options[:class].delete_all( "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} > #{self[acts_as_nested_set_options[:left_column]]} and #{acts_as_nested_set_options[:right_column]} < #{self[acts_as_nested_set_options[:right_column]]}" ) 
     307            acts_as_nested_set_options[:class].update_all( "#{acts_as_nested_set_options[:left_column]} = (#{acts_as_nested_set_options[:left_column]} - #{dif})",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:left_column]} >= #{self[acts_as_nested_set_options[:right_column]]}" ) 
     308            acts_as_nested_set_options[:class].update_all( "#{acts_as_nested_set_options[:right_column]} = (#{acts_as_nested_set_options[:right_column]} - #{dif} )",  "#{acts_as_nested_set_options[:scope]} AND #{acts_as_nested_set_options[:right_column]} >= #{self[acts_as_nested_set_options[:right_column]]}" ) 
    308309          } 
    309310        end 
    310311         
     
    334335          extent = cur_right - cur_left + 1 
    335336           
    336337          # load object if node is not an object 
    337           if !(self.class === target
    338             target = self.class.find(target) 
     338          if !(target.kind_of? acts_as_nested_set_options[:class]
     339            target = acts_as_nested_set_options[:class].find(target) 
    339340          end 
    340341          target_left, target_right = target[acts_as_nested_set_options[:left_column]], target[acts_as_nested_set_options[:right_column]] 
    341342 
     
    390391          end 
    391392           
    392393          # update and that rules 
    393           self.class.update_all( "#{acts_as_nested_set_options[:left_column]} = CASE \ 
     394          acts_as_nested_set_options[:class].update_all( "#{acts_as_nested_set_options[:left_column]} = CASE \ 
    394395                                      WHEN #{acts_as_nested_set_options[:left_column]} BETWEEN #{cur_left} AND #{cur_right} \ 
    395396                                        THEN #{acts_as_nested_set_options[:left_column]} + #{shift} \ 
    396397                                      WHEN #{acts_as_nested_set_options[:left_column]} BETWEEN #{b_left} AND #{b_right} \ 
     
    403404                                        THEN #{acts_as_nested_set_options[:right_column]} + #{updown} \ 
    404405                                      ELSE #{acts_as_nested_set_options[:right_column]} END, \ 
    405406                                  #{acts_as_nested_set_options[:parent_column]} = CASE \ 
    406                                       WHEN #{self.class.primary_key} = #{self.id} \ 
     407                                      WHEN #{acts_as_nested_set_options[:class].primary_key} = #{self.id} \ 
    407408                                        THEN #{new_parent} \ 
    408409                                      ELSE #{acts_as_nested_set_options[:parent_column]} END", 
    409410                                  acts_as_nested_set_options[:scope] )