1

I'm having trouble figuring out why the following code isn't working in Drupal 7. _queue_processor is a cron queue processor function:

function _queue_processor($uid) {

    $transaction = db_transaction();

    watchdog('debug', 'transaction created'); // This will not be called.

    try {
      user_delete($uid);
    }
    catch (Exception $e) {
      // A problem occurred. Rollback transaction.
      $transaction->rollback();
      throw $e;
    }
    // Rollback intentionally.
    if (variable_get('some_var', FALSE)) {
      $transaction->rollback();
    }
}

The code never makes it past the $transaction = db_transaction(); line. However, if I remove the transaction and try/catch, user_delete() is called just fine, and the transaction that user_delete_multiple() creates within itself works as well.

Is there something wrong with putting user_delete() within a transaction? I know it already uses one, but I need to be able to run the deletion and then conditionally rollback afterwards, and I'd rather not do this by throwing an exception in an implementation of hook_user_delete() to force rollback.

I am using MariaDB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.