17 use Translate\Controller\Stepper;
18 use Translate\Controller\ProcessParams;
24 private $tmpFolderPath;
27 private $sourceFolderPath;
30 private $totalFileCount;
48 private $seekAncestors;
52 'component' =>
'#BX_ROOT#/components/bitrix',
53 'activities' =>
'#BX_ROOT#/activities/bitrix',
54 'gadgets' =>
'#BX_ROOT#/gadgets/bitrix',
55 'wizards' =>
'#BX_ROOT#/wizards/bitrix',
56 'blocks' =>
'#BX_ROOT#/blocks/bitrix',
57 'template' =>
'#BX_ROOT#/templates',
58 'mobileapp' =>
'#BX_ROOT#/mobileapp',
59 'js' =>
'#BX_ROOT#/js',
62 'component' =>
'/install/components/bitrix',
63 'activities' =>
'/install/activities/bitrix',
64 'gadgets' =>
'/install/gadgets/bitrix',
65 'wizards' =>
'/install/wizards/bitrix',
66 'blocks' =>
'/install/blocks/bitrix',
67 'template' =>
'/install/templates',
68 'mobileapp' =>
'/install/mobileapp',
69 'js' =>
'/install/js',
84 'languageId',
'tmpFolderPath',
'totalFileCount',
'sourceFolderPath',
85 'seekPath',
'seekModule',
'seekType'
90 self::$useTranslationRepository = Main\Localization\Translation::useTranslationRepository();
91 self::$enabledLanguages = Translate\Config::getEnabledLanguages();
92 if (self::$useTranslationRepository)
94 self::$translationRepositoryRoot = Main\Localization\Translation::getTranslationRepositoryPath();
109 $updatePublic = $this->controller->getRequest()->get(
'updatePublic');
110 if ($updatePublic ===
null || $updatePublic !==
'Y')
114 'STATUS' => Translate\Controller\STATUS_COMPLETED,
115 'PROCESSED_ITEMS' => $progressParams[
'totalFileCount'],
116 'TOTAL_ITEMS' => $progressParams[
'totalItems'],
121 $this->languageId = $progressParams[
'languageId'];
122 $this->tmpFolderPath = $progressParams[
'tmpFolderPath'];
123 $this->totalFileCount = $progressParams[
'totalFileCount'];
126 if ($this->isNewProcess)
128 $this->totalItems = $this->totalFileCount;
129 $this->processedItems = 0;
132 $languageId = $this->controller->getRequest()->get(
'languageId');
133 if (empty($languageId))
137 if (!in_array($languageId, self::$enabledLanguages))
143 $this->languageId = $languageId;
146 $this->sourceFolderPath = Translate\IO\Path::tidy($this->tmpFolderPath .
'/'. $this->languageId.
'/');
149 if (!$sourceDirectory->isExists())
152 new Error(
Loc::getMessage(
'TR_ERROR_CREATE_TARGET_FOLDER', [
'#PATH#' => $this->sourceFolderPath]))
159 'STATUS' => ($this->totalItems > 0 ? Translate\Controller\STATUS_PROGRESS : Translate\Controller\STATUS_COMPLETED),
160 'PROCESSED_ITEMS' => 0,
161 'TOTAL_ITEMS' => $this->totalItems,
165 $this->targetFolderPath = $progressParams[
'targetFolderPath'];
166 $this->seekPath = $progressParams[
'seekPath'];
167 $this->seekModule = $progressParams[
'seekModule'];
168 $this->seekType = $progressParams[
'seekType'];
179 private function runApplying(): array
181 $processedItemCount = 0;
183 if (!empty($this->seekPath))
185 $this->seekAncestors = [];
186 $arr = \explode(
'/', \str_replace($this->sourceFolderPath,
'', $this->seekPath));
189 foreach ($arr as $part)
192 $this->seekAncestors[] = $this->sourceFolderPath. \implode(
'/', $parts);
197 foreach ($sourceDirectory->getChildren() as $entry)
199 $moduleName = $entry->getName();
200 if (\in_array($moduleName, Translate\IGNORE_FS_NAMES) || !$entry->isDirectory())
204 if (!empty($this->seekModule))
206 if ($this->seekModule !== $moduleName)
210 $this->seekModule =
null;
213 foreach (self::SOURCE_FOLDERS as $type => $typeSourcePath)
215 if (!empty($this->seekType))
217 if ($this->seekType !== $type)
221 $this->seekType =
null;
224 $sourceFolder =
new Main\IO\Directory($entry->getPhysicalPath(). $typeSourcePath);
225 if ($sourceFolder->isExists())
227 $targetFolderPath = \str_replace(
'#BX_ROOT#', self::$documentRoot.
''. \BX_ROOT, self::TARGET_FOLDERS[$type]);
229 foreach ($this->lookThroughTmpFolder($sourceFolder->getPhysicalPath()) as $filePaths)
231 foreach ($filePaths as $langFilePath => $sourceFullPath)
234 $targetFolderPath .
'/'.
235 \str_replace($moduleName. $typeSourcePath .
'/',
'', \dirname($langFilePath));
237 $targetFolder =
new Main\IO\Directory($targetPath);
238 if (!$targetFolder->isExists())
240 $targetFolder->create();
243 $moduleSourcePath = self::$documentRoot.
''. \BX_ROOT.
'/modules/'. $langFilePath;
244 $source =
new Main\IO\File($moduleSourcePath);
245 if (!$source->isExists())
250 $target =
new Main\IO\File($targetFolder->getPhysicalPath().
'/'. \basename($langFilePath));
251 if ($target->isExists())
253 $target->markWritable();
258 if (\function_exists(
'error_clear_last'))
262 if (\copy($source->getPhysicalPath(), $target->getPhysicalPath()) !==
true)
264 $error = \error_get_last();
265 $this->
addError(
new Main\
Error($error[
'message'], $error[
'type']));
269 $processedItemCount ++;
271 catch (Main\
IO\IoException $exception)
280 $this->seekPath = $sourceFullPath;
281 $this->seekModule = $moduleName;
282 $this->seekType = $type;
288 if (\connection_status() !== \CONNECTION_NORMAL)
290 throw new Main\SystemException(
'Process has been broken course user aborted connection.');
295 $this->processedItems += $processedItemCount;
321 private function lookThroughTmpFolder($tmpFolderFullPath): iterable
326 $tmpFolderFullPath = Translate\IO\Path::tidy(\rtrim($tmpFolderFullPath,
'/'));
327 $langFolderRelPath = \str_replace($this->sourceFolderPath,
'', $tmpFolderFullPath);
329 $childrenList = Translate\IO\FileSystemHelper::getFileList($tmpFolderFullPath);
330 if (!empty($childrenList))
332 foreach ($childrenList as $fullPath)
334 if (!empty($this->seekPath))
336 if ($this->seekPath != $fullPath)
341 $this->seekPath =
null;
342 $this->seekAncestors =
null;
345 $name = \basename($fullPath);
346 if (\in_array(
$name, Translate\IGNORE_FS_NAMES))
351 if (Translate\
IO\Path::isPhpFile($fullPath,
true))
353 $files[$langFolderRelPath.
'/'.
$name] = $fullPath;
359 $childrenList = Translate\IO\FileSystemHelper::getFolderList($tmpFolderFullPath);
360 if (!empty($childrenList))
362 foreach ($childrenList as $fullPath)
364 $name = \basename($fullPath);
365 if (\in_array(
$name, Translate\IGNORE_FS_NAMES))
370 if (!empty($this->seekPath))
372 if (\in_array($fullPath, $this->seekAncestors))
374 foreach ($this->lookThroughTmpFolder($fullPath) as $subFiles)
382 if (!\is_dir($fullPath))
387 $relPath = $langFolderRelPath.
'/'.
$name;
389 if (\in_array($relPath, Translate\IGNORE_BX_NAMES))
394 $folders[$relPath] = $fullPath;
398 if (\count($files) > 0)
403 if (\count($folders) > 0)
405 foreach ($folders as $subFolderPath)
407 foreach ($this->lookThroughTmpFolder($subFolderPath) as $subFiles)
423 return $controller::SETTING_ID;
static getMessage($code, $replace=null, $language=null)