Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
initapp.php
1<?php
3
4use \Bitrix\Landing\Internals\LandingTable;
5use \Bitrix\Landing\Internals\BlockTable;
6use \Bitrix\Landing\Demos;
7use \Bitrix\Landing\Repo;
8use \Bitrix\Main\Update\Stepper;
9use \Bitrix\Main\Config\Option;
10
16class InitApp extends Stepper
17{
18 protected static $moduleId = 'landing';
19
25 public function execute(array &$result)
26 {
27 $lastId = Option::get('landing', 'update_landing_app', 0);
28 $blocksRepo = Repo::getRepository();
29 \Bitrix\Landing\Rights::setGlobalOff();
30
31 $finished = true;
32 if (!isset($result['steps']))
33 {
34 $result['steps'] = 0;
35 }
36
37 // get all app in demo tables
38 $demos = [];
39 $res = Demos::getList([
40 'select' => [
41 'APP_CODE', 'XML_ID'
42 ]
43 ]);
44 while ($row = $res->fetch())
45 {
46 $demos[$row['APP_CODE'] . '.' . $row['XML_ID']] = $row;
47 }
48 unset($res, $row);
49
50 // calculate count of records, which we need
52 'select' => [
53 'CNT'
54 ],
55 'runtime' => [
56 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
57 ]
58 ]);
59 if ($row = $res->fetch())
60 {
61 $result['count'] = $row['CNT'];
62 }
63 unset($res, $row);
64
65
66 // one group for update
67 $res = LandingTable::getList(array(
68 'select' => array(
69 'ID', 'TPL_CODE'
70 ),
71 'filter' => array(
72 '>ID' => $lastId
73 ),
74 'order' => array(
75 'ID' => 'ASC'
76 ),
77 'limit' => 1
78 ));
79 while ($row = $res->fetch())
80 {
81 $lastId = $row['ID'];
82 $result['steps']++;
83 $appCode = isset($demos[$row['TPL_CODE']]['APP_CODE'])
84 ? $demos[$row['TPL_CODE']]['APP_CODE']
85 : null;
86
87 // mark with this app all available blocks in current page
88 $resBlock = BlockTable::getList([
89 'select' => [
90 'ID', 'CODE'
91 ],
92 'filter' => [
93 'LID' => $row['ID'],
94 '=DELETED' => 'N'
95 ]
96 ]);
97 while ($rowBlock = $resBlock->fetch())
98 {
99 $appCodeBlock = isset($blocksRepo[$rowBlock['CODE']])
100 ? $blocksRepo[$rowBlock['CODE']]['app_code']
101 : null;
102 if ($appCodeBlock != $appCode)
103 {
104 $appCodeBlock = null;
105 }
106 $resTmp = BlockTable::update($rowBlock['ID'], [
107 'INITIATOR_APP_CODE' => $appCodeBlock
108 ]);
109 $resTmp->isSuccess();
110 }
111 unset($resBlock, $rowBlock);
112
113 // mark the page with this app
114 $resTmp = LandingTable::update($row['ID'], [
115 'INITIATOR_APP_CODE' => $appCode
116 ]);
117 $resTmp->isSuccess();
118
119 $finished = false;
120 }
121 unset($res, $row);
122
123 \Bitrix\Landing\Rights::setGlobalOn();
124
125 // set next step or finish work
126 if (!$finished)
127 {
128 Option::set('landing', 'update_landing_app', $lastId);
129 return true;
130 }
131 else
132 {
133 Option::delete('landing', array('name' => 'update_landing_app'));
134 return false;
135 }
136 }
137}
static getList(array $params=array())
Definition landing.php:602
static getRepository()
Definition repo.php:70