/** * Indicate we support FreeSWITCH with this SIP Device and provide code to save SIP device specific settings */ public static function set($obj) { // Get the asterisk driver $driver = Telephony::getDriver(); // Get the asterisk manager $ami = $driver->ami; // Sanity check, ensure we have a connected manager if (!$ami->connected()) { return false; } // Get the base of this configure object $base = Bluebox_Record::getBaseTransactionObject(); // Get the username of this sip device $username = $base->Sip->username; // Get the domain of this user or set it to default if ($base->User->Location->domain == '') { $domain = 'default'; } else { $domain = $base->User->Location->domain; } /* TODO: This is temporary to push everything into the default context */ $domain = 'default'; if ($base instanceof Conference) { /* TODO: I expect this will have to be handled in the dialplan */ } elseif ($base instanceof Device) { $ami->queueConfigUpdate('sip.conf', 'Append', $username, 'callerid', '"' . $obj['internal_name'] . '" <' . $obj['internal_number'] . '>'); $ami->queueConfigUpdate('sip.conf', 'Append', $username, 'setvar', 'external_cid = "' . $obj['external_name'] . '" <' . $obj['external_number'] . '>'); } }
public function save($inSave = false) { if (substr($this->fxp_spool_dir, -1) != '/') { $this->fxp_spool_dir += '/'; } if ($inSave == false && $this->fxp_default == false) { $defaultlist = Doctrine_Query::create()->from('FaxProfile')->where('fxp_default = ?', true)->andWhere('fxp_id != ?', $this->fxp_id)->execute(); if (count($defaultlist) < 1) { $this->fxp_default = true; } } parent::save(); if ($inSave == false && $this->fxp_default == true) { $defaultlist = Doctrine_Query::create()->from('FaxProfile')->where('fxp_default = ?', true)->andWhere('fxp_id != ?', $this->fxp_id)->execute(); foreach ($defaultlist as $defobj) { $defobj->fxp_default = false; $defobj->save(true); } } if ($inSave == false && $this->fxp_send == true) { $detectlist = Doctrine_Query::create()->from('FaxProfile')->where('fxp_send = ?', true)->andWhere('fxp_id != ?', $this->fxp_id)->execute(); foreach ($detectlist as $detprof) { $detprof->fxp_send = false; $detprof->save(true); } } }
public function get($fieldName, $load = true) { if (strtolower($fieldName) == 'name') { return parent::get('dbn_name', $load); } else { return parent::get($fieldName, $load); } }
/** * Prior to a record being deleted from the DB we delete it's config on disk. Note that the item's information is still in memory * while the delete transaction and records are running. * @param Doctrine_Event $event */ public function postDelete(Doctrine_Event $event) { $invoker =& $event->getInvoker(); $baseModel = Bluebox_Record::getBaseTransactionObject(); $identifier = $invoker->identifier(); // We do this because we can't set configs until we have saved all related models that may have an auto increment! TelephonyListener::$changedModels[$invoker->getOid()] = array('action' => 'delete', 'record' => &$invoker, 'baseModel' => $baseModel, 'identifier' => $identifier); }
public function get($fieldName, $load = true) { switch (strtolower($fieldName)) { case 'name': return parent::get('fxd_name', $load); break; case 'id': return parent::get('fxd_id', $load); break; default: return parent::get($fieldName, $load); break; } }
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(); } } }
/** * Indicate we support FreeSWITCH */ public static function set($obj) { // Get the asterisk driver $driver = Telephony::getDriver(); // Get the asterisk manager $ami = $driver->ami; // Sanity check, ensure we have a connected manager if (!$ami->connected()) { return false; } // Get the base of this configure object $base = Bluebox_Record::getBaseTransactionObject(); // Get a unqiue name for this trunk $trunkName = 'trunk_' . $base->trunk_id; // If this is a sip trunk it belongs in sip.conf if (isset($base['plugins']['sip']['username'])) { $ami->queueConfigUpdate('sip.conf', 'NewCat', $trunkName); $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'type', 'friend'); $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'host', $obj->server); $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'canreinvite', 'no'); $ami->queueConfigUpdate('sip.conf', 'Append', $trunkName, 'context', 'default'); } }
/** * * @param Bluebox_Record $baseSaveObject * @return boolean TRUE if successfully set, otherwise false. Should only be false if you pass an invalid object in */ public static function setBaseSaveObject($baseSaveObject) { if (!$baseSaveObject instanceof Bluebox_Record and !empty($baseSaveObject)) { Kohana::log('alert', 'Attempt to set base object to invalid value!'); return FALSE; } self::$baseSaveObject = $baseSaveObject; return TRUE; }
public static function delete($obj, $identifier) { $success = FALSE; // Sanity check if (!is_object($obj)) { return FALSE; } // Initialize telephony driver / check if already initialized $driver = self::getDriver(); $driverName = get_class($driver); // If no driver is set, just return w/ FALSE. if (!$driver) { return FALSE; } // Support for column aggregation automagically as well as special handling of dialplan/numbers if (get_parent_class($obj) != 'Doctrine_Record' and get_parent_class($obj) != 'Bluebox_Record') { $objectName = get_parent_class($obj); Kohana::log('debug', 'Telephony -> Deleting information from ' . $objectName . ' (' . get_class($obj) . ') ' . implode(', ', $identifier) . ' with OID ' . $obj->getOid()); } else { $objectName = get_class($obj); Kohana::log('debug', 'Telephony -> Deleting information from ' . $objectName . ' ' . implode(', ', $identifier) . ' with OID ' . $obj->getOid()); } $modelDriverName = self::$driverName . '_' . $objectName . '_Driver'; // Does the [Doctrine] object we were just passed contain a relevant driver? If so, call it's driver method if (class_exists($modelDriverName, TRUE)) { self::$identifier = $identifier; // Get base model to give to the set() routine, for reference $base = Bluebox_Record::getBaseTransactionObject(); try { kohana::log('debug', 'Telephony -> EVAL ' . $modelDriverName . '::delete($obj, $base);'); $success = eval('return ' . $modelDriverName . '::delete($obj, $base);'); } catch (Exception $e) { Kohana::log('error', 'Telephony -> Eval exception: "' . $objectName . '". ' . $e->getMessage()); } if (!empty($obj['plugins'])) { foreach ($obj['plugins'] as $name => $data) { $pluginName = ucfirst($name); $pluginDriverName = $driverName . '_' . $pluginName . '_Driver'; if (!class_exists($pluginDriverName)) { Kohana::log('debug', 'Telephony -> No telephony plugin driver for delete of "' . $objectName . '" records...'); continue; } Kohana::log('debug', 'Telephony -> Deleting information from plugin ' . $pluginName . ' on ' . $objectName . ' ' . $identifier); try { kohana::log('debug', 'Telephony -> EVAL ' . $pluginDriverName . '::delete($obj, $base);'); $success = eval('return ' . $pluginDriverName . '::delete($obj, $base);'); } catch (Exception $e) { Kohana::log('error', 'Telephony -> Eval exception: "' . $pluginName . '". ' . $e->getMessage()); } } } self::$identifier = NULL; } else { Kohana::log('debug', 'Telephony -> No telephony module driver for delete of "' . $objectName . '" records...'); } Kohana::log('debug', 'Telephony -> Done deleting information from model "' . $objectName . '".'); return $success; }
public static function delete($obj) { $doc = Telephony::getDriver()->doc; $base = Bluebox_Record::getBaseTransactionObject(); if (empty($base->trunk_id)) { return FALSE; } $patterns = simplerouter::getOutboundPattern('emergency', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('international', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('local', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } $patterns = simplerouter::getOutboundPattern('short', 'asterisk'); foreach ($patterns as $pattern => $exten) { $doc->deleteDialplanExtension($obj->context_id, $pattern); } }
/** * 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')); } }