1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
appconfiguration.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\Configuration;
4
5use Bitrix\Main\Localization\Loc;
6use Bitrix\Rest\AppLogTable;
7use Bitrix\Rest\AppTable;
8use Bitrix\Rest\EventTable;
9use Bitrix\Rest\Event\Sender;
10use Bitrix\Main\Event;
11use Bitrix\Rest\Marketplace\Application;
12
14{
15 public const REST_APPLICATION = 'REST_APPLICATION';
16 private static $entityList = [
17 self::REST_APPLICATION => 100,
18 ];
19
20 private static $accessManifest = [
21 'total',
22 'app'
23 ];
24
25 public static function getEntityList()
26 {
27 return static::$entityList;
28 }
29
30 public static function getManifestList(Event $event)
31 {
32 $manifestList = [];
33 $manifestList[] = [
34 'CODE' => 'total',
35 'VERSION' => 1,
36 'ACTIVE' => 'N',
37 'PLACEMENT' => [],
38 'USES' => [
39 'total'
40 ]
41 ];
42
43 return $manifestList;
44 }
45
46 public static function onEventExportController(Event $event)
47 {
48 $result = null;
49 $code = $event->getParameter('CODE');
50 if (
51 !static::$entityList[$code]
52 || !Manifest::isEntityAvailable($code, $event->getParameters(), static::$accessManifest)
53 )
54 {
55 return $result;
56 }
57
58 if (static::checkRequiredParams($code))
59 {
60 $step = $event->getParameter('STEP');
61 $setting = $event->getParameter('SETTING');
62 switch ($code)
63 {
64 case 'REST_APPLICATION':
65 $result = static::exportApp($step, $setting);
66 break;
67 }
68 }
69
70 return $result;
71 }
72
73 public static function onEventClearController(Event $event)
74 {
75 }
76
77 public static function onEventImportController(Event $event)
78 {
79 $result = null;
80 if (!static::checkAccessImport($event))
81 {
82 return $result;
83 }
84
85 $code = $event->getParameter('CODE');
86 if (static::checkRequiredParams($code))
87 {
88 $data = $event->getParameters();
89 switch ($code)
90 {
91 case 'REST_APPLICATION':
92 $result = static::importApp($data);
93 break;
94 }
95 }
96
97 return $result;
98 }
99
100 private static function checkAccessImport(Event $event)
101 {
102 $code = $event->getParameter('CODE');
103 if (
104 !isset(static::$entityList[$code])
105 || !static::$entityList[$code]
106 || !Manifest::isEntityAvailable($code, $event->getParameters(), static::$accessManifest)
107 )
108 {
109 return false;
110 }
111
112 return true;
113 }
114
120 private static function checkRequiredParams($type)
121 {
122 return true;
123 }
124
125 //region application
126 private static function importApp($item)
127 {
128 $result = false;
129 if (!empty($item['CONTENT']['DATA']['code']))
130 {
131 $code = preg_replace('/[^a-zA-Z0-9._\-]/', '', $item['CONTENT']['DATA']['code']);
132 if ($code !== $item['CONTENT']['DATA']['code'])
133 {
134 return [
135 'ERROR_EXCEPTION' => [
136 'message' => Loc::getMessage(
137 'REST_CONFIGURATION_ERROR_UNKNOWN_APP'
138 ),
139 ],
140 ];
141 }
142
143 Application::setContextUserId((int)$item['USER_ID']);
144 $result = Application::install($code);
145 if ($result['success'])
146 {
147 $res = AppTable::getList(
148 [
149 'filter' => [
150 '=CODE' => $code,
151 '=ACTIVE' => AppTable::ACTIVE,
152 '=INSTALLED' => AppTable::NOT_INSTALLED,
153 '!=URL_INSTALL' => false,
154 ],
155 'limit' => 1
156 ]
157 );
158 if ($app = $res->fetch())
159 {
160 $res = EventTable::getList(
161 [
162 'filter' => [
163 "APP_ID" => $app['ID'],
164 "EVENT_NAME" => "ONAPPINSTALL",
165 "EVENT_HANDLER" => $app["URL_INSTALL"],
166 ],
167 'limit' => 1
168 ]
169 );
170 if (!$event = $res->fetch())
171 {
172 $res = EventTable::add(
173 [
174 "APP_ID" => $app['ID'],
175 "EVENT_NAME" => "ONAPPINSTALL",
176 "EVENT_HANDLER" => $app["URL_INSTALL"],
177 ]
178 );
179 if ($res->isSuccess())
180 {
181 Sender::bind('rest', 'OnRestAppInstall');
182 }
183
185 AppTable::update(
186 $app['ID'],
187 [
188 'INSTALLED' => AppTable::INSTALLED
189 ]
190 );
192
194
195 AppTable::install($app['ID']);
196 }
197 }
198 }
199 elseif (is_array($result) && $result['errorDescription'])
200 {
201 $result['ERROR_EXCEPTION']['message'] = Loc::getMessage(
202 'REST_CONFIGURATION_ERROR_INSTALL_APP_CONTENT_DATA',
203 [
204 '#ERROR_CODE#' => $result['error'],
205 '#ERROR_MESSAGE#' => $result['errorDescription'],
206 ]
207 );
208 }
209 else
210 {
211 $result['ERROR_EXCEPTION']['message'] = Loc::getMessage(
212 'REST_CONFIGURATION_ERROR_INSTALL_APP_CONTENT'
213 );
214 }
215 }
216 else
217 {
218 return [
219 'ERROR_EXCEPTION' => [
220 'message' => Loc::getMessage(
221 'REST_CONFIGURATION_ERROR_UNKNOWN_APP'
222 ),
223 ],
224 ];
225 }
226
227 return $result;
228 }
229
230 private static function clearApp($option)
231 {
232 $result = [
233 'NEXT' => false
234 ];
235 if ($option['CLEAR_FULL'])
236 {
237 $dbRes = AppTable::getList(
238 [
239 'order' => [
240 'ID' => 'ASC'
241 ],
242 'filter' => [
243 '=ACTIVE' => AppTable::ACTIVE,
244 "!=STATUS" => AppTable::STATUS_LOCAL,
245 '>ID' => $option['NEXT']
246 ],
247 'limit' => 5
248 ]
249 );
250
251 while ($appInfo = $dbRes->Fetch())
252 {
253 $result['NEXT'] = $appInfo['ID'];
254
255 $currentApp = Helper::getInstance()->getContextAction($appInfo['ID']);
256 if (!empty($option['CONTEXT']) && $option['CONTEXT'] === $currentApp)
257 {
258 continue;
259 }
260
261 $checkResult = AppTable::checkUninstallAvailability($appInfo['ID']);
262 if ($checkResult->isEmpty())
263 {
264 AppTable::uninstall($appInfo['ID']);
265 $appFields = [
266 'ACTIVE' => 'N',
267 'INSTALLED' => 'N',
268 ];
269 AppTable::update($appInfo['ID'], $appFields);
271 }
272 }
273 }
274
275 return $result;
276 }
277
278 public static function exportApp($step, $setting)
279 {
280 $return = [
281 'FILE_NAME' => '',
282 'CONTENT' => [],
283 'NEXT' => false
284 ];
285
286 $filter = [
287 '!=STATUS' => AppTable::STATUS_LOCAL,
288 '=ACTIVE' => AppTable::ACTIVE,
289 ];
290
291 if (is_array($setting))
292 {
293 if (!empty($setting['APP_REQUIRED']) && is_array($setting['APP_REQUIRED']))
294 {
295 $filter = [
296 [
297 'LOGIC' => 'OR',
298 $filter,
299 [
300 '=ID' => $setting['APP_REQUIRED'],
301 ],
302 ],
303 ];
304 }
305 elseif (array_key_exists('APP_USES_REQUIRED', $setting))
306 {
307 $filter = [];
308 if (!empty($setting['APP_USES_REQUIRED']))
309 {
310 $filter = [
311 '=ID' => $setting['APP_USES_REQUIRED'],
312 ];
313 }
314 }
315 }
316
317 if (!empty($filter))
318 {
319 $res = AppTable::getList(
320 [
321 'order' => [
322 'ID' => 'ASC',
323 ],
324 'filter' => $filter,
325 'select' => [
326 'ID',
327 'CODE',
328 ],
329 'limit' => 1,
330 'offset' => $step,
331 ]
332 );
333
334 if ($app = $res->Fetch())
335 {
336 $return['FILE_NAME'] = $step;
337 $return['NEXT'] = $step;
338 $return['CONTENT'] = [
339 'code' => $app['CODE'],
340 'settings' => [],
341 ];
342 }
343 }
344
345 return $return;
346 }
347 //end region application
348}
$type
Определения options.php:106
Определения event.php:5
const ACTION_TYPE_UNINSTALL
Определения applog.php:40
static log($appId, $action)
Определения applog.php:90
const ACTION_TYPE_INSTALL
Определения applog.php:38
static install($appId)
Определения app.php:497
const INSTALLED
Определения app.php:71
const STATUS_LOCAL
Определения app.php:84
static uninstall($appId, $clean=0)
Определения app.php:551
const ACTIVE
Определения app.php:69
const NOT_INSTALLED
Определения app.php:72
static setSkipRemoteUpdate($v)
Определения app.php:260
static getManifestList(Event $event)
Определения appconfiguration.php:30
static onEventClearController(Event $event)
Определения appconfiguration.php:73
static exportApp($step, $setting)
Определения appconfiguration.php:278
static onEventExportController(Event $event)
Определения appconfiguration.php:46
static onEventImportController(Event $event)
Определения appconfiguration.php:77
static isEntityAvailable(string $entityCode, array $option, $uses=[])
Определения manifest.php:156
$data['IS_AVAILABLE']
Определения .description.php:13
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$app
Определения proxy.php:8
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$event
Определения prolog_after.php:141
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$option
Определения options.php:1711
$dbRes
Определения yandex_detail.php:168