1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
agent.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing;
4
11use Bitrix\Crm\WebForm;
14
18class Agent
19{
28 public static function addUniqueAgent(
29 string $funcName,
30 array $params = [],
31 int $time = 7200,
32 ?int $nextExecDelay = null
33 ): void
34 {
35 if (!method_exists(__CLASS__, $funcName))
36 {
37 return;
38 }
39
40 $funcName = self::createFunctionName($funcName, $params);
41
42 $res = \CAgent::getList(
43 [],
44 [
45 'MODULE_ID' => 'landing',
46 'NAME' => $funcName,
47 ]
48 );
49 if (!$res->fetch())
50 {
51 if ($nextExecDelay)
52 {
53 \CAgent::addAgent($funcName,
54 'landing',
55 'N',
56 $time,
57 '',
58 'Y',
59 \ConvertTimeStamp(time() + \CTimeZone::GetOffset() + $nextExecDelay, "FULL"));
60 }
61 else
62 {
63 \CAgent::addAgent($funcName, 'landing', 'N', $time);
64 }
65 }
66 }
67
71 public static function deleteUniqueAgent(string $funcName, array $params = []): void
72 {
73 if (!method_exists(__CLASS__, $funcName))
74 {
75 return;
76 }
77
78 $funcName = self::createFunctionName($funcName, $params);
79 $res = \CAgent::getList(
80 [],
81 [
82 'MODULE_ID' => 'landing',
83 'NAME' => $funcName,
84 ]
85 );
86 if ($agent = $res->fetch())
87 {
88 \CAgent::Delete((int)$agent['ID']);
89 }
90 }
91
92 private static function createFunctionName(string $funcName, array $params = []): string
93 {
94 $funcName = __CLASS__ . '::' . $funcName . '(';
95 foreach ($params as $value)
96 {
97 if (is_int($value))
98 {
99 $funcName .= $value . ',';
100 }
101 elseif (is_string($value))
102 {
103 $funcName .= '\'' . $value . '\'' . ',';
104 }
105 }
106 $funcName = trim($funcName, ',');
107 $funcName .= ');';
108
109 return $funcName;
110 }
111
116 public static function removeBadDomain(): string
117 {
118 $maxFailCount = 7;
119
121
122 // only custom domain
123 $filterDomains = array_map(function ($domain) {
124 return '%.' . $domain;
125 }, Domain::B24_DOMAINS);
126 $filterDomains[] = '%' . Manager::getHttpHost();
127
128 $customDomainExist = false;
129 $resDomain = Domain::getList([
130 'select' => [
131 'ID', 'DOMAIN', 'FAIL_COUNT',
132 ],
133 'filter' => [
134 '!DOMAIN' => $filterDomains,
135 ],
136 'limit' => 5,
137 'order' => [
138 'DATE_MODIFY' => 'asc',
139 ],
140 ]);
141 while ($domain = $resDomain->fetch())
142 {
143 $customDomainExist = true;
144 if (Domain\Register::isDomainActive($domain['DOMAIN']))
145 {
146 Domain::update($domain['ID'], [
147 'FAIL_COUNT' => null,
148 ])->isSuccess();
149 }
150 else
151 {
152 // remove domain
153 if ($domain['FAIL_COUNT'] >= $maxFailCount - 1)
154 {
155 // wee need site for randomize domain
156 $resSite = Site::getList([
157 'select' => [
158 'ID', 'DOMAIN_ID', 'DOMAIN_NAME' => 'DOMAIN.DOMAIN',
159 ],
160 'filter' => [
161 'DOMAIN_ID' => $domain['ID'],
162 ],
163 ]);
164 if ($rowSite = $resSite->fetch())
165 {
166 Debug::log('removeBadDomain-randomizeDomain', var_export($rowSite, true));
167 Site::randomizeDomain($rowSite['ID']);
168 }
169 // site not exist, delete domain
170 /*else
171 {
172 Debug::log('removeBadDomain-Domain::delete', var_export($rowSite, true));
173 Domain::delete($domain['ID'])->isSuccess();
174 }*/
175 }
176 else
177 {
178 Domain::update($domain['ID'], [
179 'FAIL_COUNT' => intval($domain['FAIL_COUNT']) + 1,
180 ])->isSuccess();
181 }
182 }
183 }
184
186
187 return $customDomainExist ? __CLASS__ . '::' . __FUNCTION__ . '();' : '';
188 }
189
196 public static function clearRecycleScope(string $scope, ?int $days = null): string
197 {
198 Site\Type::setScope($scope);
199
200 self::clearRecycle($days);
201
202 return __CLASS__ . '::' . __FUNCTION__ . '(\'' . $scope . '\');';
203 }
204
210 protected static function getSubFolders(int $folderId): array
211 {
212 $folders = [];
213 $res = Folder::getList([
214 'select' => [
215 'ID',
216 ],
217 'filter' => [
218 'PARENT_ID' => $folderId,
219 ],
220 ]);
221 while ($row = $res->fetch())
222 {
223 $folders[] = $row['ID'];
224 $folders = array_merge($folders, self::getSubFolders($row['ID']));
225 }
226
227 return $folders;
228 }
229
235 public static function clearRecycle(?int $days = null): string
236 {
237 Rights::setGlobalOff();
238
239 $days = !is_null($days)
240 ? $days
241 : (int)Manager::getOption('deleted_lifetime_days');
242
243 $date = new DateTime;
244 $date->add('-' . $days . ' days');
245
246 // check folders to delete
247 $foldersToDelete = [-1];
248 $res = Folder::getList([
249 'select' => [
250 'ID',
251 ],
252 'filter' => [
253 '=DELETED' => 'Y',
254 '<DATE_MODIFY' => $date,
255 ],
256 ]);
257 while ($row = $res->fetch())
258 {
259 $foldersToDelete[] = $row['ID'];
260 $foldersToDelete = array_merge($foldersToDelete, self::getSubFolders($row['ID']));
261 }
262
263 // first delete landings
264 $res = Landing::getList([
265 'select' => [
266 'ID', 'FOLDER_ID',
267 ],
268 'filter' => [
269 [
270 'LOGIC' => 'OR',
271 [
272 '=DELETED' => 'Y',
273 '<DATE_MODIFY' => $date,
274 ],
275 [
276 '=SITE.DELETED' => 'Y',
277 '<SITE.DATE_MODIFY' => $date,
278 ],
279 [
280 'FOLDER_ID' => $foldersToDelete,
281 ],
282 ],
283 '=DELETED' => ['Y', 'N'],
284 '=SITE.DELETED' => ['Y', 'N'],
285 'CHECK_PERMISSIONS' => 'N',
286 ],
287 'order' => [
288 'DATE_MODIFY' => 'desc',
289 ],
290 ]);
291 while ($row = $res->fetch())
292 {
293 Lock::lockDeleteLanding($row['ID'], false);
294 Landing::delete($row['ID'], true)->isSuccess();
295 }
296
297 // delete folders
298 foreach (array_unique($foldersToDelete) as $folderId)
299 {
300 if ($folderId > 0)
301 {
302 Folder::delete($folderId)->isSuccess();
303 }
304 }
305
306 // then delete sites
307 $res = Site::getList([
308 'select' => [
309 'ID',
310 ],
311 'filter' => [
312 '=DELETED' => 'Y',
313 '<DATE_MODIFY' => $date,
314 'CHECK_PERMISSIONS' => 'N',
315 ],
316 'order' => [
317 'DATE_MODIFY' => 'desc',
318 ],
319 ]);
320 while ($row = $res->fetch())
321 {
322 Lock::lockDeleteSite($row['ID'], false);
323 Site::delete($row['ID'])->isSuccess();
324 }
325
326 Rights::setGlobalOn();
327
328 return __CLASS__ . '::' . __FUNCTION__ . '();';
329 }
330
336 public static function clearFiles(?int $count = null): string
337 {
338 $count = !is_null($count) ? $count : 30;
339
340 File::deleteFinal($count);
341
342 return __CLASS__ . '::' . __FUNCTION__ . '(' . $count . ');';
343 }
344
350 public static function clearHistory(?int $days = null): string
351 {
352 Rights::setGlobalOff();
353
354 $newAgentName = __CLASS__ . '::' . __FUNCTION__ . '(' . ($days ?? '') . ');';
355
356 $days = $days ?: (int)Manager::getOption('history_lifetime_days');
357 $date = new DateTime();
358 $date->add('-' . $days . ' days');
359
360 $rows = HistoryTable::query()
361 ->setSelect(['ENTITY_ID', 'ENTITY_TYPE'])
362 ->setDistinct(true)
363 ->where('DATE_CREATE', '<', $date)
364 ->fetchAll()
365 ;
366 foreach ($rows as $row)
367 {
368 $history = new History($row['ENTITY_ID'], $row['ENTITY_TYPE']);
369 $history->clearOld($days);
370 }
371
372 return $newAgentName;
373 }
374
379 public static function sendRestStatistic(): string
380 {
381 if (
382 \Bitrix\Main\Loader::includeModule('rest')
383 && is_callable(['\Bitrix\Rest\UsageStatTable', 'logLanding'])
384 )
385 {
386 $statCode = [
387 \Bitrix\Landing\PublicAction::REST_USAGE_TYPE_BLOCK => 'LANDING_BLOCK',
388 \Bitrix\Landing\PublicAction::REST_USAGE_TYPE_PAGE => 'LANDING_PAGE',
389 ];
390 $data = PublicAction::getRestStat(false, true);
391 foreach ($data as $type => $stat)
392 {
393 if ($statCode[$type])
394 {
395 foreach ($stat as $clientId => $count)
396 {
397 \Bitrix\Rest\UsageStatTable::logLanding($clientId, $statCode[$type], $count);
398 }
399 }
400 }
401 \Bitrix\Rest\UsageStatTable::finalize();
402 }
403
404 return __CLASS__ . '::' . __FUNCTION__ . '();';
405 }
406
411 public static function clearTempFiles(): string
412 {
413 $dateTime = new DateTime();
414
415 $res = Internals\FileTable::getList([
416 'select' => [
417 'ID', 'FILE_ID',
418 ],
419 'filter' => [
420 '>FILE_ID' => 0,
421 '=TEMP' => 'Y',
422 '<FILE.TIMESTAMP_X' => $dateTime->add('-60 minute'),
423 ],
424 ]);
425 while ($row = $res->fetch())
426 {
427 Internals\FileTable::update($row['ID'], [
428 'FILE_ID' => -1 * $row['FILE_ID'],
429 ]);
430 }
431
432 return __CLASS__ . '::' . __FUNCTION__ . '();';
433 }
434
440 public static function repairFormUrls(int $lastLid = 0): string
441 {
442 if (Loader::includeModule('crm'))
443 {
444 $formQuery = WebForm\Internals\LandingTable::query()
445 ->addSelect('FORM_ID')
446 ->addSelect('LANDING_ID')
447 ->addOrder('LANDING_ID')
448 ->setLimit(50)
449 ->where('LANDING_ID', '>', $lastLid)
450 ->exec()
451 ;
452 $lastLid = 0;
453 while ($form = $formQuery->fetch())
454 {
455 $blocksQuery = BlockTable::query()
456 ->addSelect('ID')
457 ->where('LID', $form['LANDING_ID'])
458 ->where('CODE', '66.90.form_new_default')
459 ->exec()
460 ;
461 while ($block = $blocksQuery->fetch())
462 {
463 Subtype\Form::setFormIdToBlock($block['ID'], $form['FORM_ID']);
464 }
465 $lastLid = (int)$form['LANDING_ID'];
466 }
467
468 if ($lastLid > 0)
469 {
470 return __CLASS__ . '::' . __FUNCTION__ . '(' . $lastLid . ');';
471 }
472 }
473
474 return '';
475 }
476
482 public static function checkFileExists(int $fileId): string
483 {
484 $file = \CFile::getFileArray($fileId);
485 if (!$file)
486 {
487 return '';
488 }
489 if (!$file['SRC'] || !preg_match('#^(https?://)#', $file['SRC']))
490 {
491 return '';
492 }
493 $request = new HttpClient(["redirect" => false,]);
494 $request->query(HttpClient::HTTP_HEAD, $file['SRC']);
495 if ($request->getStatus() !== 200)
496 {
497 $filesToDelete = [$fileId];
498
499 // find duplicates of file
500 $originals = FileDuplicateTable::getList([
501 'select' => ['ORIGINAL_ID'],
502 'filter' => [
503 'DUPLICATE_ID' => $fileId,
504 ],
505 ]);
506 while ($original = $originals->fetch())
507 {
508 $filesToDelete[] = (int)$original['ORIGINAL_ID'];
509 }
510
511 $duplicates = FileDuplicateTable::getList([
512 'select' => ['DUPLICATE_ID'],
513 'filter' => [
514 'ORIGINAL_ID' => $filesToDelete,
515 ],
516 ]);
517 while ($duplicate = $duplicates->fetch())
518 {
519 $filesToDelete[] = (int)$duplicate['DUPLICATE_ID'];
520 }
521
522 $filesToDelete = array_unique($filesToDelete);
523
524 // clear LandingFile table
525 $landingFiles = FileTable::getList([
526 'select' => ['ID', 'ENTITY_ID'],
527 'filter' => [
528 'ENTITY_TYPE' => File::ENTITY_TYPE_ASSET,
529 '=FILE_ID' => $filesToDelete,
530 ],
531 ]);
532 $landingsToUpdate = [];
533 while ($landingFile = $landingFiles->fetch())
534 {
535 FileTable::delete((int)$landingFile['ID']);
536 $landingsToUpdate[] = (int)$landingFile['ENTITY_ID'];
537 }
538 $landingsToUpdate = array_unique($landingsToUpdate);
539
540 // find landings for drop public cache
541 if (Manager::isB24())
542 {
544 'select' => ['SITE_ID'],
545 'filter' => [
546 '=ID' => $landingsToUpdate,
547 ],
548 ]);
549 while ($site = $sites->fetch())
550 {
551 Site::update((int)$site['SITE_ID'], []);
552 }
553 }
554
555 foreach ($filesToDelete as $fileToDelete)
556 {
557 \CFile::delete($fileToDelete);
558 }
559 }
560
561 return '';
562 }
563
570 public static function rePublicationLanding($landingId): void
571 {
572 $landing = Landing::createInstance($landingId);
573 if ($landing->publication())
574 {
575 Manager::clearCacheForSite($landing->getSiteId());
576 }
577 }
578
584 public static function executeGeneration(int $generationId): string
585 {
586 $generation = new Copilot\Generation();
587 if ($generation->initById($generationId))
588 {
589 $generation->execute();
590 }
591
592 return '';
593 }
594}
return select
Определения access_edit.php:440
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
Определения agent.php:19
static clearRecycleScope(string $scope, ?int $days=null)
Определения agent.php:196
static deleteUniqueAgent(string $funcName, array $params=[])
Определения agent.php:71
static removeBadDomain()
Определения agent.php:116
static executeGeneration(int $generationId)
Определения agent.php:584
static rePublicationLanding($landingId)
Определения agent.php:570
static clearRecycle(?int $days=null)
Определения agent.php:235
static addUniqueAgent(string $funcName, array $params=[], int $time=7200, ?int $nextExecDelay=null)
Определения agent.php:28
static log($itemId, $itemDesc, $typeId='LANDING_LOG')
Определения debug.php:24
static isDomainActive(string $domainName)
Определения register.php:89
const ENTITY_TYPE_ASSET
Определения file.php:26
static isB24()
Определения manager.php:1135
static getHttpHost()
Определения manager.php:1058
static clearCacheForSite(int $siteId)
Определения manager.php:1460
static setGlobalOn()
Определения rights.php:116
static setGlobalOff()
Определения rights.php:107
static setScope($scope, array $params=[])
Определения type.php:88
Определения file.php:45
Определения loader.php:13
static getList(array $parameters=array())
Определения datamanager.php:431
$sites
Определения clear_component_cache.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
Определения chat.php:2
Определения agent.php:3
$time
Определения payment.php:61
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$site
Определения yandex_run.php:614