1C-Bitrix 25.700.0
base.php
См. документацию.
1<?php
2
4
11use Bitrix\Disk\SystemUser;
12use Bitrix\Disk\Internals\FolderTable;
13use Bitrix\Disk\Internals\ObjectTable;
14use Bitrix\Disk\Driver;
18
24class Base extends ProviderBase
25{
26 private $storage;
27 private $folderFilter = [];
28
33 public function __construct(array $setting)
34 {
35 parent::__construct($setting);
36 if (!Loader::includeModule('disk'))
37 {
38 throw new SystemException(
39 'Can\'t include module disk',
40 'ERROR_INCLUDE_DISK'
41 );
42 }
43
44 if (!$this->loadStorage())
45 {
46 throw new SystemException(
47 'Can\'t load storage',
48 'ERROR_LOAD_STORAGE'
49 );
50 }
51 }
52
62 public function addContent(string $code, $content, $type = false): bool
63 {
64 $result = false;
65
67 if (is_null($content))
68 {
69 return $result;
70 }
71
72 $name = $code . Helper::CONFIGURATION_FILE_EXTENSION;
73
74 $folder = $this->getFolder(true);
75 if (!$folder)
76 {
77 if ($type !== false)
78 {
79 $subFolder = $folder->getChild(
80 [
81 '=NAME' => $type,
82 '=TYPE' => FolderTable::TYPE_FOLDER,
83 ]
84 );
85 if (!$subFolder)
86 {
87 $folder = $folder->addSubFolder(
88 [
89 'NAME' => $type,
90 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
91 ]
92 );
93 }
94 else
95 {
96 $folder = $subFolder;
97 }
98 }
99
100 if ($folder)
101 {
102 $file = $folder->uploadFile(
103 [
104 'name' => $name,
105 'content' => $content,
106 'type' => 'application/json',
107 ],
108 [
109 'NAME' => $name,
110 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
111 ]
112 );
113 if ($file)
114 {
115 $result = true;
116 }
117 }
118 }
119
120 return $result;
121 }
122
131 public function get(string $path, int $step): ?array
132 {
133 $result = null;
134 $folder = $this->getFolder();
135 if ($folder)
136 {
137 $folder = $folder->getChild(
138 [
139 '=NAME' => $path,
140 ]
141 );
142 }
143
144 if ($folder)
145 {
146 $fakeSecurityContext = Driver::getInstance()->getFakeSecurityContext();
147 $fileList = $folder->getChildren(
148 $fakeSecurityContext,
149 [
150 'filter' => [
151 '=TYPE' => ObjectTable::TYPE_FILE,
152 ]
153 ]
154 );
155 $i = 0;
156 foreach ($fileList as $child)
157 {
158 if ($i == $step && $child instanceof \Bitrix\Disk\File)
159 {
160 $server = Application::getInstance()->getContext()->getServer();
161 $documentRoot = $server->getDocumentRoot();
162 $filePath = $documentRoot . \CFile::GetPath(
163 $child->getFileId()
164 );
165 $file = new File($filePath);
166 try
167 {
168 $result = [
169 'DATA' => $file->getContents(),
170 'FILE_NAME' => $child->getName(),
171 ];
172 }
173 catch (FileNotFoundException $exception)
174 {
175 $result = null;
176 }
177
178 break;
179 }
180 $i++;
181 }
182 $result['COUNT'] = count($fileList);
183 }
184
185 return $result;
186 }
187
194 public function addFiles(array $files): array
195 {
196 $result = [
197 'success' => false,
198 'result' => [],
199 ];
200
201 $structure = new Structure($this->getUserContext());
202
203 $storage = $this->getStorage();
204 if ($storage)
205 {
206 $folder = $this->getFolder();
207 if (!$folder)
208 {
209 $folder = $storage->addFolder(
210 [
211 'NAME' => $this->getContext(),
212 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
213 ]
214 );
215 }
216
217 $subFolder = $folder->getChild(
218 [
219 '=NAME' => Helper::STRUCTURE_FILES_NAME,
220 '=TYPE' => FolderTable::TYPE_FOLDER,
221 ]
222 );
223 if (!$subFolder)
224 {
225 $subFolder = $folder->addSubFolder(
226 [
227 'NAME' => Helper::STRUCTURE_FILES_NAME,
228 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
229 ]
230 );
231 }
232
233 if ($subFolder)
234 {
235 foreach ($files as $file)
236 {
237 if ($file['ID'])
238 {
239 $id = (int) $file['ID'];
240 $structure->saveFile($id, $file);
241
242 $fileData = \CFile::MakeFileArray($id);
243 $res = $subFolder->uploadFile(
244 $fileData,
245 [
246 'NAME' => $id,
247 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
248 ]
249 );
250 if (!is_null($res))
251 {
252 $result['success'] = true;
253 $result['result'][$id] = true;
254 }
255 else
256 {
257 $result['result'][$id] = false;
258 }
259 }
260 }
261 }
262 }
263
264 return $result;
265 }
266
272 public function deleteFolder()
273 {
274 $folder = $this->getFolder();
275 if ($folder)
276 {
277 global $USER;
278 if (!$folder->deleteTree($USER->GetID()))
279 {
280 //$this->setErrors($folder->getErrors());//todo: add errors
281 }
282 }
283
284 return true;
285 }
286
293 {
294 $this->folderFilter = $filter;
295 }
296
303 public function getFolder(bool $autoCreate = false)
304 {
305 $filter = $this->folderFilter;
306 $folderName = $this->getContext();
307 if (empty($filter))
308 {
309 $filter = [
310 '=NAME' => $folderName,
311 '=TYPE' => FolderTable::TYPE_FOLDER
312 ];
313 }
314
315 $folder = $this->getStorage()->getChild($filter);
316 if (!$folder && $autoCreate)
317 {
318 $folder = $this->getStorage()->addFolder(
319 [
320 'NAME' => $folderName,
321 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
322 ]
323 );
324 }
325
326 return $folder;
327 }
328
329 private function loadStorage(): bool
330 {
331 $this->storage = Driver::getInstance()->addStorageIfNotExist(
332 Helper::getInstance()->getStorageBackupParam()
333 );
334
335 return !is_null($this->storage);
336 }
337
343 public function getStorage()
344 {
345 return $this->storage;
346 }
347}
$path
Определения access_edit.php:21
$type
Определения options.php:106
Определения loader.php:13
addContent(string $code, $content, $type=false)
Определения base.php:62
__construct(array $setting)
Определения base.php:33
setFolderFilter(array $filter)
Определения base.php:292
getFolder(bool $autoCreate=false)
Определения base.php:303
$content
Определения commerceml.php:144
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
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
Определения autoload.php:27
$name
Определения menu_edit.php:35
Определения Image.php:9
$files
Определения mysql_to_pgsql.php:30
if(empty($decryptedData)) $storage
Определения quickway.php:270
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936