Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
calendarlogevent.php
1<?php
2
4
10use Exception;
11
13{
14 private const TYPE_CALENDAR = 'calendar';
15 private const LIMIT = 1000;
16
17 protected static $moduleId = 'socialnetwork';
18
19 private int $lastId = 0;
20 private LogCollection $items;
21
22 public function execute(array &$option): bool
23 {
24 $this
25 ->setLastId($option['lastId'] ?? 0)
26 ->setItems();
27
28 if ($this->items->isEmpty())
29 {
31 }
32
33 $this
34 ->moveItems()
35 ->updateLastId()
36 ->setOptions($option);
37
39 }
40
41
42 private function setLastId(int $id): static
43 {
44 $this->lastId = $id;
45 return $this;
46 }
47
48 private function setItems(): static
49 {
50 $this->items = new LogCollection();
51 try
52 {
53 $query = LogTable::query();
54 $query
55 ->setSelect(['ID'])
56 ->where('EVENT_ID', static::TYPE_CALENDAR)
57 ->whereNull('MODULE_ID')
58 ->where(new Condition('ID', '>', $this->lastId))
59 ->setOrder(['ID' => 'asc'])
60 ->setLimit(static::LIMIT);
61
62 $this->items = $query->exec()->fetchCollection();
63 }
64 catch (Exception $exception)
65 {
66 $this->writeToLog($exception);
67 return $this;
68 }
69
70 return $this;
71 }
72
73 private function moveItems(): static
74 {
75 $table = LogTable::getTableName();
76 $ids = implode(',', $this->items->getIdList());
77 $moduleId = static::TYPE_CALENDAR;
78 $sql = "update {$table} set MODULE_ID = '{$moduleId}' where id in ({$ids})";
79 try
80 {
81 Application::getConnection()->query($sql);
82 }
83 catch (Exception $exception)
84 {
85 $this->writeToLog($exception);
86 }
87
88 return $this;
89 }
90
91 private function updateLastId(): static
92 {
93 $this->lastId = max($this->items->getIdList());
94 return $this;
95 }
96
97 private function setOptions(array &$options): static
98 {
99 $options['lastId'] = $this->lastId;
100 return $this;
101 }
102}
static getConnection($name="")
writeToLog(\Exception $exception)
Definition stepper.php:406