- Модуль: translate
- Путь к файлу: ~/bitrix/modules/translate/lib/controller/asset/collect.php
- Класс: BitrixTranslateControllerAssetCollect
- Вызов: Collect::run
public function run($path = '', $runBefore = false)
{
if ($runBefore)
{
$this->onBeforeRun();
}
if (empty($path))
{
$path = Grabber::START_PATH;
}
$path = '/'. trim($path, '/.\');
if ($this->isNewProcess)
{
$this->clearProgressParameters();
$this->totalItems = 0;
$this->processedItems = 0;
$this->totalFileCount = 0;
// language
$languageId = $this->controller->getRequest()->get('languageId');
if (empty($languageId))
{
$this->addError(new MainError(Loc::getMessage('TR_ERROR_SELECT_LANGUAGE')));
}
if (!in_array($languageId, self::$enabledLanguages))
{
$this->addError(new MainError(Loc::getMessage('TR_ERROR_LANGUAGE_ID')));
}
else
{
$this->languageId = $languageId;
}
// convert encoding
$this->convertEncoding = ($this->controller->getRequest()->get('convertEncoding') === 'Y');
// encoding
$encoding = $this->controller->getRequest()->get('encoding');
if ($encoding !== null && in_array($encoding, self::$allowedEncodings))
{
$this->encoding = $encoding;
}
elseif ($this->convertEncoding)
{
$this->addError(new MainError(Loc::getMessage('TR_ERROR_ENCODING')));
}
if ($this->convertEncoding)
{
if (self::$useTranslationRepository)
{
$encodingIn = MainLocalizationTranslation::getSourceEncoding($this->languageId);
$encodingOut = $this->encoding;
if ($encodingIn === 'utf-8' && $encodingOut !== 'utf-8')
{
$this->addError(new Error(Loc::getMessage('TR_ERROR_LANGUAGE_CHARSET_NON_UTF')));
}
}
elseif (TranslateConfig::isUtfMode())
{
$encodingIn = 'utf-8';
$encodingOut = $this->encoding;
if (TranslateConfig::getCultureEncoding($this->languageId) !== 'utf-8')
{
$this->addError(new Error(Loc::getMessage('TR_ERROR_LANGUAGE_CHARSET_NON_UTF')));
}
}
else
{
$encodingIn = TranslateConfig::getCultureEncoding($this->languageId);
if (!$encodingIn)
{
$encodingIn = MainLocalizationTranslation::getCurrentEncoding();
}
$this->encoding = $encodingOut = 'utf-8';
}
$this->convertEncoding = (mb_strtolower($encodingIn) !== mb_strtolower($encodingOut));
}
// assembly date
$assemblyDate = $this->controller->getRequest()->get('assemblyDate');
if ($assemblyDate !== null && preg_replace("/[D]+/", "", $assemblyDate) && mb_strlen($assemblyDate) == 8)
{
$this->assemblyDate = $assemblyDate;
}
else
{
$this->addError(new MainError(Loc::getMessage('TR_ERROR_LANGUAGE_DATE')));
}
// pack
$this->packFile = ($this->controller->getRequest()->get('packFile') === 'Y');
if (!$this->hasErrors())
{
$exportFolder = TranslateConfig::getExportFolder();
if (!empty($exportFolder))
{
$tempDir = new TranslateIODirectory($exportFolder.'/'.$this->languageId);
if ($tempDir->isExists())
{
$tempDir->wipe();
}
else
{
$tempDir->create();
}
}
else
{
$tempDir = TranslateIODirectory::generateTemporalDirectory('translate');
$tempDir = $tempDir->createSubdirectory($this->languageId);
}
$this->tmpFolderPath = $tempDir->getPhysicalPath(). '/';
if (!$tempDir->isExists())
{
$this->addError(
new Error(Loc::getMessage('TR_ERROR_CREATE_TEMP_FOLDER', ['#PATH#' => $this->tmpFolderPath]))
);
}
}
if (!$this->hasErrors())
{
$fileDateMarkFullPath = $this->tmpFolderPath.
str_replace('#LANG_ID#', $this->languageId, TranslateSUPD_LANG_DATE_MARK);
TranslateIOPath::checkCreatePath(dirname($fileDateMarkFullPath));
$fileDateMark = new MainIOFile($fileDateMarkFullPath);
if ($fileDateMark->putContents($assemblyDate) === false)
{
$this->addError(
new Error(Loc::getMessage('TR_ERROR_OPEN_FILE', ['#FILE#' => $fileDateMarkFullPath]))
);
}
}
$this->totalItems = (int)IndexInternalsPathLangTable::getCount(['=%PATH' => $path.'%']);
$this->processedItems = 0;
$this->saveProgressParameters();
return [
'STATUS' => ($this->totalItems > 0 ? TranslateControllerSTATUS_PROGRESS : TranslateControllerSTATUS_COMPLETED),
'PROCESSED_ITEMS' => 0,
'TOTAL_ITEMS' => $this->totalItems,
];
}
$progressParams = $this->getProgressParameters();
$this->languageId = $progressParams['languageId'];
$this->convertEncoding = $progressParams['convertEncoding'];
$this->encoding = $progressParams['encoding'];
$this->assemblyDate = $progressParams['assemblyDate'];
$this->packFile = $progressParams['packFile'];
$this->tmpFolderPath = $progressParams['tmpFolderPath'];
if (isset($progressParams['totalItems']) && (int)$progressParams['totalItems'] > 0)
{
$this->totalItems = (int)$progressParams['totalItems'];
$this->processedItems = (int)$progressParams['processedItems'];
$this->totalFileCount = (int)$progressParams['totalFileCount'];
}
if (isset($progressParams['seekPathLangId']))
{
$this->seekPathLangId = $progressParams['seekPathLangId'];
}
return $this->performStep('runCollecting', ['path' => $path]);
}