1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
wipeempty.php
См. документацию.
1<?php
2namespace Bitrix\Translate\Controller\Editor;
3
4use Bitrix\Main;
5use Bitrix\Translate;
6use Bitrix\Translate\Index;
7use Bitrix\Main\Localization\Loc;
8
15{
18
19 const SETTING_ID = 'WIPE_EMPTY';
20
22 private $pathList;
23
25 private $seekOffset;
26
27
36 {
37 $this->keepField(['pathList', 'seekOffset']);
38
39 parent::__construct($name, $controller, $config);
40 }
41
42
50 public function run($pathList)
51 {
52 if ($this->isNewProcess)
53 {
54 $pathList = \preg_split("/[\r\n]+/", $pathList);
55 \array_walk($pathList, 'trim');
56 $pathList = \array_unique(\array_filter($pathList));
57
58 if (empty($pathList))
59 {
60 $this->addError(new Main\Error(Loc::getMessage('TR_CLEAN_EMPTY_PATH_LIST')));
61
62 return [
64 ];
65 }
66
67 foreach ($pathList as $testPath)
68 {
69 if (Translate\IO\Path::isPhpFile($testPath))
70 {
71 if (Translate\IO\Path::isLangDir($testPath))
72 {
73 $this->pathList[] = $testPath;
74 }
75 else
76 {
77 $this->addError(new Main\Error(Loc::getMessage('TR_CLEAN_FILE_NOT_LANG', ['#FILE#' => $testPath])));
78 }
79 }
80 else
81 {
82 if (Translate\IO\Path::isLangDir($testPath))
83 {
84 $this->pathList[] = $testPath;
85 }
86 else
87 {
88 // load lang folders
89 $pathFilter = [];
90 $pathFilter[] = [
91 'LOGIC' => 'OR',
92 '=PATH' => \rtrim($testPath, '/'),
93 '=%PATH' => \rtrim($testPath, '/'). '/%'
94 ];
96 'filter' => $pathFilter,
97 'order' => ['ID' => 'ASC'],
98 'select' => ['PATH'],
99 ]);
100 while ($pathLang = $pathLangRes->fetch())
101 {
102 $this->pathList[] = $pathLang['PATH'];
103 }
104 }
105 }
106 }
107
108 $this->totalItems = \count($this->pathList);
109 $this->processedItems = 0;
110
111 if ($this->totalItems == 0)
112 {
113 return [
115 'PROCESSED_ITEMS' => 0,
116 'TOTAL_ITEMS' => 0,
117 ];
118 }
119
120 $this->saveProgressParameters();
121 $this->isNewProcess = false;
122 }
123
124 return $this->performStep('runWiping');
125 }
126
132 private function runWiping(): array
133 {
134 $processedItemCount = 0;
135 for ($pos = ((int)$this->seekOffset > 0 ? (int)$this->seekOffset : 0), $total = count($this->pathList); $pos < $total; $pos ++)
136 {
137 $testPath = $this->pathList[$pos];
138
139 $isOk = true;
140
141 // file
142 if (Translate\IO\Path::isPhpFile($testPath))
143 {
144 $testPath = Translate\IO\Path::replaceLangId($testPath, '#LANG_ID#');
145
146 foreach (self::$enabledLanguagesList as $langId)
147 {
148 $langRelPath = Translate\IO\Path::replaceLangId($testPath, $langId);
149 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.'/'.$langRelPath);
150 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
151
152 if ($this->removeEmptyParents($langFullPath))
153 {
154 Translate\Index\Internals\FileIndexTable::purge(new Translate\Filter(['path' => $testPath, 'langId' => $langId]));
155 }
156 else
157 {
158 $isOk = false;
159 }
160 }
161 }
162
163 // folder
164 else
165 {
166 if (\mb_substr($testPath, -5) === '/lang')
167 {
168 $testPath .= '/#LANG_ID#';
169 }
170 else
171 {
172 $testPath = Translate\IO\Path::replaceLangId($testPath, '#LANG_ID#');
173 }
174
175 foreach (self::$enabledLanguagesList as $langId)
176 {
177 $langRelPath = Translate\IO\Path::replaceLangId($testPath. '/.nonExistentTestFile.php', $langId);
178 $langFullPath = Translate\IO\Path::tidy(self::$documentRoot.'/'.$langRelPath);
179 $langFullPath = Main\Localization\Translation::convertLangPath($langFullPath, $langId);
180
181 if ($this->removeEmptyParents($langFullPath))
182 {
183 Translate\Index\Internals\FileIndexTable::purge(new Translate\Filter(['path' => $testPath, 'langId' => $langId]));
184 }
185 else
186 {
187 $isOk = false;
188 }
189 }
190 }
191
192 if ($isOk)
193 {
194 Translate\Index\Internals\PathIndexTable::purge(new Translate\Filter(['path' => $testPath, 'recursively' => true]));
195 }
196
197
198 $processedItemCount ++;
199
200 if (isset($this->pathList[$pos + 1]))
201 {
202 $this->seekOffset = $pos + 1;//next
203 }
204 else
205 {
206 $this->seekOffset = null;
207 $this->declareAccomplishment();
209 }
210
211 if ($this->instanceTimer()->hasTimeLimitReached())
212 {
213 break;
214 }
215 }
216
217 $this->processedItems += $processedItemCount;
218
219 if ($this->instanceTimer()->hasTimeLimitReached() !== true)
220 {
221 $this->declareAccomplishment();
223 }
224
225 return [
226 'PROCESSED_ITEMS' => $this->processedItems,
227 'TOTAL_ITEMS' => $this->totalItems,
228 ];
229 }
230
238 private function removeEmptyParents($langFullPath): bool
239 {
240 try
241 {
242 $langFile = Translate\File::instantiateByPath($langFullPath);
243 if ($langFile instanceof Translate\File)
244 {
245 return $langFile->removeEmptyParents();
246 }
247 }
248 catch (Main\ArgumentException $ex)
249 {
250 }
251
252 return false;
253 }
254
255
262 {
263 return self::SETTING_ID;
264 }
265}
$controller
Определения action.php:23
static convertLangPath($langFile, $language)
Определения translation.php:267
static getList(array $parameters=array())
Определения datamanager.php:431
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения wipeempty.php:35
static replaceLangId(string $path, string $langId)
Определения path.php:98
static tidy(string $path)
Определения path.php:16
static purge(?Translate\Filter $filter=null)
Определения fileindex.php:123
$langFile
Определения .description.php:2
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$pathLang
Определения jscore.php:6
Определения action.php:3
Определения directory.php:3
const Filter
Определения resultview.php:22
trait ProcessParams
Определения processparams.php:12
const STATUS_COMPLETED
Определения controller.php:6
instanceTimer()
Определения stepper.php:172
int $processedItems
Определения stepper.php:20
int $totalItems
Определения stepper.php:22
performStep($action, array $params=[])
Определения stepper.php:75
declareAccomplishment(bool $flag=true)
Определения stepper.php:136
trait Stepper
Определения stepper.php:13
Определения autoload.php:3
addError(Main\Error $error)
Определения error.php:22
trait Error
Определения error.php:11
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936