Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
extract.php
1<?php
3
8
9
16{
17 use Translate\Controller\ProcessParams;
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
45 public function __construct($name, Main\Engine\Controller $controller, array $config = [])
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 if (!$this->archiveFile->isExists() || !$this->archiveFile->isFile())
82 {
83 $this->addError(
84 new Error(Loc::getMessage('TR_ERROR_OPEN_FILE', ['#FILE#' => $this->archiveFilePath]))
85 );
86 }
87 elseif ($this->archiveFileType !== '.tar.gz' && $this->archiveFileType !== '.tar')
88 {
89 $this->addError(new Main\Error(Loc::getMessage('TR_ERROR_TARFILE_EXTENTION')));
90 }
91
92 if (!$this->hasErrors())
93 {
94 if ($this->archiveFile->extract($this->tmpFolder) !== true)
95 {
96 if ($this->archiveFile->hasErrors())
97 {
98 $this->addErrors($this->archiveFile->getErrors());
99 }
100 else
101 {
102 $this->addError(
103 new Main\Error(Loc::getMessage('TR_ERROR_ARCHIVE'))
104 );
105 }
106 }
107 else
108 {
109 $this->totalFileCount = $this->archiveFile->getProcessedFileCount();
110 }
111
112 // we have to continue process in next action
113 $this->processToken = null;
114
115 $this->saveProgressParameters();
116 }
117
118 return [
119 'STATUS' => Translate\Controller\STATUS_COMPLETED,
120 'PROCESSED_ITEMS' => $this->totalFileCount,
121 'TOTAL_ITEMS' => $this->totalFileCount,
122 ];
123 }
124
125
132 {
133 $controller = $this->getController();
134 return $controller::SETTING_ID;
135 }
136}
addError(Error $error)
Definition action.php:200
addErrors(array $errors)
Definition action.php:213
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
__construct($name, Main\Engine\Controller $controller, array $config=[])
Definition extract.php:45