Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
App.php
1<?php
2
4
5use \Bitrix\Main;
6use \Bitrix\Rest;
7use \Bitrix\UI\Avatar\Mask;
8use \Bitrix\UI\Avatar;
9
10class App
11{
12 private const REST_STATISTIC_MASK_ENTITY_NAME = 'MASK';
13
14 public static function onRestAppDelete($app)
15 {
16 if (isset($app['APP_ID'])
17 && $app['APP_ID']
18 && ($app = Rest\AppTable::getByClientId($app['APP_ID']))
19 )
20 {
21 try
22 {
23 (new Mask\Owner\RestApp($app['ID']))->delete();
24 if (!Avatar\Model\ItemTable::getList(['filter' => ['=OWNER_TYPE' => Mask\Owner\RestApp::class], 'limit' => 1])->fetch())
25 {
26 \CAgent::RemoveAgent(__CLASS__ . '::sendRestStatistic();', 'ui');
27 }
28 }
29 catch (\Throwable $e)
30 {
31 // in case we do not
32 }
33 }
34 }
35
36 public static function OnRestAppInstall()
37 {
38 \CAgent::addAgent(
39 __CLASS__.'::sendRestStatistic();',
40 'ui',
41 'N',
42 86400,
43 "",
44 "Y",
45 "",
46 100,
47 false,
48 false
49 );
50 }
51
52 public static function sendRestStatistic()
53 {
54 if (
55 Main\Loader::includeModule('rest')
56 && is_callable(['\Bitrix\Rest\UsageStatTable', 'logUserInterface'])
57 )
58 {
59 $dbRes = Avatar\Model\ItemToFileTable::getList([
60 'select' => ['APP_ID' => 'ITEM.OWNER_ID', 'CNT'],
61 'filter' => [
62 '=ITEM.OWNER_TYPE' => Mask\Owner\RestApp::class,
63 ],
64 'runtime' => [new Main\Entity\ExpressionField('CNT', 'COUNT(%s)', 'ID')],
65 'group' => ['ITEM.OWNER_ID'],
66 ]);
67 while ($res = $dbRes->fetch())
68 {
69 Rest\UsageStatTable::logUserInterface(
70 $res['APP_ID'],
71 static::REST_STATISTIC_MASK_ENTITY_NAME,
72 $res['CNT']
73 );
74 }
75 Rest\UsageStatTable::finalize();
76 }
77
78 return __CLASS__ . '::' . __FUNCTION__ . '();';
79 }
80}
static onRestAppDelete($app)
Definition App.php:14