1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sectionstructureupdate.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Update;
4
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Main\Update\Stepper;
7use \Bitrix\Main\Config\Option;
8use \Bitrix\Main\Loader;
9
10
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 );
48
49 if ($entry = $r->Fetch())
50 {
51 $newStatus['lastEventId'] = $entry['ID'];
52 if ((int)$status['lastEventId'] === (int)$newStatus['lastEventId'])
53 {
54 Option::set('calendar', 'sectionStructureConverted', 'Y');
55 Option::delete('calendar', ['name' => 'sectionStructureUpdaterStatus']);
56
57 return self::FINISH_EXECUTION;
58 }
59
60 $DB->Query('UPDATE b_calendar_event CE
61 INNER JOIN b_calendar_event_sect CES ON CE.ID = CES.EVENT_ID
62 SET CE.SECTION_ID = CES.SECT_ID
63 WHERE CE.SECTION_ID is null and CE.ID < '.((int)$entry['ID'] + $BATCH_SIZE)
64 );
65
66 $newStatus['steps'] = $newStatus['count'] - $this->getTotalCount();
67
68 Option::set('calendar', 'sectionStructureUpdaterStatus', serialize($newStatus));
69 $result = array(
70 'title' => Loc::getMessage("CALENDAR_UPDATE_STRUCTURE_TITLE"),
71 'count' => $newStatus['count'],
72 'steps' => $newStatus['steps']
73 );
74 return self::CONTINUE_EXECUTION;
75 }
76
77 Option::set('calendar', 'sectionStructureUpdaterStatus', serialize($newStatus));
78 }
79
80 Option::set('calendar', 'sectionStructureConverted', 'Y');
81 Option::delete('calendar', ['name' => 'sectionStructureUpdaterStatus']);
82
83 return self::FINISH_EXECUTION;
84 }
85
86 private function loadCurrentStatus()
87 {
88 $status = Option::get('calendar', 'sectionStructureUpdaterStatus', 'default');
89 $status = ($status !== 'default' ? @unserialize($status, ['allowed_classes' => false]) : []);
90 $status = (is_array($status) ? $status : []);
91
92 if (empty($status))
93 {
94 $status = [
95 'count' => $this->getTotalCount(),
96 'steps' => 0,
97 'lastEventId' => 0,
98 'finished' => false
99 ];
100 }
101
102 return $status;
103 }
104
105 private function getTotalCount()
106 {
107 global $DB;
108 $count = 0;
109 $res = $DB->Query('SELECT count(*) AS c FROM b_calendar_event WHERE SECTION_ID is null');
110 if($res = $res->Fetch())
111 {
112 $count = intval($res['c']);
113 }
114
115 return $count;
116 }
117}
$count
Определения admin_tab.php:4
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
$status
Определения session.php:10
return false
Определения prolog_main_admin.php:185