1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
extract.php
См. документацию.
1<?php
2namespace Bitrix\Translate\Controller\Asset;
3
4use Bitrix\Main;
5use Bitrix\Main\Error;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Translate;
8
9
16{
18
20 private $archiveFilePath;
21
23 private $archiveFileType;
24
26 private $archiveFile;
27
29 private $tmpFolderPath;
30
32 private $tmpFolder;
33
35 private $totalFileCount;
36
37
46 {
47 $this->keepField(['archiveFilePath', 'archiveFileType', 'tmpFolderPath', 'totalFileCount']);
48
49 parent::__construct($name, $controller, $config);
50 }
51
57 public function run()
58 {
59 // continue previous process
60 $progressParams = $this->getProgressParameters();
61
62 $this->archiveFilePath = $progressParams['archiveFilePath'];
63 $this->archiveFileType = $progressParams['archiveFileType'];
64
65 $this->totalFileCount = 0;
66
67
68 $this->tmpFolder = Translate\IO\Directory::generateTemporalDirectory('translate');
69 if (!$this->tmpFolder->isExists() || !$this->tmpFolder->isDirectory())
70 {
71 $this->addError(new Error(
72 Loc::getMessage('TR_ERROR_CREATE_TEMP_FOLDER', ['#PATH#' => $this->tmpFolder->getPhysicalPath()])
73 ));
74 }
75 else
76 {
77 $this->tmpFolderPath = $this->tmpFolder->getPhysicalPath();
78 }
79
80 $this->archiveFile = new Translate\IO\Archiver($this->archiveFilePath);
81 $this->archiveFile->setOptions(['CHECK_PERMISSIONS' => false]);
82
83 if (!$this->archiveFile->isExists() || !$this->archiveFile->isFile())
84 {
85 $this->addError(
86 new Error(Loc::getMessage('TR_ERROR_OPEN_FILE', ['#FILE#' => $this->archiveFilePath]))
87 );
88 }
89 elseif ($this->archiveFileType !== '.tar.gz' && $this->archiveFileType !== '.tar')
90 {
91 $this->addError(new Main\Error(Loc::getMessage('TR_ERROR_TARFILE_EXTENTION')));
92 }
93
94 if (!$this->hasErrors())
95 {
96 if ($this->archiveFile->extract($this->tmpFolder) !== true)
97 {
98 if ($this->archiveFile->hasErrors())
99 {
100 $this->addErrors($this->archiveFile->getErrors());
101 }
102 else
103 {
104 $this->addError(
105 new Main\Error(Loc::getMessage('TR_ERROR_ARCHIVE'))
106 );
107 }
108 }
109 else
110 {
111 $this->totalFileCount = $this->archiveFile->getProcessedFileCount();
112 }
113
114 // we have to continue process in next action
115 $this->processToken = null;
116
117 $this->saveProgressParameters();
118 }
119
120 return [
122 'PROCESSED_ITEMS' => $this->totalFileCount,
123 'TOTAL_ITEMS' => $this->totalFileCount,
124 ];
125 }
126
127
134 {
135 $controller = $this->getController();
136 return $controller::SETTING_ID;
137 }
138}
addError(Error $error)
Определения action.php:200
addErrors(array $errors)
Определения action.php:213
$controller
Определения action.php:23
getController()
Определения action.php:138
__construct($name, Main\Engine\Controller $controller, array $config=[])
Определения extract.php:45
static generateTemporalDirectory(string $prefix, int $timeToLive=3)
Определения directory.php:34
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения action.php:3
trait ProcessParams
Определения processparams.php:12
const STATUS_COMPLETED
Определения controller.php:6
trait Error
Определения error.php:11
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393