Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
appconfiguration.php
1<?php
3
4use \Bitrix\Landing\File;
5use \Bitrix\Landing\Rights;
6use \Bitrix\Landing\Landing;
7use \Bitrix\Landing\Site;
8use \Bitrix\Landing\Restriction;
9use \Bitrix\Landing\Site\Type;
10use \Bitrix\Main\Application;
11use \Bitrix\Main\Event;
12use \Bitrix\Main\Localization\Loc;
13use \Bitrix\Rest\Configuration;
14
15Loc::loadMessages(__FILE__);
16
22{
26 const SYSTEM_BLOCK_REST_PENDING = 'system.rest.pending';
27 const SYSTEM_COMPONENT_REST_PENDING = 'bitrix:landing.rest.pending';
28
32 const PREFIX_CODE = 'landing_';
33
38 protected static $processing = false;
39
44 private static $entityList = [
45 'LANDING' => 500
46 ];
47
52 private static $accessManifest = [
53 'total',
54 'landing_page',
55 'landing_store',
56 'landing_knowledge'
57 ];
58
63 private static $contextSiteId = null;
64
69 public static function inProcess(): bool
70 {
71 return self::$processing;
72 }
73
78 public static function getEntityList(): array
79 {
80 return static::$entityList;
81 }
82
88 public static function getManifestList(Event $event): array
89 {
90 $request = Application::getInstance()->getContext()->getRequest();
91 $additional = $request->get('additional');
92 $siteId = $additional['siteId'] ?? null;
93 $manifestList = [];
94
95 foreach (self::$accessManifest as $code)
96 {
97 if ($code == 'total')
98 {
99 continue;
100 }
101 $langCode = mb_strtoupper(mb_substr($code, mb_strlen(self::PREFIX_CODE)));
102 $manifestList[] = [
103 'CODE' => $code,
104 'VERSION' => 1,
105 'ACTIVE' => 'Y',
106 'PLACEMENT' => [$code],
107 'USES' => [
108 $code,
109 'app',
110 ],
111 'DISABLE_CLEAR_FULL' => 'Y',
112 'DISABLE_NEED_START_BTN' => 'Y',
113 'COLOR' => '#ff799c',
114 'ICON' => '/bitrix/images/landing/landing_transfer.svg',
115 'TITLE' => Loc::getMessage('LANDING_TRANSFER_GROUP_TITLE_' . $langCode),
116 //'DESCRIPTION' => Loc::getMessage('LANDING_TRANSFER_GROUP_DESC'),
117 'EXPORT_TITLE_PAGE' => Loc::getMessage('LANDING_TRANSFER_EXPORT_ACTION_TITLE_BLOCK_' . $langCode),
118 'EXPORT_TITLE_BLOCK' => Loc::getMessage('LANDING_TRANSFER_EXPORT_ACTION_TITLE_BLOCK_' . $langCode),
119 'EXPORT_ACTION_DESCRIPTION' => Loc::getMessage('LANDING_TRANSFER_EXPORT_ACTION_DESCRIPTION_' . $langCode),
120 'IMPORT_TITLE_PAGE' => Loc::getMessage('LANDING_TRANSFER_IMPORT_ACTION_TITLE_BLOCK_' . $langCode),
121 'IMPORT_TITLE_BLOCK' => Loc::getMessage('LANDING_TRANSFER_IMPORT_ACTION_TITLE_BLOCK_' . $langCode),
122 'IMPORT_DESCRIPTION_UPLOAD' => Loc::getMessage('LANDING_TRANSFER_IMPORT_DESCRIPTION_UPLOAD_' . $langCode),
123 'IMPORT_DESCRIPTION_START' => ' ',
124 'IMPORT_INSTALL_FINISH_TEXT' => '',
125 'IMPORT_TITLE_PAGE_CREATE' => Loc::getMessage('LANDING_TRANSFER_IMPORT_ACTION_TITLE_BLOCK_CREATE_' . $langCode),
126 'REST_IMPORT_AVAILABLE' => 'Y',
127 'SITE_ID' => $siteId,
128 'ACCESS' => [
129 'MODULE_ID' => 'landing',
130 'CALLBACK' => [
131 '\Bitrix\Landing\Transfer\AppConfiguration',
132 'onCheckAccess'
133 ]
134 ]
135 ];
136 }
137
138 return $manifestList;
139 }
140
147 public static function onCheckAccess(string $type, array $manifest): array
148 {
149 if ($manifest['CODE'] ?? null)
150 {
151 $siteType = substr($manifest['CODE'], strlen(AppConfiguration::PREFIX_CODE));
152 \Bitrix\Landing\Site\Type::setScope($siteType);
153 }
154
155 $siteId = $manifest['SITE_ID'] ?? 0;
156 if ($type === 'export')
157 {
158 $access = in_array(Rights::ACCESS_TYPES['read'], Rights::getOperationsForSite($siteId));
159 if ($access)
160 {
161 $access = !Rights::hasAdditionalRight(Rights::ADDITIONAL_RIGHTS['unexportable'], null, false, true);
162 }
163 }
164 else
165 {
167 && in_array(Rights::ACCESS_TYPES['edit'], Rights::getOperationsForSite($siteId));
168 }
169 return [
170 'result' => $access
171 ];
172 }
173
179 public static function onInitManifest(Event $event): ?array
180 {
181 $code = $event->getParameter('CODE');
182 $type = $event->getParameter('TYPE');
183
184 self::$processing = true;
185
186 if (in_array($code, static::$accessManifest))
187 {
188 if ($type == 'EXPORT')
189 {
190 return Export\Site::getInitManifest($event);
191 }
192 else if ($type == 'IMPORT')
193 {
194 return Import\Site::getInitManifest($event);
195 }
196 }
197
198 return null;
199 }
200
206 public static function onEventExportController(Event $event): ?array
207 {
208 $code = $event->getParameter('CODE');
209 $manifest = $event->getParameter('MANIFEST');
210 $access = array_intersect($manifest['USES'], static::$accessManifest);
211
212 self::$processing = true;
213
214 if (Restriction\Manager::isAllowed('limit_sites_transfer'))
215 {
216 if ($access && isset(static::$entityList[$code]))
217 {
218 return Export\Site::nextStep($event);
219 }
220 }
221
222 return null;
223 }
224
230 public static function onEventImportController(Event $event): ?array
231 {
232 self::$contextSiteId = $event->getParameter('RATIO')['LANDING']['SITE_ID'] ?? null;
233 $code = $event->getParameter('CODE');
234
235 self::$processing = true;
236
238
239 if (isset(static::$entityList[$code]))
240 {
241 return Import\Site::nextStep($event);
242 }
243
245
246 return null;
247 }
248
254 public static function onFinish(Event $event): array
255 {
256 $type = $event->getParameter('TYPE');
257 $code = $event->getParameter('MANIFEST_CODE');
258
259 if (in_array($code, static::$accessManifest))
260 {
261 if ($type == 'EXPORT')
262 {
263 // rename file to download
264 $context = $event->getParameter('CONTEXT_USER');
265 $setting = new Configuration\Setting($context);
266 $manifest = $setting->get(Configuration\Setting::SETTING_MANIFEST);
267 if (!empty($manifest['SITE_ID']))
268 {
269 Type::setScope($manifest['SITE_TYPE']);
270 $res = Site::getList([
271 'select' => [
272 'TITLE'
273 ],
274 'filter' => [
275 'ID' => $manifest['SITE_ID']
276 ]
277 ]);
278 if ($row = $res->fetch())
279 {
280 $structure = new Configuration\Structure($context);
281 $structure->setArchiveName(\CUtil::translit(
282 trim($row['TITLE']),
283 'ru',
284 [
285 'replace_space' => '_',
286 'replace_other' => '_'
287 ]
288 ));
289 }
290 }
291 return Export\Site::onFinish($event);
292 }
293 else if ($type == 'IMPORT')
294 {
295 return Import\Site::onFinish($event);
296 }
297 }
298
299 self::$processing = false;
300
301 return [];
302 }
303
309 public static function saveFile(array $file): ?int
310 {
311 $checkExternal = self::$contextSiteId && ($file['ID'] ?? null);
312 $externalId = $checkExternal ? self::$contextSiteId . '_' . $file['ID'] : null;
313
314 if ($externalId)
315 {
316 $res = \CFile::getList([], ['EXTERNAL_ID' => $externalId]);
317 if ($row = $res->fetch())
318 {
319 return $row['ID'];
320 }
321 }
322
323 $fileId = null;
324 $fileData = \CFile::makeFileArray(
325 $file['PATH']
326 );
327
328 if ($fileData)
329 {
330 $fileData['name'] = $file['NAME'];
331 $fileData['external_id'] = $externalId;
332
333 if (\CFile::checkImageFile($fileData, 0, 0, 0, array('IMAGE')) === null)
334 {
335 $fileData['MODULE_ID'] = 'landing';
336 $fileData['name'] = File::sanitizeFileName($fileData['name']);
337 $fileId = (int)\CFile::saveFile($fileData, $fileData['MODULE_ID']);
338 if (!$fileId)
339 {
340 $fileId = null;
341 }
342 }
343 }
344
345 return $fileId;
346 }
347}
static sanitizeFileName(string $fileName)
Definition file.php:54
static disableCheckUniqueAddress()
Definition landing.php:514
static enableCheckUniqueAddress()
Definition landing.php:523
static getOperationsForSite($siteId)
Definition rights.php:518
static hasAdditionalRight($code, $type=null, bool $checkExtraRights=false, bool $strict=false)
Definition rights.php:1025
static onCheckAccess(string $type, array $manifest)
getParameter($key)
Definition event.php:80
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29