/** * 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(); } } }