- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/preset/provider.php
- Класс: BitrixRestPresetProvider
- Вызов: Provider::getWebHook
static function getWebHook($scopeList = [], $id = 0, $title = '')
{
$password = [];
$id = intVal($id);
$scopeList = is_array($scopeList) ? $scopeList : [];
if ($id !== 0)
{
$passData = PasswordTable::getList(
[
'filter' => [
'=ID' => $id,
],
'select' => [
'PASSWORD',
'USER_ID',
'TITLE',
'ID'
],
'limit' => 1
]
);
if ($passwordData = $passData->fetch())
{
$scopeListOld = [];
$scopeIdList = [];
$permData = PermissionTable::getList(
[
'filter' => [
'=PASSWORD_ID' => $passwordData['ID']
]
]
);
while ($scopeItem = $permData->fetch())
{
$scopeIdList[$scopeItem['PERM']] = $scopeItem['ID'];
$scopeListOld[] = $scopeItem['PERM'];
}
$resultList = array_diff($scopeList, $scopeListOld);
foreach ($resultList as $scope)
{
PermissionTable::add(
[
'PASSWORD_ID' => $passwordData['ID'],
'PERM' => $scope,
]
);
}
$resultList = array_diff($scopeListOld, $scopeList);
foreach ($resultList as $scope)
{
if (isset($scopeIdList[$scope]))
{
PermissionTable::delete($scopeIdList[$scope]);
}
}
if ($title !== '' && $passwordData['TITLE'] !== $title)
{
PasswordTable::update(
$passwordData['ID'],
[
'TITLE' => $title
]
);
}
$password = $passwordData;
}
}
if (empty($password))
{
$userId = $GLOBALS['USER']->GetID();
$passwordCreat = PasswordTable::createPassword(
$userId,
$scopeList,
$title,
true
);
if ($passwordCreat !== false)
{
$password = $passwordCreat;
}
}
if (!empty($password['PASSWORD']))
{
$password['URL'] = CRestUtil::getWebhookEndpoint($password['PASSWORD'], $password['USER_ID']);
}
return $password;
}