17 use Translate\Controller\Stepper;
18 use Translate\Controller\ProcessParams;
33 private $totalFileCount;
36 private $tmpFolderPath;
39 private $archiveFilePath;
42 private $archiveFileName;
48 private $downloadParams;
60 'packFile',
'languageId',
'tmpFolderPath',
'archiveFilePath',
61 'archiveFileName',
'seekPath',
'totalFileCount',
'downloadParams',
75 public function run($runBefore =
false)
84 $this->packFile = (bool)$progressParams[
'packFile'];
85 $this->languageId = $progressParams[
'languageId'];
86 $this->tmpFolderPath = $progressParams[
'tmpFolderPath'];
88 $this->totalFileCount = (int)$progressParams[
'totalFileCount'];
90 if ($this->isNewProcess)
92 $this->totalItems = $this->totalFileCount;
93 $this->processedItems = 0;
94 $this->archiveFileName = $this->generateExportFileName();
96 $exportFolder = Translate\Config::getExportFolder();
97 if (!empty($exportFolder))
103 $tempDir = Translate\IO\Directory::generateTemporalDirectory(
'translate');
106 if (!$tempDir->isExists() || !$tempDir->isDirectory())
109 Loc::getMessage(
'TR_ERROR_CREATE_TEMP_FOLDER', [
'#PATH#' => $tempDir->getPhysicalPath()])
114 $this->archiveFilePath = $tempDir->getPhysicalPath().
'/'. $this->archiveFileName;
117 $this->seekPath =
null;
121 $this->processedItems = (int)$progressParams[
'processedItems'];
122 $this->archiveFilePath = $progressParams[
'archiveFilePath'];
123 $this->archiveFileName = $progressParams[
'archiveFileName'];
124 $this->seekPath = $progressParams[
'seekPath'];
127 if (!$tempDir->isExists() || !$tempDir->isDirectory())
138 if ($this->isNewProcess)
140 if ($this->archiveFile->isExists())
142 $this->archiveFile->delete();
146 if ($this->isNewProcess)
151 'STATUS' => ($this->totalItems > 0 ? Translate\Controller\STATUS_PROGRESS : Translate\Controller\STATUS_COMPLETED),
152 'PROCESSED_ITEMS' => $this->processedItems,
153 'TOTAL_ITEMS' => $this->totalItems,
157 $this->archiveFile->setOptions([
158 'COMPRESS' => $this->packFile,
167 private function runPacking(): array
171 $this->totalItems = $this->totalFileCount;
175 switch ($this->archiveFile->pack($langDir, $this->seekPath))
177 case \IBXArchive::StatusContinue:
178 $this->seekPath = $this->archiveFile->getSeekPosition();
179 $this->processedItems += $this->archiveFile->getProcessedFileCount();
184 case \IBXArchive::StatusSuccess:
185 $this->processedItems += $this->archiveFile->getProcessedFileCount();
188 $this->downloadParams = $this->getDownloadingParameters();
189 $result[
'FILE_NAME'] = $this->downloadParams[
'fileName'];
190 $result[
'DOWNLOAD_LINK'] = $this->generateDownloadLink();
192 $messagePlaceholders = [
194 '#FILE_SIZE_FORMAT#' => \CFile::formatSize($this->downloadParams[
'fileSize']),
195 '#LANG#' => \mb_strtoupper($this->languageId),
196 '#FILE_PATH#' => $this->archiveFileName,
197 '#LINK#' => $result[
'DOWNLOAD_LINK'],
201 Loc::getMessage(
'TR_LANGUAGE_COLLECTED_ARCHIVE', $messagePlaceholders).
"\n".
205 $this->processToken =
null;
206 $this->seekPath =
null;
210 case \IBXArchive::StatusError:
211 if ($this->archiveFile->hasErrors())
213 $this->
addErrors($this->archiveFile->getErrors());
237 private function generateDownloadLink(): string
247 private function generateExportFileName(): string
249 if ($this->packFile && Translate\
IO\Archiver::libAvailable())
251 $fileName =
'file-'.$this->languageId.
'.tar.gz';
255 $fileName =
'file-'.$this->languageId.
'.tar';
266 private function getDownloadingParameters(): array
269 'fileName' => $this->archiveFileName,
270 'filePath' => $this->archiveFilePath,
271 'fileType' => $this->packFile ?
'application/tar+gzip' :
'application/tar',
272 'fileSize' => $this->archiveFile->getSize(),
284 return $controller::SETTING_ID;
static getMessage($code, $replace=null, $language=null)