60 public static function updateList(array $filter, array $fields, array $eventData = [])
62 $entity = static::getEntity();
63 $connection = $entity->getConnection();
65 $result = $connection->query(sprintf(
66 "UPDATE %s SET %s WHERE %s",
67 $connection->getSqlHelper()->quote($entity->getDbTableName()),
68 $connection->getSqlHelper()->prepareUpdate($entity->getDbTableName(), $fields)[0],
69 Entity\Query::buildFilterSql($entity, $filter)
71 $eventManager = EventManager::getInstance();
72 $eventKey = $eventManager->addEventHandler(
74 'onMailMessageModified',
75 array(MessageEventManager::class,
'onMailMessageModified')
77 $event = new \Bitrix\Main\Event(
'mail',
'onMailMessageModified', array(
78 'MAIL_FIELDS_DATA' => $eventData,
79 'UPDATED_FIELDS_VALUES' => $fields,
80 'UPDATED_BY_FILTER' => $filter,
83 EventManager::getInstance()->removeEventHandler(
'mail',
'onMailMessageModified', $eventKey);
98 public static function deleteList(array $filter, array $messages = [], $limit =
false): bool
102 $filter = array_merge(
109 $messages = static::selectMessagesToBeDeleted(
116 if (empty($messages))
121 $entity = static::getEntity();
122 $connection = $entity->getConnection();
126 $messagesCount = count($messages);
128 for ($i = 0; $i < $messagesCount; $i=$i+$portionLimit)
130 $portion = array_slice($messages, $i, $portionLimit);
133 ' FROM %s WHERE ID IN (\'' . join(
"','", array_column($portion,
'ID')) .
'\')
',
134 $connection->getSqlHelper()->quote($entity->getDbTableName()),
137 self::insertIntoDeleteMessagesQueue($connection, $query);
139 $connection->query(sprintf('DELETE %s
', $query));
146 $remains = array_column(
147 static::selectMessagesToBeDeleted(
148 MessageEventManager::getRequiredFieldNamesForEvent($eventName),
157 if ($messagesIds = array_column($messages, 'MESSAGE_ID
') )
159 $remains = array_column(
166 '@MESSAGE_ID
' => $messagesIds,
175 //Checking that the values were actually deleted:
176 $deletedMessages = array_filter(
178 function ($item) use ($remains)
180 return !in_array($item['MESSAGE_ID
'], $remains);
184 $eventManager = EventManager::getInstance();
185 $eventKey = $eventManager->addEventHandler(
187 'onMailMessageDeleted
',
188 array(MessageEventManager::class, 'onMailMessageDeleted
')
190 $event = new \Bitrix\Main\Event('mail
', 'onMailMessageDeleted
', array(
191 'MAIL_FIELDS_DATA
' => $deletedMessages,
192 'DELETED_BY_FILTER
' => $filter,
195 EventManager::getInstance()->removeEventHandler('mail
', 'onMailMessageDeleted
', $eventKey);
233 public static function deleteListSoft(array $filter)
235 $entity = static::getEntity();
236 $connection = $entity->getConnection();
237 $filter = array_merge($filter , static::getPresetRemoveFilters());
239 //mark selected messages for deletion if there are no messages in the download queue
241 'UPDATE %s SET %s WHERE %s AND NOT EXISTS (SELECT 1 FROM %s WHERE %s)
',
242 $connection->getSqlHelper()->quote($entity->getDbTableName()),
243 $connection->getSqlHelper()->prepareUpdate($entity->getDbTableName(), [
244 'DELETE_TIME
' => time(),
246 Entity\Query::buildFilterSql(
250 $connection->getSqlHelper()->quote(Internals\MessageUploadQueueTable::getTableName()),
251 Entity\Query::buildFilterSql(
254 '=ID
' => new \Bitrix\Main\DB\SqlExpression('?#
', 'ID
'),
255 '=MAILBOX_ID
' => new \Bitrix\Main\DB\SqlExpression('?#
', 'MAILBOX_ID
'),
260 $result = $connection->query($query);
261 $count = $connection->getAffectedRowsCount();
262 $result->setCount($count > 0 ? $count : 0);
277 private static function selectMessagesToBeDeleted($fields, $filter, array $eventData, $limit = false): array
362 public static function mergeData(array $insert, array $update)
364 $entity = static::getEntity();
365 $connection = $entity->getConnection();
366 $helper = $connection->getSqlHelper();
368 $sql = $helper->prepareMerge($entity->getDBTableName(), $entity->getPrimaryArray(), $insert, $update);
370 $sql = current($sql);
373 $connection->queryExecute($sql);
374 $entity->cleanCache();