16 use Translate\Controller\Stepper;
17 use Translate\Controller\ProcessParams;
37 $this->
keepField([
'pathList',
'seekOffset']);
50 public function run($pathList)
52 if ($this->isNewProcess)
54 $pathList = \preg_split(
"/[\r\n]+/", $pathList);
55 \array_walk($pathList,
'trim');
56 $pathList = \array_unique(\array_filter($pathList));
63 'STATUS' => Translate\Controller\STATUS_COMPLETED,
67 foreach ($pathList as $testPath)
69 if (Translate\
IO\Path::isPhpFile($testPath))
71 if (Translate\
IO\Path::isLangDir($testPath))
73 $this->pathList[] = $testPath;
82 if (Translate\
IO\Path::isLangDir($testPath))
84 $this->pathList[] = $testPath;
92 '=PATH' => \rtrim($testPath,
'/'),
93 '=%PATH' => \rtrim($testPath,
'/').
'/%'
95 $pathLangRes = Index\Internals\PathLangTable::getList([
96 'filter' => $pathFilter,
97 'order' => [
'ID' =>
'ASC'],
100 while ($pathLang = $pathLangRes->fetch())
102 $this->pathList[] = $pathLang[
'PATH'];
108 $this->totalItems = \count($this->pathList);
109 $this->processedItems = 0;
111 if ($this->totalItems == 0)
114 'STATUS' => Translate\Controller\STATUS_COMPLETED,
115 'PROCESSED_ITEMS' => 0,
121 $this->isNewProcess =
false;
132 private function runWiping(): array
134 $processedItemCount = 0;
135 for ($pos = ((
int)$this->seekOffset > 0 ? (
int)$this->seekOffset : 0), $total = count($this->pathList); $pos < $total; $pos ++)
137 $testPath = $this->pathList[$pos];
142 if (Translate\
IO\Path::isPhpFile($testPath))
144 $testPath = Translate\IO\Path::replaceLangId($testPath,
'#LANG_ID#');
146 foreach (self::$enabledLanguagesList as $langId)
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);
152 if ($this->removeEmptyParents($langFullPath))
154 Translate\Index\Internals\FileIndexTable::purge(
new Translate\
Filter([
'path' => $testPath,
'langId' => $langId]));
166 if (\mb_substr($testPath, -5) ===
'/lang')
168 $testPath .=
'/#LANG_ID#';
172 $testPath = Translate\IO\Path::replaceLangId($testPath,
'#LANG_ID#');
175 foreach (self::$enabledLanguagesList as $langId)
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);
181 if ($this->removeEmptyParents($langFullPath))
183 Translate\Index\Internals\FileIndexTable::purge(
new Translate\Filter([
'path' => $testPath,
'langId' => $langId]));
194 Translate\Index\Internals\PathIndexTable::purge(
new Translate\Filter([
'path' => $testPath,
'recursively' =>
true]));
198 $processedItemCount ++;
200 if (isset($this->pathList[$pos + 1]))
202 $this->seekOffset = $pos + 1;
206 $this->seekOffset =
null;
217 $this->processedItems += $processedItemCount;
238 private function removeEmptyParents($langFullPath): bool
242 $langFile = Translate\File::instantiateByPath($langFullPath);
243 if ($langFile instanceof Translate\File)
245 return $langFile->removeEmptyParents();
248 catch (Main\ArgumentException $ex)
static getMessage($code, $replace=null, $language=null)