23 private static $maxAgentTime = 10;
24 private static $fileDescriptionDelete =
'configuration_delete';
27 private $zipMimeType = [
29 'application/x-zip-compressed'
36 $this->context = $context;
37 $this->setting =
new Setting($context);
38 $this->setting->addMultipleCode(self::CODE_CONFIGURATION_FILES_LIST);
39 $this->setting->addMultipleCode(self::CODE_FILES_LIST);
40 $this->setting->addMultipleCode(self::CODE_FILES_SMALL_LIST);
50 $folder = $this->setting->get(
'FOLDER');
53 $folder = CTempFile::GetDirectoryName(
57 uniqid($this->context,
true)
62 $this->setting->set(
'FOLDER', $folder);
70 return $folder ?:
false;
98 $id = CFile::SaveFile(
101 'MODULE_ID' =>
'rest',
103 'description' => self::$fileDescriptionDelete
105 'configuration/export'
110 $return = $this->saveConfigurationFile($id,
$path);
126 private function saveConfigurationFile($id,
$name)
134 return $this->setting->set(self::CODE_CONFIGURATION_FILES_LIST, $file);
143 return $this->setting->get(self::CODE_CONFIGURATION_FILES_LIST);
152 public function saveFile($id, $additionalData = [])
154 $additionalData[
'ID'] = (int) $id;
155 return $this->setting->set(self::CODE_FILES_LIST, $additionalData);
164 return $this->setting->get(self::CODE_FILES_LIST);
176 $fileContent = File::getFileContents($fileInfo[
"tmp_name"]);
179 $type = (in_array($fileInfo[
"type"], $this->zipMimeType)) ?
'ZIP' :
'TAR.GZ';
181 $filePath = $folder.
'archive_tmp';
185 $res = $archive->Unpack($folder);
188 $this->initUnpackFilesList();
191 File::deleteFile($filePath);
212 if (!empty($file[
'CONTENT']))
214 $id = (int)$file[
'ID'];
217 File::putFileContents(
218 $folder . Helper::STRUCTURE_FILES_NAME .
'/' . $id,
219 base64_decode($file[
'CONTENT'])
221 unset($file[
'CONTENT']);
222 if (File::isFileExists($folder . Helper::STRUCTURE_FILES_NAME .
'/' . $id))
224 $file[
'PATH'] = $folder . Helper::STRUCTURE_FILES_NAME .
'/' . $id;
225 $this->setting->set(self::CODE_UNPACK_FILE_PREFIX . $id, $file);
240 private function initUnpackFilesList()
243 if (File::isFileExists($folder . Helper::STRUCTURE_SMALL_FILES_NAME . Helper::CONFIGURATION_FILE_EXTENSION))
247 . Helper::STRUCTURE_SMALL_FILES_NAME
248 . Helper::CONFIGURATION_FILE_EXTENSION
253 if (File::isFileExists($folder.Helper::STRUCTURE_FILES_NAME.Helper::CONFIGURATION_FILE_EXTENSION))
255 $content = File::getFileContents($folder.Helper::STRUCTURE_FILES_NAME.Helper::CONFIGURATION_FILE_EXTENSION);
263 $id = (int) $file[
'ID'];
264 if ($id > 0 && File::isFileExists($folder . Helper::STRUCTURE_FILES_NAME .
'/' . $id))
266 $file[
'PATH'] = $folder . Helper::STRUCTURE_FILES_NAME .
'/' . $id;
267 $this->setting->set(self::CODE_UNPACK_FILE_PREFIX . $id, $file);
272 catch (\Exception $e)
287 foreach ($filesInfo as $file)
289 $id = (int) $file[
'ID'];
290 if ($id > 0 &&
$files[$id])
292 $file[
'PATH'] =
$files[$id];
293 $this->setting->set(self::CODE_UNPACK_FILE_PREFIX . $id, $file);
310 if (Loader::includeModule(
'disk'))
314 $storage = Driver::getInstance()->addStorageIfNotExist(
326 $file = $folder->getChild(
328 '=NAME' => Helper::STRUCTURE_FILES_NAME . Helper::CONFIGURATION_FILE_EXTENSION
331 if ($file && $file->getFileId() > 0)
333 $server = Application::getInstance()->getContext()->getServer();
335 $filePath =
$documentRoot . CFile::GetPath($file->getFileId());
336 if (File::isFileExists($filePath))
338 $content = File::getFileContents($filePath);
342 $subFolder = $folder->getChild(
344 'NAME' => Helper::STRUCTURE_FILES_NAME
349 $fileList = array_column($fileList,
null,
'ID');
350 $fakeSecurityContext = Driver::getInstance()->getFakeSecurityContext();
351 $folderFiles = $subFolder->getChildren(
352 $fakeSecurityContext,
355 '=TYPE' => ObjectTable::TYPE_FILE
360 foreach ($folderFiles as $file)
362 $id = $file->getOriginalName();
363 if (!empty($fileList[$id]))
368 if (File::isFileExists(
$path))
370 $saveFile = $fileList[$id];
371 $saveFile[
'PATH'] =
$path;
372 $this->setting->set(self::CODE_UNPACK_FILE_PREFIX . $file->getFileId(), $saveFile);
400 return $this->setting->get(self::CODE_UNPACK_FILE_PREFIX . (
int) $id);
411 $this->setting->set(self::CODE_FILES_SMALL_LIST,
$info);
419 return $this->setting->get(self::CODE_FILES_SMALL_LIST);
431 $name = preg_replace(
'/[^a-zA-Z0-9_]/',
'',
$name);
458 $deleteDate->add(
'-2 days');
460 $res = StorageTable::getList(
462 'select' => [
'ID',
'CODE'],
464 '<CREATE_TIME' => $deleteDate
469 while ($item =
$res->fetch())
474 $row = StorageTable::getRowById($item[
'ID']);
475 StorageTable::deleteFile($row);
478 StorageTable::delete($item[
'ID']);
481 return '\Bitrix\Rest\Configuration\Structure::clearContentAgent();';
foreach(['Bitrix\\Main'=> '/lib', 'Psr\\Container'=> '/vendor/psr/container/src', 'Psr\\Log'=> '/vendor/psr/log/src', 'Psr\\Http\\Message'=> '/vendor/psr/http-message/src', 'Psr\\Http\\Client'=> '/vendor/psr/http-client/src', 'Http\\Promise'=> '/vendor/php-http/promise/src', 'PHPMailer\\PHPMailer'=> '/vendor/phpmailer/phpmailer/src', 'GeoIp2'=> '/vendor/geoip2/geoip2/src', 'MaxMind\\Db'=> '/vendor/maxmind-db/reader/src/MaxMind/Db', 'PhpParser'=> '/vendor/nikic/php-parser/lib/PhpParser', 'Recurr'=> '/vendor/simshaun/recurr/src/Recurr',] as $namespace=> $namespacePath) $documentRoot
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)