You are here

function photos_comment_delete in Album Photos 8.4

Same name and namespace in other branches
  1. 7.3 photos.module \photos_comment_delete()

Implements hook_ENTITY_TYPE_delete().

File

./photos.module, line 1036
Implementation of photos.module.

Code

function photos_comment_delete(CommentInterface $comment) {

  // Get fid.
  $db = \Drupal::database();
  $fid = $db
    ->select('photos_comment', 'v')
    ->fields('v', [
    'fid',
  ])
    ->condition('v.cid', $comment
    ->id())
    ->execute()
    ->fetchField();

  // Delete comment from {photos_comment}.
  $db
    ->delete('photos_comment')
    ->condition('cid', $comment
    ->id())
    ->execute();

  // Update image comment count.
  $count = $db
    ->query("SELECT COUNT(fid) FROM {photos_comment} WHERE fid = :fid", [
    ':fid' => $fid,
  ])
    ->fetchField();
  $db
    ->update('photos_image')
    ->fields([
    'comcount' => $count,
  ])
    ->condition('fid', $fid)
    ->execute();
}