From 97fbd4a5fb76c718041985a4b9888740787d96bb Mon Sep 17 00:00:00 2001 From: Martin Cording Date: Tue, 6 Mar 2012 14:40:48 +0100 Subject: [PATCH] Fix problems with DB handling causing break of an installation. --- ting.controllers.inc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ting.controllers.inc b/ting.controllers.inc index e286375..7df63da 100644 --- a/ting.controllers.inc +++ b/ting.controllers.inc @@ -106,14 +106,24 @@ class TingObjectController extends DrupalDefaultEntityController { $ting_object = array( 'ding_entity_id' => $ding_entity_id, ); - drupal_write_record('ting_object', $ting_object); - drupal_write_record('ting_object_revision', $ting_object); - db_update('ting_object') - ->fields(array('vid' => $ting_object['vid'])) - ->condition('tid', $ting_object['tid']) - ->execute(); - // Add new id to the loaded set. - $new_ids[] = $ting_object['tid']; + // Start of transaction: the following queries are one atomic operation. + $transaction = db_transaction(); + try { + drupal_write_record('ting_object', $ting_object); + drupal_write_record('ting_object_revision', $ting_object); + db_update('ting_object') + ->fields(array('vid' => $ting_object['vid'])) + ->condition('tid', $ting_object['tid']) + ->execute(); + unset($transaction); + // Add new id to the loaded set. + $new_ids[] = $ting_object['tid']; + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception('ting_object', $e); + } + // End of transaction, Drupal automatically calls commit (__destruct method). } } if ($new_ids) {