You are here

function _answers_orphan_nids in Answers 7.4

Same name and namespace in other branches
  1. 7.3 includes/answers.field_utils.inc \_answers_orphan_nids()

Implements helper for orphaned answers.

Return value

array An array of answer nids.

2 calls to _answers_orphan_nids()
answers_orphan_report in includes/answers.display.inc
Reports orphaned answers.
answers_requirements in ./answers.install
Implements hook_requirements().

File

includes/answers.helpers.inc, line 14
Helper functions for the Answers module.

Code

function _answers_orphan_nids() {
  $orphan_nids = array();
  $query = db_select('field_data_answers_related_question', 'q');
  $query
    ->leftJoin('node', 'n', 'q.answers_related_question_target_id = n.nid');
  $query
    ->fields('q', array(
    'entity_id',
  ))
    ->fields('n', array(
    'nid',
  ))
    ->isNull('nid');
  $result = $query
    ->execute();
  foreach ($result as $record) {
    $orphan_nids[] = $record->entity_id;
  }
  $query = db_select('node', 'n');
  $query
    ->leftJoin('field_data_answers_related_question', 'q', 'n.nid = q.entity_id');
  $query
    ->fields('q', array(
    'entity_id',
  ))
    ->fields('n', array(
    'nid',
  ))
    ->condition('type', 'answers_answer')
    ->isNull('entity_id');
  $result = $query
    ->execute();
  foreach ($result as $record) {
    $orphan_nids[] = $record->nid;
  }
  return array_unique($orphan_nids);
}