Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
webpackclear.php
1<?php
2
4
8
9final class WebpackClear extends Stepper
10{
11 protected const CONTINUE_EXECUTING = true;
12 protected const STOP_EXECUTING = false;
13 protected const STEP_PORTION = 100;
14 protected const WEBPACK_NAME_MASK = 'landing_assets_webpack';
15 protected const MODULE_ID = 'landing';
16
21 protected $filesToDelete;
22
23 protected static $moduleId = 'landing';
24
30 public function execute(array &$result): bool
31 {
32 $countToStep = count($this->getFilesToDelete());
33
34 if ($countToStep <= 0)
35 {
37 }
38
39 $portionToDelete = array_slice($this->getFilesToDelete(), 0, self::STEP_PORTION);
40 foreach ($portionToDelete as $fileId)
41 {
42 \CFile::Delete($fileId);
43 }
44
45 if ($countToStep <= self::STEP_PORTION)
46 {
48 }
49
50 $result['count'] = $result['count'] ?: $countToStep;
51 $result['steps'] = $result['steps'] ? ($result['steps'] + self::STEP_PORTION) : self::STEP_PORTION;
52
54 }
55
56 protected function getFilesToDelete(): array
57 {
58 if (!$this->filesToDelete)
59 {
60 $this->findFilesToDelete();
61 }
62
64 }
65
69 protected function findFilesToDelete(): void
70 {
71 $fileIds = [];
72 $dbFiles = FileTable::getList([
73 'select' => ['ID'],
74 'filter' => [
75 '%ORIGINAL_NAME' => self::WEBPACK_NAME_MASK,
76 '=MODULE_ID' => self::MODULE_ID,
77 ],
78 ]);
79 while ($row = $dbFiles->fetch())
80 {
81 $fileIds[] = (int)$row['ID'];
82 }
83
84 $landingFileIds = [];
85 $fileIdsInRecycleBin = array_map(
86 function($i)
87 {
88 return $i * -1;
89 },
90 $fileIds
91 );
92 $dbLandingFiles = Landing\Internals\FileTable::getList([
93 'select' => ['FILE_ID'],
94 'filter' => [
95 'FILE_ID' => array_merge($fileIds, $fileIdsInRecycleBin),
96 ],
97 ]);
98 while ($row = $dbLandingFiles->fetch())
99 {
100 $landingFileIds[] = abs($row['FILE_ID']);
101 }
102
103 $this->filesToDelete = array_diff($fileIds, array_unique($landingFileIds));
104 }
105
112 public static function clearNotBindedFiles(): void
113 {
114 Stepper::bindClass('Bitrix\Landing\Update\Assets\WebpackClear', 'landing', 600);
115 }
116}