Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
locationduplicatecleaner.php
1<?php
2
6
8{
9 protected static $moduleId = "calendar";
10
11 public static function className()
12 {
13 return get_called_class();
14 }
15
21 public function execute(array &$result): bool
22 {
23 if (!Loader::includeModule("calendar"))
24 {
26 }
27
28 if ($dataToClean = $this->getEntryDataToClean())
29 {
30 $this->cleanDuplicates((int)$dataToClean['PARENT_ID'], (int)$dataToClean['LASTID']);
32 }
33
35 }
36
40 private function getEntryDataToClean(): ?array
41 {
42 global $DB;
43 $strSql = "select
44 MAX(ID) as LASTID,
45 PARENT_ID,
46 COUNT(1) as CNT
47 from
48 b_calendar_event
49 where
50 CAL_TYPE='location'
51 group by
52 PARENT_ID
53 having CNT > 1
54 order by ID desc
55 limit 1";
56
57 $res = $DB->Query($strSql);
58 if ($entry = $res->Fetch())
59 {
60 return $entry;
61 }
62 return null;
63 }
64
70 private function cleanDuplicates(int $parentId, int $entryToLeave): void
71 {
72 global $DB;
73 $strSql = "delete from
74 b_calendar_event
75 where
76 CAL_TYPE = 'location'
77 and PARENT_ID = '".$parentId."'
78 and ID != '".$entryToLeave."'
79 limit 1000";
80
81 $DB->Query($strSql);
82 }
83}