You are here

function taxonomy_orphanage_roundup in Taxonomy Orphanage 7

Looks for orphaned taxonomy references and removes them.

Parameters

bool $progressive: TRUE if this is a progressive batch, else FALSE.

int $limit: Number of records per batch set to process. Useful for cron jobs.

bool $display_finished: TRUE to send finished messages to the log, else FALSE.

3 calls to taxonomy_orphanage_roundup()
drush_taxonomy_orphanage_roundup in ./taxonomy_orphanage.drush.inc
Drush callback that passes off the roundup to our internal function.
taxonomy_orphanage_admin_roundup in ./taxonomy_orphanage.admin.inc
Admin callback to remove orphaned term references.
taxonomy_orphanage_cron in ./taxonomy_orphanage.module
Implements hook_cron().

File

./taxonomy_orphanage.module, line 47
Module file.

Code

function taxonomy_orphanage_roundup($progressive = TRUE, $limit = -1, $display_finished = TRUE) {
  $batch = array(
    'title' => t('Collecting orphans'),
    'file' => drupal_get_path('module', 'taxonomy_orphanage') . '/taxonomy_orphanage.batch.inc',
    'finished' => 'taxonomy_orphanage_batch_finished',
    'operations' => array(),
  );

  // Find all the taxonomy reference fields.
  $fields = field_info_fields();
  foreach ($fields as $field) {
    if ($field['type'] != 'taxonomy_term_reference') {
      continue;
    }
    $batch['operations'][] = array(
      'taxonomy_orphanage_batch_roundup',
      array(
        $field,
        $limit,
        $display_finished,
      ),
    );
  }
  batch_set($batch);
  if (!$progressive) {
    $batch =& batch_get();
    $batch['progressive'] = FALSE;
  }
  batch_process();
}