You are here

function drafty_queue_delete_revision in Drafty 7

Callback function to delete a single temporary-draft revision.

Could be called either from a batch job or from a cron-queue.

2 string references to 'drafty_queue_delete_revision'
Drafty::restorePublishedRevisions in ./drafty.module
Publish revisions previously set with setRevisionToBePublished().
drafty_cron_queue_info in ./drafty.module
Implements hook_cron_queue_info().

File

./drafty.module, line 118
Hook implementations and API functions for the Drafty module.

Code

function drafty_queue_delete_revision($drafty_queue_item, &$context = NULL) {
  try {

    // Trigger hook_drafty_predelete_revision(). Allow other modules to
    // preserve information on the old revision before it's deleted.
    module_invoke_all('drafty_predelete_revision', $drafty_queue_item['entity_type'], $drafty_queue_item['entity_id'], $drafty_queue_item['revision_id'], $drafty_queue_item['replaced_by']);

    // Delete the old revision.
    entity_revision_delete($drafty_queue_item['entity_type'], $drafty_queue_item['revision_id']);

    // Document the successful batch operation for the batch-finished function
    // to use.
    if (!empty($context) && isset($context['results'])) {
      $context['results'][] = $drafty_queue_item;
    }
  } catch (Exception $ex) {

    // Log the problem.
    $message = 'An error occurred while deleting temporary revision: @args. Exception details: @error';
    $args = array(
      '@args' => print_r($drafty_queue_item, TRUE),
      '@error' => print_r($ex, TRUE),
    );
    watchdog('drafty', $message, $args, WATCHDOG_ERROR);
    throw $ex;

    // Batch API will pass $success = FALSE.
  }
}