You are here

function lingotek_cleanup_entity_references in Lingotek Translation 7.7

Re-links translation parent entities to translation child entities

1 string reference to 'lingotek_cleanup_entity_references'
lingotek_admin_cleanup_form_submit in ./lingotek.admin.inc
Attempt to execute each of the cleanup functions selected by the requester.

File

./lingotek.util.inc, line 1299
Utility functions.

Code

function lingotek_cleanup_entity_references($entity_reference_date) {
  LingotekLog::trace(__METHOD__);
  $timestamp = time();
  if ($entity_reference_date === '30_days') {
    $time_boundary = strtotime('-30 days', $timestamp);
  }
  elseif ($entity_reference_date === '90_days') {
    $time_boundary = strtotime('-90 days', $timestamp);
  }
  elseif ($entity_reference_date === '1_day') {
    $time_boundary = strtotime('-1 days', $timestamp);
  }
  else {
    $time_boundary = 0;
  }
  $entity_reference_fields = db_select('field_config', 'fc')
    ->fields('fc', array(
    'id',
  ))
    ->condition('type', 'entityreference');
  $entity_reference_bundles = db_select('field_config_instance', 'fci')
    ->fields('fci', array(
    'bundle',
  ))
    ->condition('field_id', $entity_reference_fields, 'IN')
    ->distinct();
  $entities = db_select('node', 'n')
    ->fields('n')
    ->condition('tnid', 0, '<>')
    ->condition('type', $entity_reference_bundles, 'IN')
    ->condition('changed', $time_boundary, '>=')
    ->execute()
    ->fetchAll();
  $operations = lingotek_get_entity_reference_updater_batch_elements($entities);
  $batch = array(
    'title' => t('Lingotek Entity Reference Updater'),
    'operations' => $operations,
    'finished' => 'lingotek_entity_reference_updater_batch_finished',
    'file' => 'lingotek.batch.inc',
  );
  $redirect = current_path();
  batch_set($batch);
  batch_process($redirect);
}