154 $result =
new Main\Entity\AddResult();
155 $fileCheckResult = \CFile::CheckImageFile($file,
156 static::MAX_FILE_SIZE,
157 static::MAX_SIDE_SIZE,
158 static::MAX_SIDE_SIZE,
161 if ($fileCheckResult ===
null)
163 $file[
'MODULE_ID'] =
'ui';
165 if ($fileId = \CFile::SaveFile($file,
'ui/mask'))
167 $result = Avatar\Model\ItemTable::add([
168 'OWNER_TYPE' => get_class(
$owner),
170 'GROUP_ID' => $descriptionParams[
'GROUP_ID'] ??
null,
171 'TITLE' => $descriptionParams[
'TITLE'] ??
null,
172 'DESCRIPTION' => $descriptionParams[
'DESCRIPTION'] ??
null,
173 'SORT' => $descriptionParams[
'SORT'] ?? 0,
177 if ($result->isSuccess() && ($item = static::getInstance($result->getId())))
180 $result->setData([$item]);
183 \CFile::Delete($fileId);
186 $result->addError(
new Main\
Error($fileCheckResult,
'image check'));
204 $result =
new Main\Entity\DeleteResult();
206 $connection = Main\Application::getConnection();
207 $sqlHelper = $connection->getSqlHelper();
208 $sqlItemTableName = Avatar\Model\ItemTable::getTableName();
209 $where = Main\ORM\Query\Query::buildFilterSql(Avatar\Model\ItemTable::getEntity(), $filter);
215 $connection = \Bitrix\Main\Application::getConnection();
217 $connection->getSqlHelper()->getInsertIgnore(
218 'b_ui_avatar_mask_file_deleted',
219 ' (ENTITY, ORIGINAL_FILE_ID, FILE_ID, ITEM_ID) ',
221SELECT
'ITEM_TEMP', FILE_ID, FILE_ID, ID
222 FROM {$sqlHelper->quote($sqlItemTableName)}
226 $connection->getType() ===
'mysql' ?
230 b_ui_avatar_mask_file_deleted AS FDTABLE
231 WHERE ACCESS1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
232MYSQL : ($connection->getType() ===
'pgsql' ?
235USING b_ui_avatar_mask_file_deleted AS FDTABLE
236WHERE ACCESS1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
238 $connection->getType() ===
'mysql' ?
242 b_ui_avatar_mask_file_deleted AS FDTABLE
243 WHERE RECENTLYUSED1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
244MYSQL : ($connection->getType() ===
'pgsql' ?
247USING b_ui_avatar_mask_file_deleted AS FDTABLE WHERE RECENTLYUSED1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
249 $connection->getSqlHelper()->getInsertIgnore(
250 'b_ui_avatar_mask_file_deleted',
251 ' (ENTITY, ORIGINAL_FILE_ID, FILE_ID, ITEM_ID) ',
253SELECT
'LINK', LINK1.ORIGINAL_FILE_ID, LINK1.FILE_ID, LINK1.ITEM_ID
255 b_ui_avatar_mask_file_deleted AS FDTABLE
256 WHERE LINK1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
259 $connection->getType() ===
'mysql' ?
263 b_ui_avatar_mask_file_deleted AS FDTABLE
264 WHERE LINK1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
265MYSQL : ($connection->getType() ===
'pgsql' ?
268USING b_ui_avatar_mask_file_deleted AS FDTABLE WHERE LINK1.ITEM_ID = FDTABLE.ITEM_ID AND FDTABLE.ENTITY =
'ITEM_TEMP'
271UPDATE b_ui_avatar_mask_file_deleted SET ENTITY =
'ITEM' WHERE ENTITY =
'ITEM_TEMP';
274 $sql = implode(
';' . PHP_EOL, $sql);
276 $connection->executeSqlBatch($sql);
278 $cleaningString = static::clearFileTable();
279 if ($cleaningString !==
'')
281 \CAgent::AddAgent($cleaningString,
'ui',
'Y',0,
'',
282 'Y',
'', 100,
false,
false
290 $connection = Main\Application::getConnection();
291 $limit = self::ORM_OPERATION_LIMIT_COUNT;
292 $dbRes = $connection->query(
"
294 FROM b_ui_avatar_mask_file_deleted
295 WHERE ENTITY IN ('ITEM', 'LINK')
301 if ($res = $dbRes->fetch())
305 self::$buffer[] = $res[
'FILE_ID'];
306 $items[] = $res[
'ITEM_ID'];
307 \CFile::Delete($res[
'FILE_ID']);
308 }
while ($res = $dbRes->fetch());
309 $itemsSql = implode(
',', $items);
310 $connection->queryExecute(
"DELETE FROM b_ui_avatar_mask_file_deleted WHERE ITEM_ID IN ({$itemsSql})");
313 if (count($items) < self::ORM_OPERATION_LIMIT_COUNT)
317 return '\\' . __CLASS__ .
"::" . __FUNCTION__ .
"();";
322 if (in_array($file[
'ID'], self::$buffer))
326 if ($file[
'MODULE_ID'] ===
'ui')
328 Avatar\Model\ItemToFileTable::deleteByFilter([
'=FILE_ID' => $file[
'ID']]);
331 'select' => [
'FILE_ID'],
332 'filter' => [
'=ORIGINAL_FILE_ID' => $file[
'ID']],
335 $connection = Main\Application::getConnection();
336 $sqlHelper = $connection->getSqlHelper();
337 $fileId = (int) $file[
'ID'];
340 $sqlHelper->getInsertIgnore(
341 'b_ui_avatar_mask_file_deleted',
342 '(ENTITY, ORIGINAL_FILE_ID, FILE_ID, ITEM_ID)',
344SELECT
'LINK', ORIGINAL_FILE_ID, FILE_ID, ITEM_ID
346 WHERE ORIGINAL_FILE_ID = {$fileId}
353 $sql = implode(
';' . PHP_EOL, $sql);
355 $connection->executeSqlBatch($sql);
357 $cleaningString = static::clearFileTable();
358 if ($cleaningString !==
'')
360 \CAgent::AddAgent($cleaningString,
'ui',
'Y',0,
'',
361 'Y',
'', 100,
false,
false