Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agent.php
1<?php
2
4
6
7class Agent
8{
9 private static bool $processing = false;
10
11 public static function execute()
12 {
13 if (self::$processing)
14 {
15 return self::getAgentName();
16 }
17
18 self::$processing = true;
19
20 $queue = Queue::getInstance();
21 $rows = $queue->get(CounterController::STEP_LIMIT);
22
23 if (empty($rows))
24 {
25 self::$processing = false;
26 return '';
27 }
28
29 foreach ($rows as $row)
30 {
31 $userId = (int)$row['USER_ID'];
32 (new CounterController($userId))->processQueueItem($row);
33 }
34
35 $queue->done();
36
37 self::$processing = false;
38
39 return self::getAgentName();
40 }
41
42 public function __construct()
43 {
44
45 }
46
47 public function addAgent(): void
48 {
49 $res = \CAgent::GetList(
50 ['ID' => 'DESC'],
51 [
52 '=NAME' => self::getAgentName()
53 ]
54 );
55 if ($res->Fetch())
56 {
57 return;
58 }
59
60 \CAgent::AddAgent(
61 self::getAgentName(),
62 'socialnetwork',
63 'N',
64 0,
65 '',
66 'Y',
67 ''
68 );
69 }
70
71 public function removeAgent(): void
72 {
73 \CAgent::RemoveAgent(self::getAgentName(), 'socialnetwork');
74 }
75
76 private static function getAgentName(): string
77 {
78 return static::class . "::execute();";
79 }
80}