app/models/page.rb
# Occasionally you'll see "NO NAME" for some page IDs (in searches, associations, collections, and so on), and this
# can be caused by the native_node_id being set to a node that no longer exists. You should try and track down the
# source of that problem, but this code can be used to (slowly) fix the problem, where it's possible to do so:
Occasionally you'll see "NO NAME" for some page IDs (in searches, associations, collections, and so on), and this
can be caused by the native_node_id being set to a node that no longer exists. You should try and track down the
source of that problem, but this code can be used to (slowly) fix the problem, where it's possible to do so.
Occasionally you ' ll see " NO NAME " for some page IDs ( in searches associations collections and so on ) and this can be caused by the native_node_id being set to a node that no longer exists . You should try and track down the source of that problem but this code can be used to ( slowly ) fix the problem where it ' s possible to do so .
def fix_missing_native_nodes(scope)
      pages = scope.joins('LEFT JOIN nodes ON (pages.native_node_id = nodes.id)').where('nodes.id IS NULL')
      pages.includes(:nodes).find_each do |page|
        if page.nodes.empty?
          if PageContent.exists?(page_id: page.id) || ScientificName.exists?(page_id: page.id)
            log_healing("!! RETAINED nodeless page #{page.id} because it had content (or a name). "\
                        "You should investigate")
          else
            log_healing("!! DESTROYED page #{page.id}")
            page.destroy
          end
        else
          correct_id = page.nodes.first.id
          log_healing("healed page #{page.id} (node #{page.native_node_id} -> #{correct_id})")
          page.update_attribute(:native_node_id, correct_id)
        end
      end
    end
def fix_missing_native_nodes ( scope ) pages = scope . joins ( 'LEFT JOIN nodes ON (pages.native_node_id = nodes.id)' ) . where ( 'nodes.id IS NULL' ) pages . includes ( :nodes ) . find_each do | page | if page . nodes . empty? if PageContent . exists? ( page_id : page . id ) || ScientificName . exists? ( page_id : page . id ) log_healing ( "!! RETAINED nodeless page #{page.id} because it had content (or a name). " "You should investigate" ) else log_healing ( "!! DESTROYED page #{page.id}" ) page . destroy end else correct_id = page . nodes . first . id log_healing ( "healed page #{page.id} (node #{page.native_node_id} -> #{correct_id})" ) page . update_attribute ( :native_node_id , correct_id ) end end end
Occasionally you'll see "NO NAME" for some page IDs (in searches, associations, collections, and so on), and this
can be caused by the native_node_id being set to a node that no longer exists.
Occasionally you ' ll see " NO NAME " for some page IDs ( in searches associations collections and so on ) and this can be caused by the native_node_id being set to a node that no longer exists .
# NOTE: This DOES destroy pages! ...But only if it's reasonably sure they have no content:
scope
<not_specific>