Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
deletebyfiltertrait.php
1<?php
2
11
12use Bitrix\Main;
14
15trait DeleteByFilterTrait
16{
22 public static function deleteByFilter(array $filter)
23 {
24 $entity = static::getEntity();
25 $table = static::getTableName();
26
27 $where = Query\Query::buildFilterSql($entity, $filter);
28
29 if($where <> '')
30 {
31 $where = ' where ' . $where;
32 }
33 else
34 {
35 throw new Main\ArgumentException("Deleting by empty filter is not allowed, use truncate ({$table}).", 'filter');
36 }
37
38 static::onBeforeDeleteByFilter($where);
39
40 $entity->getConnection()->queryExecute("delete from {$table} {$where}");
41
42 static::cleanCache();
43 }
44
45 protected static function onBeforeDeleteByFilter(string $where)
46 {
47 // may be implemented in a class that uses the trait
48 }
49}