Example #1
0
 public function postTransactionCommit(Doctrine_Event $event)
 {
     Event::run('telephony.postTransactionCommit', Bluebox_Record::getBaseTransactionObject());
     // A transaction just ended - we write out any configuration information set by the telephony driver now.
     // THIS IS WHERE WE UPDATE VIA THE SWITCH-SPECIFIC DRIVER!
     if (Kohana::config('telephony.driver') && Kohana::config('telephony.diskoutput')) {
         if (!empty(self::$changedModels)) {
             Kohana::log('debug', 'Telephony -> Creating config from saved models in memory.');
             foreach (self::$changedModels as $change) {
                 Kohana::log('debug', 'Telephony -> Preparing to generate configurartion from ' . $change['action'] . ' of ' . get_class($change['record']) . ' ' . implode(', ', $change['identifier']) . ' with OID ' . $change['record']->getOid() . ' on base model ' . get_class($change['baseModel']));
             }
             // Figure out what models were touched and either set or delete based on the action that was done to them
             // NOTE: Make sure this occurs in the same order it occurred via Doctrine's transaction
             foreach (self::$changedModels as $change) {
                 if (!empty($change['baseModel'])) {
                     Bluebox_Record::setBaseSaveObject($change['baseModel']);
                 } else {
                     Kohana::log('alert', 'Telephony -> The record ' . get_class($change['record']) . ' did not have the baseModel set!');
                     continue;
                 }
                 switch ($change['action']) {
                     case 'update':
                     case 'insert':
                         Telephony::set($change['record'], $change['identifier']);
                         break;
                     case 'delete':
                         Telephony::delete($change['record'], $change['identifier']);
                         break;
                     default:
                         Kohana::log('debug', 'An unknown action (' . $change['action'] . ') was performed on model ' . get_class($change['record']));
                         break;
                 }
             }
             self::$changedModels = array();
             Telephony::save();
             // If configured, tell the telephony engine to reload it's configs immediately
             Telephony::commit();
             // Clear the telephony info in memory. This is important, because if someone is doing a bulk add or otherwise, things get crazy
             Telephony::reset();
         }
     }
 }
Example #2
0
 /**
  * This function preforms the default restful delete,
  * extend this class and redefine if you need different behavoir.
  *
  * @return void
  */
 public function restfulDelete()
 {
     $errorOccured = FALSE;
     kohana::log('debug', 'Attempting a RESTful delete');
     if (empty($_POST['id'])) {
         message::set('No rows where specified for delete', array('type' => 'alert'));
         return;
     }
     $delIDs = explode(',', $_POST['id']);
     $conn = Doctrine_Manager::connection();
     foreach ($delIDs as $delID) {
         $row = Doctrine::getTable($this->baseModel)->find($delID);
         if (!$row) {
             $errorOccured = TRUE;
             message::set('Unable to locate row ' . strtolower($this->baseModel) . ' id ' . $delID . '!');
             continue;
         }
         try {
             Bluebox_Record::setBaseSaveObject($row);
             $conn->beginTransaction();
             plugins::delete($row);
             $row->delete();
             $conn->commit();
             plugins::delete($row, array('custom' => Router::$controller . '.success', 'coreAction' => FALSE, 'core' => FALSE));
             Bluebox_Record::setBaseSaveObject(NULL);
         } catch (Exception $e) {
             $errorOccured = TRUE;
             message::set('Unable to delete ' . strtolower($this->baseModel) . ' id ' . $delID . '! ' . $e->getMessage());
         }
     }
     if (empty($errorOccured)) {
         message::set('Selected record(s) deleted.', array('type' => 'success'));
     }
 }