You are here

public function DigestManager::cleanupOldMessages in Message Digest 8

Cleanup old messages from the message_digest table.

Overrides DigestManagerInterface::cleanupOldMessages

Deprecated

This method is deprecated and will be removed before Message Digest 8.2.0 is released. Entries in the message_digest table are cleaned up automatically when messages or users are deleted so this is no longer needed.

File

src/DigestManager.php, line 103

Class

DigestManager
Digest manager service.

Namespace

Drupal\message_digest

Code

public function cleanupOldMessages() {

  // Removes any message entries from the message_digest table if the
  // corresponding message entity has been deleted.
  // The delete method cannot use a JOIN, so first query to find entries to
  // delete.
  // @see https://www.drupal.org/node/2693899
  $query = $this->database
    ->select('message_digest', 'md');
  $query
    ->leftJoin('message', 'm', 'md.mid = m.mid');
  $query
    ->isNull('m.mid');
  $query
    ->fields('md', [
    'mid',
  ]);
  $query
    ->condition('md.sent', 1);
  $mids = $query
    ->execute()
    ->fetchCol();
  if (!empty($mids)) {
    $this->database
      ->delete('message_digest')
      ->condition('mid', $mids, 'IN')
      ->condition('sent', 1)
      ->execute();
  }
}