16 private static $skipMode =
false;
17 private static $tmpAppList = [];
18 private static $tmpUsesLangAppList = [];
19 private static $tmpApList = [];
20 private static $tmpApPermissionList = [];
28 static::$skipMode =
true;
38 static::$skipMode =
false;
49 if (!static::$skipMode)
55 $scope = explode(
',', $fields[
'SCOPE']);
56 $result = IntegrationTable::add(
58 'ELEMENT_CODE' => Element::DEFAULT_APPLICATION,
59 'TITLE' => $fields[
'APP_NAME'],
60 'APP_ID' => $fields[
'APP_ID'],
62 'APPLICATION_ONLY_API' =>
'Y',
63 'APPLICATION_NEEDED' =>
'Y',
64 'QUERY_NEEDED' =>
'N',
65 'OUTGOING_NEEDED' =>
'N',
66 'WIDGET_NEEDED' =>
'N',
71 if ($result->isSuccess())
73 $integrationID = $result->getId();
74 static::$tmpAppList[$id] = $integrationID;
87 if (!static::$skipMode)
91 if ($id > 0 && !empty(static::$tmpAppList[$fields[
'APP_ID']]) && !isset(static::$tmpUsesLangAppList[$fields[
'APP_ID']]))
93 static::$tmpUsesLangAppList[$fields[
'APP_ID']] = $fields[
'LANGUAGE_ID'];
96 $integrationId = static::$tmpAppList[$fields[
'APP_ID']];
97 IntegrationTable::update(
100 'APPLICATION_ONLY_API' =>
'N',
104 catch (\Exception $e)
118 if (!static::$skipMode)
122 if ($id > 0 && !$fields[
'APP_ID'] > 0 && !$fields[
'INTEGRATION_ID'] > 0)
124 $result = IntegrationTable::add(
126 'ELEMENT_CODE' => Element::DEFAULT_OUT_WEBHOOK,
127 'TITLE' => $fields[
'TITLE'],
128 'USER_ID' => $fields[
'USER_ID'],
129 'APPLICATION_TOKEN' => $fields[
'APPLICATION_TOKEN'],
130 'OUTGOING_EVENTS' => [
131 $fields[
'EVENT_NAME']
133 'OUTGOING_HANDLER_URL' => $fields[
'EVENT_HANDLER'],
134 'APPLICATION_NEEDED' =>
'N',
135 'QUERY_NEEDED' =>
'N',
136 'OUTGOING_NEEDED' =>
'Y',
137 'WIDGET_NEEDED' =>
'N',
142 if ($result->isSuccess())
147 'INTEGRATION_ID' => $result->getId()
160 public static function onAfterAddAp(
Event $event)
162 if (!static::$skipMode)
169 $result = IntegrationTable::add(
171 'ELEMENT_CODE' => Element::DEFAULT_IN_WEBHOOK,
172 'TITLE' => $fields[
'TITLE'],
173 'PASSWORD_ID' => $id,
174 'USER_ID' => $fields[
'USER_ID'],
176 'APPLICATION_NEEDED' =>
'N',
177 'QUERY_NEEDED' =>
'Y',
178 'OUTGOING_NEEDED' =>
'N',
179 'WIDGET_NEEDED' =>
'N',
184 if ($result->isSuccess())
186 $integrationID = $result->getId();
187 static::$tmpApList[$id] = $integrationID;
198 public static function onAfterAddApPermission(Event $event)
200 if (!static::$skipMode)
202 $id = intVal($event->getParameter(
'id'));
206 $fields = $event->getParameter(
'fields');
207 if (!isset(static::$tmpApList[$fields[
'PASSWORD_ID']]) ||
208 !isset(static::$tmpApPermissionList[$fields[
'PASSWORD_ID']]))
210 $res = IntegrationTable::getList(
213 'PASSWORD_ID' => $fields[
'PASSWORD_ID']
222 if ($integration = $res->fetch())
224 static::$tmpApList[$integration[
'PASSWORD_ID']] = $integration[
'ID'];
225 static::$tmpApPermissionList[$integration[
'PASSWORD_ID']] = $integration[
'SCOPE'];
230 array_key_exists($fields[
'PASSWORD_ID'], static::$tmpApPermissionList)
231 && !in_array($fields[
'PERM'], static::$tmpApPermissionList[$fields[
'PASSWORD_ID']])
234 static::$tmpApPermissionList[$fields[
'PASSWORD_ID']][] = $fields[
'PERM'];
238 $integrationId = static::$tmpApList[$fields[
'PASSWORD_ID']];
239 $scopeList = static::$tmpApPermissionList[$fields[
'PASSWORD_ID']];
240 IntegrationTable::update(
243 'SCOPE' => $scopeList
247 catch (\Exception $e)