You are here

function entityqueue_queue_save in Entityqueue 7

Saves a queue.

Parameters

EntityQueue $queue: EntityQueue object with queue properties. See entityqueue_queue_create().

bool $rebuild_menu: Boolean indicating whether the the database tables used by various menu functions should be rebuilt. Setting this to FALSE is useful if multiple queues are being created programmatically. Defaults to TRUE.

Return value

int|bool If the queue insert or update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

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

File

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

Code

function entityqueue_queue_save(EntityQueue $queue, $rebuild_menu = TRUE) {

  // Make sure all keys are populated.
  $queue = entityqueue_queue_create($queue);
  if ($queue->export_type & EXPORT_IN_DATABASE) {

    // Existing queue.
    $write_record_keys = array(
      'name',
    );
    $queue->is_new = FALSE;
  }
  else {

    // New queue.
    $write_record_keys = array();
    $queue->export_type = EXPORT_IN_DATABASE;
    $queue->is_new = TRUE;
  }
  entityqueue_get_handler($queue)
    ->preSave();
  $transaction = db_transaction();
  try {
    $return = drupal_write_record('entityqueue_queue', $queue, $write_record_keys);
    _entityqueue_queue_ensure_instance($queue);
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception('Entityqueue', $e);
    throw $e;
  }
  if ($queue->is_new) {
    entityqueue_get_handler($queue)
      ->insert();
  }
  else {
    entityqueue_get_handler($queue)
      ->update();
  }
  if ($rebuild_menu) {
    menu_rebuild();
  }
  return $return;
}