4use \Bitrix\Landing\Internals\FileTable;
35 $parts = pathinfo($fileName);
36 $basename = $parts[
'filename'];
37 $transliterateBaseName = \CUtil::translit(
41 'replace_space' =>
'_',
42 'replace_other' =>
'_'
46 return $transliterateBaseName .
'.' . $parts[
'extension'];
71 protected static function add(
int $fileId,
int $entityId,
string $entityType,
bool $temp =
false): void
73 $res = FileTable::getList(array(
79 'ENTITY_ID' => $entityId,
80 '=ENTITY_TYPE' => $entityType
87 'ENTITY_ID' => $entityId,
88 'ENTITY_TYPE' => $entityType,
89 'TEMP' => $temp ?
'Y' :
'N'
101 protected static function getFiles($entityId, $entityType)
104 $res = FileTable::getList(array(
109 'ENTITY_ID' => $entityId,
110 '=ENTITY_TYPE' => $entityType
113 while ($row = $res->fetch())
115 $files[] = $row[
'FILE_ID'];
127 protected static function delete($fileId, $entityId, $entityType)
131 $entityId .
'@' . $entityType,
132 'fileId: ' . print_r($fileId,
true) .
'@' . print_r(\
Bitrix\Main\Diag\Helper::getBackTrace(15),
true),
133 'LANDING_FILE_MARK_DELETE'
137 'ENTITY_ID' => $entityId,
138 '=ENTITY_TYPE' => $entityType
142 $filter[
'FILE_ID'] = $fileId;
144 $res = FileTable::getList(array(
150 while ($row = $res->fetch())
155 'FILE_ID' => -1 * abs($row[
'FILE_ID'])
158 $resUpdate->isSuccess();
171 $res = FileTable::getList([
183 while ($row = $res->fetch())
185 $row[
'FILE_ID'] *= -1;
187 $deletedFiles[$row[
'FILE_ID']] = $row[
'FILE_ID'];
189 if (!empty($deletedFiles))
192 $res = FileTable::getList([
197 'FILE_ID' => $deletedFiles
200 while ($row = $res->fetch())
202 unset($deletedFiles[$row[
'FILE_ID']]);
204 foreach ($deletedFiles as $fid)
206 $fileData = self::getFileArray($fid);
213 'LANDING_FILE_DELETE'
215 \CFile::delete($fid);
228 public static function addToSite(
int $id,
int $fileId,
bool $temp =
false): void
230 if ($fileId > 0 && $id > 0)
232 self::add($fileId, $id, self::ENTITY_TYPE_SITE, $temp);
243 return self::getFiles(
245 self::ENTITY_TYPE_SITE
257 self::delete($fileId, $id, self::ENTITY_TYPE_SITE);
268 if ($fileId > 0 && $lid > 0)
270 self::add($fileId, $lid, self::ENTITY_TYPE_LANDING);
281 return self::getFiles(
283 self::ENTITY_TYPE_LANDING
295 self::delete($fileId, $lid, self::ENTITY_TYPE_LANDING);
305 public static function addToBlock(
int $blockId, $fileId,
bool $temp =
false): void
309 if (!is_array($fileId))
311 $fileId = array($fileId);
313 foreach ($fileId as $fid)
317 self::add($fid, $blockId, self::ENTITY_TYPE_BLOCK, $temp);
333 if (!is_array($fileId))
335 $fileId = array($fileId);
337 $res = FileTable::getList(array(
342 'ENTITY_ID' => $blockId,
343 '=ENTITY_TYPE' => self::ENTITY_TYPE_BLOCK
346 while ($row = $res->fetch())
348 if (!in_array($row[
'FILE_ID'], $fileId))
350 self::delete($row[
'FILE_ID'], $blockId, self::ENTITY_TYPE_BLOCK);
353 self::addToBlock($blockId, $fileId);
365 self::delete($fileId, $blockId, self::ENTITY_TYPE_BLOCK);
378 if (preg_match_all(
'/data-fileid[2x]{0,2}="([\d]+)"/i', $content, $matches))
380 foreach ($matches[1] as $fid)
386 if (!empty($fileIds))
388 $res = FileTable::getList(array(
393 'FILE_ID' => $fileIds,
394 'ENTITY_ID' => $blockId,
395 '=ENTITY_TYPE' => self::ENTITY_TYPE_BLOCK
399 while ($row = $res->fetch())
401 $fileIds[] = $row[
'FILE_ID'];
414 return self::getFiles(
416 self::ENTITY_TYPE_BLOCK
428 if ($fileId > 0 && $assetId > 0)
430 self::add($fileId, $assetId, self::ENTITY_TYPE_ASSET);
431 self::markAssetRebuilded($assetId);
443 return self::getFiles(
445 self::ENTITY_TYPE_ASSET
458 self::delete($fileId, $assetId, self::ENTITY_TYPE_ASSET);
469 '=ENTITY_TYPE' => self::ENTITY_TYPE_ASSET
473 $filter[
'ENTITY_ID'] = $assetId;
476 $res = FileTable::getList([
477 'select' => [
'ID',
'ENTITY_ID'],
480 $files = $res->fetchAll();
482 foreach ($files as $file)
487 'ENTITY_ID' => -1 * abs($file[
'ENTITY_ID'])
490 $result = $result && $resUpdate->isSuccess();
493 return count($files) > 0 ? $result :
false;
503 if(!is_array($assetId))
505 $assetId = [$assetId];
508 foreach ($assetId as $key => $id)
510 self::deleteFromAsset(-1 * abs($id));
523 $res = FileTable::getList(array(
528 'ENTITY_ID' => $from,
529 '=ENTITY_TYPE' => $entityType
532 while ($row = $res->fetch())
535 'FILE_ID' => $row[
'FILE_ID'],
537 'ENTITY_TYPE' => $entityType
550 self::copyEntityFiles($from, $to, self::ENTITY_TYPE_SITE);
561 self::copyEntityFiles($from, $to, self::ENTITY_TYPE_LANDING);
572 self::copyEntityFiles($from, $to, self::ENTITY_TYPE_BLOCK);
582 $file = \CFile::getFileArray(
586 isset($file[
'MODULE_ID']) &&
587 $file[
'MODULE_ID'] ==
'landing'
602 $file = self::getFileArray($fileId);
603 if (isset($file[
'SRC']))
617 $res = FileTable::getList(array(
625 while ($row = $res->fetch())
638 if (self::getFileArray($fileId))
640 self::releaseFile($fileId);
641 \CFile::delete($fileId);
static markAssetToRebuild($assetId=[])
static getFilesFromLanding($landingId)
static addToLanding($lid, $fileId)
static copyEntityFiles($from, $to, $entityType)
static addToAsset($assetId, $fileId)
static replaceInBlock($blockId, $fileId)
static add(int $fileId, int $entityId, string $entityType, bool $temp=false)
static copyLandingFiles($from, $to)
static addToSite(int $id, int $fileId, bool $temp=false)
static addToBlock(int $blockId, $fileId, bool $temp=false)
static deleteFromSite($id, $fileId=array())
static deleteFromAsset(int $assetId, $fileId=[])
static sanitizeFileName(string $fileName)
static getFilesFromBlock($blockId)
static deletePhysical(int $fileId)
static copyBlockFiles($from, $to)
static getFilesFromSite($siteId)
static getFiles($entityId, $entityType)
static deleteFinal($limit=null)
static transliterateFileName(string $fileName)
static deleteFromBlock($blockId, $fileId=array())
static copySiteFiles($from, $to)
static getFileArray($fileId)
static deleteFromLanding($lid, $fileId=array())
static getFilesFromAsset($assetId)
static getFilesFromBlockContent($blockId, $content)
static getFilePath($fileId)
const ENTITY_TYPE_LANDING
static markAssetRebuilded($assetId)
static releaseFile(int $fileId)
static update($primary, array $data)