Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
filesave.php
1<?php
2namespace Bitrix\Clouds;
3
6Loc::loadMessages(__FILE__);
7
39{
40 private static $files = array();
41
47 public static function getTableName()
48 {
49 return 'b_clouds_file_save';
50 }
51
57 public static function getMap()
58 {
59 return array(
60 'ID' => array(
61 'data_type' => 'integer',
62 'primary' => true,
63 'autocomplete' => true,
64 'title' => Loc::getMessage('FILE_SAVE_ENTITY_ID_FIELD'),
65 ),
66 'TIMESTAMP_X' => array(
67 'data_type' => 'datetime',
68 'required' => true,
69 'title' => Loc::getMessage('FILE_SAVE_ENTITY_TIMESTAMP_X_FIELD'),
70 ),
71 'BUCKET_ID' => array(
72 'data_type' => 'integer',
73 'required' => true,
74 'title' => Loc::getMessage('FILE_SAVE_ENTITY_BUCKET_ID_FIELD'),
75 ),
76 'SUBDIR' => array(
77 'data_type' => 'string',
78 'validation' => array(__CLASS__, 'validateSubdir'),
79 'title' => Loc::getMessage('FILE_SAVE_ENTITY_SUBDIR_FIELD'),
80 ),
81 'FILE_NAME' => array(
82 'data_type' => 'string',
83 'required' => true,
84 'validation' => array(__CLASS__, 'validateFileName'),
85 'title' => Loc::getMessage('FILE_SAVE_ENTITY_FILE_NAME_FIELD'),
86 ),
87 'EXTERNAL_ID' => array(
88 'data_type' => 'string',
89 'validation' => array(__CLASS__, 'validateExternalId'),
90 'title' => Loc::getMessage('FILE_SAVE_ENTITY_EXTERNAL_ID_FIELD'),
91 ),
92 'FILE_SIZE' => array(
93 'data_type' => 'integer',
94 'title' => Loc::getMessage('FILE_SAVE_ENTITY_FILE_SIZE_FIELD'),
95 ),
96 );
97 }
103 public static function validateSubdir()
104 {
105 return array(
106 new Main\Entity\Validator\Length(null, 255),
107 );
108 }
114 public static function validateFileName()
115 {
116 return array(
117 new Main\Entity\Validator\Length(null, 255),
118 );
119 }
125 public static function validateExternalId()
126 {
127 return array(
128 new Main\Entity\Validator\Length(null, 50),
129 );
130 }
131
142 public static function startFileOperation($bucketId, $subDir, $fileName, $externalId)
143 {
144 $key = $bucketId."|".$subDir."|".$fileName;
145 $fileSave = \Bitrix\Clouds\FileSaveTable::createObject();
146 $fileSave->setTimestampX(new \Bitrix\Main\Type\DateTime());
147 $fileSave->setBucketId($bucketId);
148 $fileSave->setSubdir($subDir);
149 $fileSave->setFileName($fileName);
150 $fileSave->setExternalId($externalId);
151 $fileSave->setFileSize(-1);
152 $saveResult = $fileSave->save();
153 if ($saveResult->isSuccess())
154 {
155 self::$files[$key] = $fileSave;
156 }
157 }
168 public static function setFileSize($bucketId, $subDir, $fileName, $fileSize)
169 {
170 $key = $bucketId."|".$subDir."|".$fileName;
171 if (isset(self::$files[$key]))
172 {
173 $fileSave = self::$files[$key];
174 $fileSave->setFileSize($fileSize);
175 $fileSave->save();
176 }
177 }
187 public static function endFileOperation($bucketId, $subDir, $fileName)
188 {
189 $key = $bucketId."|".$subDir."|".$fileName;
190 if (isset(self::$files[$key]))
191 {
192 $fileSave = self::$files[$key];
193 $fileSave->delete();
194 unset(self::$files[$key]);
195 }
196 }
197}
static endFileOperation($bucketId, $subDir, $fileName)
Definition filesave.php:187
static setFileSize($bucketId, $subDir, $fileName, $fileSize)
Definition filesave.php:168
static startFileOperation($bucketId, $subDir, $fileName, $externalId)
Definition filesave.php:142
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29