/** * When a number is saved, we need to update any contexts that the number lives in */ public static function set($obj) { // Go create the number related stuff for each context it is assigned to if ($obj->NumberContext) { foreach ($obj->NumberContext as $context) { // Add any "global" hooks that come before the processing of any numbers (this is per context) dialplan::start('context_' . $context['context_id']); FreeSwitch_NumberContext_Driver::set($context); // Add any "global" hooks that come after the processing of any numbers (this is per context) dialplan::end('context_' . $context['context_id']); } } }
/** * When a number is saved, we need to update any contexts that the number lives in */ public static function set($obj) { // Go create the number related stuff for each context it is assigned to if ($obj->NumberContext) { $assignedContexts = array(); foreach ($obj->NumberContext as $context) { // Add any "global" hooks that come before the processing of any numbers (this is per context) dialplan::start('context_' . $context['context_id'], $context->Number); FreeSwitch_NumberContext_Driver::set($context); // Add any "global" hooks that come after the processing of any numbers (this is per context) dialplan::end('context_' . $context['context_id'], $context->Number); $assignedContexts[] = $context['context_id']; } // Changed the operation of setting the pools that cause existings // pool records to be used, where we used to unset (delete) them, so // we need to ensure we dont orphan numbers when changing contexts $contexts = Doctrine::getTable('Context')->findAll(); $xml = Telephony::getDriver()->xml; $xp = new DOMXPath($xml); foreach ($contexts as $context) { if (!in_array($context['context_id'], $assignedContexts)) { $search = sprintf('//document/section[@name="dialplan"]/context[@name="context_%s"]/extension[@name="%s"]', $context['context_id'], 'main_number_' . $obj['number_id']); if ($xp->query($search)->length) { kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') FROM CONTEXT ' . $context['context_id']); $xml->setXmlRoot($search); $xml->deleteNode(); } } } if ($obj['type'] == Number::TYPE_EXTERNAL and !empty($obj->NumberContext[0]['context_id'])) { kohana::log('debug', 'FreeSWITCH -> ADDING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') TO NUMBER ROUTE'); $xml = Freeswitch::setSection('number_route', $obj['number_id']); // Dialplans are a bit different - we don't want to keep anything that is currently in an extension, in the event it's totally changed $xml->deleteChildren(); $num = str_replace(array('*', '+'), array('\\*', '\\+'), $obj['number']); // Check what number they dialed $condition = '/condition[@field="destination_number"]{@expression="^' . $num . '$"}'; $xml->update($condition . '/action[@application="set"][@data="vm-operator-extension=' . $obj['number'] . '"]'); $xml->update($condition . '/action[@application="set"][@data="force_transfer_context=context_' . $obj->NumberContext[0]['context_id'] . '"]'); $xml->update($condition . '/action[@application="transfer"]{@data="' . $obj['number'] . ' XML context_' . $obj->NumberContext[0]['context_id'] . '"}'); } else { kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') FROM NUMBER ROUTE'); Freeswitch::setSection('number_route', $obj['number_id'])->deleteNode(); } } }
public static function set($obj) { $numberInUse = FALSE; if ($obj->NumberContext) { foreach ($obj->NumberContext as $context) { // Add any "global" hooks that come before the processing of any numbers (this is per context) dialplan::start('context_' . $context['context_id']); $numberInUse = $numberInUse | Asterisk_NumberContext_Driver::set($context); // Add any "global" hooks that come after the processing of any numbers (this is per context) dialplan::end('context_' . $context['context_id']); } } if (!$numberInUse) { // Remove the destination itself, fully. Despite this being called create, an empty context gets deleted automagically at save time kohana::log('debug', 'Number id ' . $obj['number_id'] . ' is no longer in use in any context, deleteing!'); $doc = Telephony::getDriver()->doc; $doc->deleteContext('extensions.conf', 'number_' . $obj['number_id']); } }
/** * Creates a context that you can route calls to initially. Takes care of adding the global event hooks/conditions * at the top of the context and then does a GoTo to the context's destinations list * @param integer $contextId */ public function createRoutableContext($contextId) { // TODO: ADD SKIP FUNCTIONALITY HERE. Don't recreate this on the same run if we've already created this context, that's dumb. $this->createContext('extensions.conf', 'context_' . $contextId, NULL, array('replace' => TRUE)); // Add global event hooks dialplan::start('context_' . $contextId); // TODO: Context gets clobbered during dialplan start/end, so let's set it again //self:: $this->add('GoSub(extensions_' . $contextId . ',${EXTEN},1)'); // Put end of dialplan stuff dialplan::end('context_' . $contextId); // TODO: Context gets clobbered again. Set it up again. $this->add('Hangup()'); }