Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
expiredlinkcleanagent.php
1<?php
2
4
10
12{
13 private const MAX_LINKS_PER_QUERY = 500;
14
22 public static function runAgent(): string
23 {
24 (new self())->run();
25
26 return self::class . "::runAgent();";
27 }
28
35 private function run(): void
36 {
37 $expiredLinks = $this->getExpiredLinks();
38 if (!empty($expiredLinks))
39 {
40 $this->cleanExpiredLinks($expiredLinks);
41 }
42 }
43
50 private function getExpiredLinks(): array
51 {
52 $expiredLinks =
53 SharingLinkTable::query()
54 ->setSelect(['ID'])
55 ->whereNotNull('DATE_EXPIRE')
56 ->where('DATE_EXPIRE', '<', new DateTime())
57 ->where('ACTIVE', '=', 'Y')
58 ->setLimit(self::MAX_LINKS_PER_QUERY)
59 ->fetchAll()
60 ;
61
62 return array_map(static function($expiredLink){
63 return (int)$expiredLink['ID'];
64 }, $expiredLinks);
65 }
66
73 private function cleanExpiredLinks(array $expiredLinks): void
74 {
75 SharingLinkTable::updateMulti(
76 $expiredLinks,
77 ['ACTIVE' => 'N'],
78 );
79 }
80}