You are here

function taxonomy_tools_publisher_publish in Taxonomy Tools 8

Same name and namespace in other branches
  1. 7 taxonomy_tools_publisher/taxonomy_tools_publisher.module \taxonomy_tools_publisher_publish()

Publishes scheduled taxonomy terms.

1 call to taxonomy_tools_publisher_publish()
taxonomy_tools_publisher_cron in taxonomy_tools_publisher/taxonomy_tools_publisher.module
Implements hook_cron().

File

taxonomy_tools_publisher/taxonomy_tools_publisher.module, line 183
Drupal hooks and functions to manipulate taxonomy terms.

Code

function taxonomy_tools_publisher_publish() {

  // Collect term ID's of terms which publish on value is before now.
  $config = array_filter(variable_get('taxonomy_tools_publisher_config', array()));
  $query = db_select('field_data_field_taxonomy_term_publish_on', 'foo');
  $query
    ->addField('foo', 'entity_id', 'tid');
  $query
    ->addField('foo', 'field_taxonomy_term_publish_on_value', 'publish_on');
  $query
    ->leftJoin('taxonomy_term_data', 'bar', 'foo.entity_id = bar.tid');
  $query
    ->join('taxonomy_vocabulary', 'baz', 'baz.vid = bar.vid');
  $query
    ->condition('baz.machine_name', $config, 'IN');
  $result = $query
    ->execute()
    ->fetchAll();
  $tids = array();
  foreach ($result as $data) {
    if ($data->publish_on < REQUEST_TIME) {
      $tids[] = $data->tid;
    }
  }
  foreach ($tids as $tid) {

    // Publish the term.
    taxonomy_tools_publisher_publish_term($tid);
  }
}