Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
foldernew.php
1<?php
3
10
11//\Bitrix\Main\Update\Stepper::bindClass('Bitrix\Landing\Update\Landing\FolderNew', 'landing', 0);
12
13class FolderNew extends Stepper
14{
15 protected static $moduleId = 'landing';
16
23 public function execute(array &$result, ?int $siteId = null): bool
24 {
26 $finished = true;
27
28 $globalFilter = [
29 '=FOLDER' => 'Y',
30 //'=DELETED' => ['Y', 'N'],
31 //'=SITE.DELETED' => ['Y', 'N']
32 ];
33
34 if ($siteId)
35 {
36 $globalFilter['SITE_ID'] = $siteId;
37 }
38
39 // gets common quantity
41 'select' => [
43 'CNT', 'COUNT(*)'
44 )
45 ],
46 'filter' => $globalFilter
47 ]);
48 if ($row = $res->fetch())
49 {
50 $result['count'] = $row['CNT'];
51 }
52
53 // gets group for update
55 'select' => [
56 'ID', 'TITLE', 'CODE', 'ACTIVE', 'DELETED', 'SITE_ID'
57 ],
58 'filter' => $globalFilter,
59 'order' => [
60 'ID' => 'ASC'
61 ]
62 ]);
63 while ($page = $res->fetch())
64 {
65 $folderId = null;
66 // create new folder and update folder to page
67 $resFolder = Folder::add([
68 'SITE_ID' => $page['SITE_ID'],
69 'TITLE' => $page['TITLE'],
70 'CODE' => $page['CODE'],
71 'ACTIVE' => $page['ACTIVE'],
72 'DELETED' => $page['DELETED']
73 ]);
74 if ($resFolder->isSuccess())
75 {
76 $folderId = $resFolder->getId();
77 }
78 else
79 {
80 foreach ($resFolder->getErrors() as $error)
81 {
82 if ($error->getCode() === 'FOLDER_IS_NOT_UNIQUE')
83 {
84 $resFolder = Folder::getList([
85 'select' => [
86 'ID'
87 ],
88 'filter' => [
89 'SITE_ID' => $page['SITE_ID'],
90 'PARENT_ID' => null,
91 '=CODE' => $page['CODE']
92 ]
93 ]);
94 if ($rowFolder = $resFolder->fetch())
95 {
96 $folderId = $rowFolder['ID'];
97 break;
98 }
99 }
100 }
101 }
102
103 if ($folderId)
104 {
105 Folder::update($folderId, [
106 'INDEX_ID' => $page['ID']
107 ]);
108 LandingTable::update($page['ID'], [
109 'FOLDER' => 'N',
110 'FOLDER_ID' => $folderId
111 ]);
112 Debug::log('FU:LandingTable::update', var_export([
113 'ID' => $page['ID'],
114 'FOLDER' => 'N',
115 'FOLDER_ID' => $folderId
116 ], true));
117 // fetch old folder's pages and move it to the new folder
118 $resPage = LandingTable::getList([
119 'select' => [
120 'ID', 'FOLDER_ID'
121 ],
122 'filter' => [
123 'FOLDER_ID' => $page['ID'],
124 //'=DELETED' => ['Y', 'N'],
125 //'=SITE.DELETED' => ['Y', 'N']
126 ]
127 ]);
128 while ($rowPage = $resPage->fetch())
129 {
130 LandingTable::update($rowPage['ID'], [
131 'FOLDER_ID' => $folderId
132 ]);
133 Debug::log('FU:LandingTable::update', var_export([
134 'ID' => $rowPage['ID'],
135 'FOLDER_ID_OLD' => $rowPage['FOLDER_ID'],
136 'FOLDER_ID' => $folderId
137 ], true));
138 }
139 }
140
141 $finished = false;
142 }
143
144 if ($finished && !$siteId)
145 {
146 Manager::setOption('landing_new', 'Y');
147 }
148
150
151 return !$finished;
152 }
153}
static log($itemId, $itemDesc, $typeId='LANDING_LOG')
Definition debug.php:24
static getList(array $params=array())
Definition landing.php:602
static setOption($code, $value)
Definition manager.php:171
static setGlobalOff()
Definition rights.php:105
execute(array &$result, ?int $siteId=null)
Definition foldernew.php:23