lib/fertile_forest/modules/reconstructers.rb
#
# Remove the node and shift depth of descendant nodes.
#   soft delete
#    (1) soft delete
#    (2) grove delete
#    (3) normal delete
# @param node_obj [Entity|Integer] Node to remove.
# @return [Boolean] true: Success.
# @return [Boolean] false: Failure.
#
Remove the node and shift depth of descendant nodes.
Remove the node and shift depth of descendant nodes .
def remove(node_obj)
            transaction do
              remove_node = ff_resolve_nodes(node_obj, true)       
              raise ActiveRecord::Rollback if remove_node.blank?   
              aim_queue = remove_node.ff_queue
              aim_depth = remove_node.ff_depth
              aim_grove = remove_node.ff_grove
              if aim_depth == ROOT_DEPTH
                offset_depth = 1
              else
                parent_node = genitor(remove_node)
                raise ActiveRecord::Rollback if parent_node.blank?
                offset_depth = aim_depth - parent_node.ff_depth
              end
              remove_query = ff_subtree_scope(remove_node, true, false)
              ffdd = arel_table[@_ff_depth]
              update_columns = []
              depth_value = ff_create_case_expression(
                @_ff_queue,
                [[aim_queue, 0]],               
                "ff_depth - #{offset_depth}"    
              )
              update_columns << "ff_depth = (#{depth_value})"
              if has_soft_delete? || enable_grove_delete?
                if has_soft_delete?
                  delete_value = ff_create_case_expression(
                    @_ff_queue,
                    [[aim_queue, ff_options[:delete_value]]],     
                    @_ff_soft_delete    
                  )
                  update_columns << "#{@_ff_soft_delete} = (#{delete_value})"
                else
                  delete_value = ff_create_case_expression(
                    @_ff_queue,
                    [[aim_queue, -1]],    
                    1                     
                  )
                  update_columns << "#{@_ff_grove} = #{@_ff_grove} * (#{delete_value})"
                end
                res = remove_query.update_all(update_columns.join(', '))
              else
                update_res = remove_query.update_all(update_columns.join(', '))
                res = delete_all(@_id => remove_node.id)
              end
              res
            end   
          end
def remove ( node_obj ) transaction do remove_node = ff_resolve_nodes ( node_obj , true ) raise ActiveRecord :: Rollback if remove_node . blank? aim_queue = remove_node . ff_queue aim_depth = remove_node . ff_depth aim_grove = remove_node . ff_grove if aim_depth == ROOT_DEPTH offset_depth = 1 else parent_node = genitor ( remove_node ) raise ActiveRecord :: Rollback if parent_node . blank? offset_depth = aim_depth - parent_node . ff_depth end remove_query = ff_subtree_scope ( remove_node , true , false ) ffdd = arel_table [ @_ff_depth ] update_columns = [ ] depth_value = ff_create_case_expression ( @_ff_queue , [ [ aim_queue , 0 ] ] , "ff_depth - #{offset_depth}" ) update_columns << "ff_depth = (#{depth_value})" if has_soft_delete? || enable_grove_delete? if has_soft_delete? delete_value = ff_create_case_expression ( @_ff_queue , [ [ aim_queue , ff_options [ :delete_value ] ] ] , @_ff_soft_delete ) update_columns << "#{@_ff_soft_delete} = (#{delete_value})" else delete_value = ff_create_case_expression ( @_ff_queue , [ [ aim_queue , - 1 ] ] , 1 ) update_columns << "#{@_ff_grove} = #{@_ff_grove} * (#{delete_value})" end res = remove_query . update_all ( update_columns . join ( ', ' ) ) else update_res = remove_query . update_all ( update_columns . join ( ', ' ) ) res = delete_all ( @_id => remove_node . id ) end res end end
Remove the node and shift depth of descendant nodes.
Remove the node and shift depth of descendant nodes .
# refresh # nil as dubious # get range of descendants for shifting these depth # for soft delete # can not use subquery for same table in UPDATE # Mysql2::Error: You can't specify target table 'categories' for update in FROM clause: # when then # else value # when then # else value # when then # else value # hard delete # tansaction end
None
Boolean
None
Boolean
node_obj
Node to remove.
Node to remove .