Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TempFileAgent.php
1<?php
2
4
6
8{
9 const AGENT_MAX_INTERVAL = 1800;
10 const AGENT_MIN_INTERVAL = 360;
11
12 public static function clearOldRecords(): string
13 {
14 $expired = new DateTime();
15 $expired->add('-1 days');
16 $limit = 20;
17
18 $tempFiles = TempFileTable::getList([
19 'filter' => ['<CREATED_AT' => $expired->toString()],
20 'limit' => $limit,
21 'order' => ['CREATED_AT' => 'ASC']
22 ])->fetchCollection();
23
24 foreach ($tempFiles as $tempFile)
25 {
26 $tempFile->delete();
27 }
28
29 $agentName = '\\' . __METHOD__ . '();';
30 $agents = \CAgent::getList(['ID' => 'DESC'], [
31 'MODULE_ID' => 'ui',
32 'NAME' => $agentName,
33 ]);
34
35 if ($agent = $agents->fetch())
36 {
37 $interval = $tempFiles->count() < $limit ? static::AGENT_MAX_INTERVAL : static::AGENT_MIN_INTERVAL;
38 if ((int)$agent['AGENT_INTERVAL'] !== $interval)
39 {
40 \CAgent::update($agent['ID'], ['AGENT_INTERVAL' => $interval]);
41 }
42 }
43
44 return $agentName;
45 }
46}