You are here

public static function Heartbeat::updateTermUsage in Heartbeat 8

Parameters

$tid:

5 calls to Heartbeat::updateTermUsage()
StatusForm::parseHashtags in modules/statusmessage/src/Form/StatusForm.php
StatusHeartPost::parseHashtags in modules/statusmessage/src/StatusHeartPost.php
StatusInstagram::processTerms in modules/statusmessage/src/StatusInstagram.php
StatusTwitter::processTerms in modules/statusmessage/src/StatusTwitter.php
StatusYoutube::parseHashtags in modules/statusmessage/src/StatusYoutube.php

File

src/Entity/Heartbeat.php, line 925

Class

Heartbeat

Namespace

Drupal\heartbeat\Entity

Code

public static function updateTermUsage($tid, $vid = null) {
  $update = Database::getConnection()
    ->update('taxonomy_term__field_count')
    ->expression('field_count_value', 'field_count_value + 1')
    ->condition('entity_id', $tid);
  if (!$update
    ->execute()) {
    $insert = Database::getConnection()
      ->insert('taxonomy_term__field_count')
      ->fields([
      'entity_id' => $tid,
      'revision_id' => $tid,
      'bundle' => $vid,
      'langcode' => \Drupal::languageManager()
        ->getDefaultLanguage()
        ->getId(),
      'delta' => 0,
      'field_count_value' => 1,
    ]);
    if (!$insert
      ->execute()) {
      \Drupal::logger('Heartbeat')
        ->error('Unable to update term counts for Term with ID = %tid', array(
        '%tid' => $tid,
      ));
    }
    else {
      self::newTermUsage($tid);
    }
  }
  else {
    self::newTermUsage($tid);
  }
}