Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
locationduplicatecleaner.php
1
<?php
2
3
namespace
Bitrix\Calendar\Update
;
4
use
Bitrix\Main\Loader
;
5
use
Bitrix\Main\Update\Stepper
;
6
7
class
LocationDuplicateCleaner
extends
Stepper
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
{
25
return
self::FINISH_EXECUTION
;
26
}
27
28
if
($dataToClean = $this->getEntryDataToClean())
29
{
30
$this->cleanDuplicates((
int
)$dataToClean[
'PARENT_ID'
], (
int
)$dataToClean[
'LASTID'
]);
31
return
self::CONTINUE_EXECUTION
;
32
}
33
34
return
self::FINISH_EXECUTION
;
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
}
Bitrix\Calendar\Update\LocationDuplicateCleaner
Definition
locationduplicatecleaner.php:8
Bitrix\Calendar\Update\LocationDuplicateCleaner\execute
execute(array &$result)
Definition
locationduplicatecleaner.php:21
Bitrix\Calendar\Update\LocationDuplicateCleaner\$moduleId
static $moduleId
Definition
locationduplicatecleaner.php:9
Bitrix\Calendar\Update\LocationDuplicateCleaner\className
static className()
Definition
locationduplicatecleaner.php:11
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Update\Stepper
Definition
stepper.php:27
Bitrix\Main\Update\Stepper\FINISH_EXECUTION
const FINISH_EXECUTION
Definition
stepper.php:34
Bitrix\Main\Update\Stepper\CONTINUE_EXECUTION
const CONTINUE_EXECUTION
Definition
stepper.php:33
Bitrix\Calendar\Update
Definition
converterobjectcolor.php:4
modules
calendar
lib
update
locationduplicatecleaner.php
Создано системой
1.10.0