Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
queueremoveeventhandler.php
1<?php
2
4
10
12{
13
15 private $errorCollection;
16
17 private $code;
18
19 private $clientId;
20
21 private function __construct()
22 {
23 $this->errorCollection = new ErrorCollection();
24 }
25
26 private static function createHandler() : self
27 {
28 return new self;
29 }
30
31 private function result() : EventResult
32 {
33 return new EventResult($this->getEventStatus(), ['ERROR_COLLECTION' => $this->errors()]);
34 }
35
36 private function getEventStatus() : int
37 {
38 return $this->hasErrors() ? EventResult::ERROR : EventResult::SUCCESS;
39 }
40
41 private function errors() : ErrorCollection
42 {
43 return $this->errorCollection;
44 }
45
46 private function hasErrors() : bool
47 {
48 return $this->errorCollection->count() > 0;
49 }
50
51 private function setClientId($clientId) : self
52 {
53 if(!$this->hasErrors())
54 {
55 if (!isset($clientId))
56 {
57 $this->errorCollection->setError(new Main\Error("client is null"));
58 }
59 $this->clientId = $clientId;
60
61 }
62 return $this;
63 }
64
65 private function setEngineCode($code) : self
66 {
67 if(!$this->hasErrors())
68 {
69 if(!is_string($code))
70 {
71 $this->errorCollection->setError(new Main\Error('Engine code is not string'));
72 }
73 $this->code = $code;
74 }
75 return $this;
76 }
77 private function run() : self
78 {
79 if(!$this->hasErrors())
80 {
81 $row = Internals\ServiceQueueTable::getRow([
82 'select' => ['ID'],
83 'filter' => [
84 'CLIENT_ID' => $this->clientId,
85 '=SERVICE_TYPE' => $this->code,
86 ]
87 ]);
88 if ($row)
89 {
90 $result = Internals\ServiceQueueTable::delete($row['ID']);
91 if(!$result->isSuccess())
92 {
93 $this->errors()->add($result->getErrors());
94 }
95 }
96 }
97 return $this;
98 }
99
107 public static function handleEvent($clientId,$engineCode)
108 {
109 return
110 static::createHandler()
111 ->setClientId($clientId)
112 ->setEngineCode($engineCode)
113 ->run();
114 }
115}