You are here

function _answers_orphan_nids in Answers 7.3

Same name and namespace in other branches
  1. 7.4 includes/answers.helpers.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.field_utils.inc, line 47
Field utility functions for the 'Answers' module.

Code

function _answers_orphan_nids() {
  $orphan_nids = array();
  $query = db_select('field_data_field_answer_question', 'q');
  $query
    ->leftJoin('node', 'n', 'q.field_answer_question_nid = 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_field_answer_question', 'q', 'n.nid = q.entity_id');
  $query
    ->fields('q', array(
    'entity_id',
  ))
    ->fields('n', array(
    'nid',
    'type',
  ))
    ->condition('type', 'answer')
    ->isNull('entity_id');
  $result = $query
    ->execute();
  foreach ($result as $record) {
    $orphan_nids[] = $record->nid;
  }
  return array_unique($orphan_nids);
}