You are here

function entityqueue_queue_delete in Entityqueue 7

Deletes a queue.

Parameters

EntityQueue|string $queue: An EntityQueue object or the machine name of a queue.

1 string reference to 'entityqueue_queue_delete'
entityqueue_schema in ./entityqueue.install
Implements hook_schema().

File

./entityqueue.module, line 273
Allows users to collect entities in arbitrarily ordered lists.

Code

function entityqueue_queue_delete($queue) {

  // If the argument is not an EntityQueue object, load it now.
  if (!is_object($queue)) {
    $queue = entityqueue_queue_load($queue);
  }
  entityqueue_get_handler($queue)
    ->preDelete();

  // Delete this queue's subqueues first.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'entityqueue_subqueue')
    ->entityCondition('bundle', $queue->name);
  $result = $query
    ->execute();
  if (!empty($result['entityqueue_subqueue'])) {
    if ($queue->export_type == EXPORT_IN_CODE + EXPORT_IN_DATABASE) {
      db_delete('entityqueue_queue')
        ->condition('name', $queue->name)
        ->execute();
      return;
    }
    entity_delete_multiple('entityqueue_subqueue', array_keys($result['entityqueue_subqueue']));
  }

  // Delete the entity reference field instance that was created for this queue.
  $field_name = _entityqueue_get_target_field_name($queue->target_type);
  $entityreference_field = field_read_instance('entityqueue_subqueue', $field_name, $queue->name);
  field_delete_instance($entityreference_field, FALSE);
  field_attach_delete_bundle('entityqueue_subqueue', $queue->name);

  // And finally we can delete the queue.
  db_delete('entityqueue_queue')
    ->condition('name', $queue->name)
    ->execute();
  entityqueue_get_handler($queue)
    ->postDelete();
}