Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionstructureupdate.php
1<?php
2
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 {
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
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 );
79 }
80
81 Option::set('calendar', 'sectionStructureUpdaterStatus', serialize($newStatus));
82 }
83
84 Option::set('calendar', 'sectionStructureConverted', 'Y');
85 Option::delete('calendar', ['name' => 'sectionStructureUpdaterStatus']);
86
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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29