14 return get_called_class();
22 public function execute(array &$result): bool
24 if (!Loader::includeModule(
"calendar"))
31 $dataToClean = $this->getDuplicatedChildEntryList();
32 if (count($dataToClean))
34 foreach ($dataToClean as $entryToClean)
36 $this->cleanDuplicates(
37 (
int)$entryToClean[
'PARENT_ID'],
38 (
int)$entryToClean[
'OWNER_ID'],
39 (
int)$entryToClean[
'FIRSTID'] === (
int)$entryToClean[
'PARENT_ID']
40 ? (
int)$entryToClean[
'FIRSTID']
41 : (int)$entryToClean[
'LASTID']
43 $totalCount += $entryToClean[
'CNT'];
44 if ($totalCount >= self::MAX_TOTAL_COUUNT)
53 if ($this->getBogusLocationEntry())
55 $this->clearBogusLocationEntries();
59 if ($this->getLocationEntriesWithEmptyParent())
61 $this->clearLocationEntriesWithEmptyParent();
71 private function getDuplicatedChildEntryList(): ?array
84 and PARENT_ID is not null
92 $res = $DB->Query($strSql);
93 while ($entry = $res->Fetch())
103 private function getBogusLocationEntry(): ?array
107 select ID from b_calendar_event
110 and CAL_TYPE = 'location'
115 $res = $DB->Query($strSql);
116 if ($entry = $res->Fetch())
126 private function clearBogusLocationEntries(): void
130 delete from b_calendar_event
133 and CAL_TYPE = 'location'
145 private function cleanDuplicates(
int $parentId,
int $ownerId,
int $entryToLeave): void
154 and PARENT_ID = '".$parentId.
"'
155 and OWNER_ID = '".$ownerId.
"'
156 and ID != '".$entryToLeave.
"'
164 private function getLocationEntriesWithEmptyParent(): ?array
169 ce.ID, ce.PARENT_ID, p.ID as PID
170 from b_calendar_event ce
171 left join b_calendar_event p
174 ce.CAL_TYPE='location'
175 and (p.ID is null or p.DELETED='Y')
179 $res = $DB->Query($strSql);
180 if ($entry = $res->Fetch())
190 private function clearLocationEntriesWithEmptyParent(): void
195 from b_calendar_event as ce
196 left join b_calendar_event as p
199 ce.CAL_TYPE='location'
200 and (p.ID is null or p.DELETED='Y')