Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sectionstructureupdate.php
1
<?php
2
3
namespace
Bitrix\Calendar\Update
;
4
5
use \Bitrix\Main\Localization\Loc;
6
use \Bitrix\Main\Update\Stepper;
7
use \Bitrix\Main\Config\Option;
8
use \Bitrix\Main\Loader;
9
10
11
final
class
SectionStructureUpdate
extends
Stepper
12
{
13
const
PORTION
= 40;
14
15
protected
static
$moduleId
=
"calendar"
;
16
17
public
static
function
className
()
18
{
19
return
get_called_class();
20
}
21
22
public
function
execute
(array &$result)
23
{
24
global $DB;
25
$BATCH_SIZE = 1000;
26
if
(
27
Loader::includeModule(
"calendar"
)
28
&& Option::get(
'calendar'
,
'sectionStructureConverted'
,
'N'
) ===
'Y'
29
)
30
{
31
return
self::FINISH_EXECUTION
;
32
}
33
34
$status = $this->loadCurrentStatus();
35
36
$newStatus = array(
37
'count'
=> $status[
'count'
],
38
'steps'
=> $status[
'steps'
],
39
'lastEventId'
=>
null
,
40
'finished'
=> $status[
'finished'
]
41
);
42
43
if
(!$status[
'finished'
])
44
{
45
$r = $DB->Query(
'SELECT ID FROM b_calendar_event
46
WHERE SECTION_ID IS NULL ORDER BY ID ASC limit 1;'
,
47
false
,
48
"File: "
.__FILE__.
"<br>Line: "
.__LINE__
49
);
50
51
if
($entry = $r->Fetch())
52
{
53
$newStatus[
'lastEventId'
] = $entry[
'ID'
];
54
if
((
int
)$status[
'lastEventId'
] === (
int
)$newStatus[
'lastEventId'
])
55
{
56
Option::set(
'calendar'
,
'sectionStructureConverted'
,
'Y'
);
57
Option::delete(
'calendar'
, [
'name'
=>
'sectionStructureUpdaterStatus'
]);
58
59
return
self::FINISH_EXECUTION
;
60
}
61
62
$DB->Query(
'UPDATE b_calendar_event CE
63
INNER JOIN b_calendar_event_sect CES ON CE.ID = CES.EVENT_ID
64
SET CE.SECTION_ID = CES.SECT_ID
65
WHERE CE.SECTION_ID is null and CE.ID < '
.((
int
)$entry[
'ID'
] + $BATCH_SIZE),
66
false
,
67
"File: "
.__FILE__.
"<br>Line: "
.__LINE__
68
);
69
70
$newStatus[
'steps'
] = $newStatus[
'count'
] - $this->getTotalCount();
71
72
Option::set(
'calendar'
,
'sectionStructureUpdaterStatus'
, serialize($newStatus));
73
$result = array(
74
'title'
=>
Loc::getMessage
(
"CALENDAR_UPDATE_STRUCTURE_TITLE"
),
75
'count'
=> $newStatus[
'count'
],
76
'steps'
=> $newStatus[
'steps'
]
77
);
78
return
self::CONTINUE_EXECUTION
;
79
}
80
81
Option::set(
'calendar'
,
'sectionStructureUpdaterStatus'
, serialize($newStatus));
82
}
83
84
Option::set(
'calendar'
,
'sectionStructureConverted'
,
'Y'
);
85
Option::delete(
'calendar'
, [
'name'
=>
'sectionStructureUpdaterStatus'
]);
86
87
return
self::FINISH_EXECUTION
;
88
}
89
90
private
function
loadCurrentStatus()
91
{
92
$status = Option::get(
'calendar'
,
'sectionStructureUpdaterStatus'
,
'default'
);
93
$status = ($status !==
'default'
? @unserialize($status, [
'allowed_classes'
=>
false
]) : []);
94
$status = (is_array($status) ? $status : []);
95
96
if
(empty($status))
97
{
98
$status = [
99
'count'
=> $this->getTotalCount(),
100
'steps'
=> 0,
101
'lastEventId'
=> 0,
102
'finished'
=> false
103
];
104
}
105
106
return
$status;
107
}
108
109
private
function
getTotalCount()
110
{
111
global $DB;
112
$count = 0;
113
$res = $DB->Query(
'SELECT count(*) AS c FROM b_calendar_event WHERE SECTION_ID is null'
,
false
,
"File: "
.__FILE__.
"<br>Line: "
.__LINE__);
114
if
($res = $res->Fetch())
115
{
116
$count = intval($res[
'c'
]);
117
}
118
119
return
$count;
120
}
121
}
Bitrix\Calendar\Update\SectionStructureUpdate
Definition
sectionstructureupdate.php:12
Bitrix\Calendar\Update\SectionStructureUpdate\execute
execute(array &$result)
Definition
sectionstructureupdate.php:22
Bitrix\Calendar\Update\SectionStructureUpdate\$moduleId
static $moduleId
Definition
sectionstructureupdate.php:15
Bitrix\Calendar\Update\SectionStructureUpdate\className
static className()
Definition
sectionstructureupdate.php:17
Bitrix\Calendar\Update\SectionStructureUpdate\PORTION
const PORTION
Definition
sectionstructureupdate.php:13
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
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
sectionstructureupdate.php
Создано системой
1.10.0