public static function sipDelete($arParams, $nav, $server) { if (!CVoxImplantMain::CheckAccess()) { throw new \Bitrix\Rest\AccessException(); } $arParams = array_change_key_case($arParams, CASE_UPPER); $dbResCnt = \Bitrix\Voximplant\SipTable::getList(array('filter' => array('CONFIG_ID' => $arParams["CONFIG_ID"], 'APP_ID' => $server->getAppId()), 'select' => array("CNT" => new Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')))); $arResCnt = $dbResCnt->fetch(); if (!$arResCnt || $arResCnt["CNT"] <= 0) { throw new Bitrix\Rest\RestException("Specified CONFIG_ID is not found", Bitrix\Rest\RestException::ERROR_NOT_FOUND, CRestServer::STATUS_WRONG_REQUEST); } $viSip = new CVoxImplantSip(); $result = $viSip->Delete($arParams['CONFIG_ID']); if (!$result || $viSip->GetError()->error) { throw new Bitrix\Rest\RestException($viSip->GetError()->msg, $viSip->GetError()->code, CRestServer::STATUS_WRONG_REQUEST); } return 1; }
public function Get($configId, $params = array()) { $configId = intval($configId); if ($configId <= 0) { $this->error = new CVoxImplantError(__METHOD__, 'CONFIG_ID_NULL', GetMessage('VI_SIP_CONFIG_ID_NULL')); return false; } if (!is_array($params)) { $params = array(); } $result = VI\SipTable::getList(array('select' => $params['WITH_TITLE'] ? array('*', 'TITLE') : array('*'), 'filter' => array('=CONFIG_ID' => $configId))); $row = $result->fetch(); if (!$row) { $this->error = new CVoxImplantError(__METHOD__, 'CONFIG_NOT_FOUND', GetMessage('VI_SIP_CONFIG_NOT_FOUND')); return false; } if ($row['TYPE'] == self::TYPE_CLOUD) { if (intval($row['REG_ID']) <= 0) { $result = $this->CreateSipRegistration($row['ID'], $row['CONFIG_ID'], $row['SERVER'], $row['LOGIN'], $row['PASSWORD']); if ($result) { $row['REG_ID'] = $result->reg_id; } $row['REG_STATUS'] = $result ? self::REG_STATUS_IN_PROGRESS : self::REG_STATUS_ERROR; } else { $row['REG_STATUS'] = self::REG_STATUS_WAIT; } unset($row['INCOMING_SERVER']); unset($row['INCOMING_LOGIN']); unset($row['INCOMING_PASSWORD']); } else { if (empty($row['INCOMING_SERVER']) && empty($row['INCOMING_LOGIN']) && empty($row['INCOMING_PASSWORD'])) { $ViHttp = new CVoxImplantHttp(); $result = $ViHttp->GetSipParams($configId); if ($result) { $row['INCOMING_SERVER'] = str_replace(array('incoming.', '.voximplant.com'), array('ip.', '.bitrixphone.com'), $result->server); $row['INCOMING_LOGIN'] = $result->user_name; $row['INCOMING_PASSWORD'] = $result->user_password; $this->Update($configId, array('TYPE' => self::TYPE_OFFICE, 'INCOMING_SERVER' => $row['INCOMING_SERVER'], 'INCOMING_LOGIN' => $row['INCOMING_LOGIN'], 'INCOMING_PASSWORD' => $row['INCOMING_PASSWORD'])); } } else { $row['INCOMING_SERVER'] = str_replace(array('incoming.', '.voximplant.com'), array('ip.', '.bitrixphone.com'), $row['INCOMING_SERVER']); } unset($row['REG_ID']); } unset($row['ID']); return $row; }