You are here

public function SiteAuditCheckContentVocabularies::calculateScore in Site Audit 8.2

Same name and namespace in other branches
  1. 7 Check/Content/Vocabularies.php \SiteAuditCheckContentVocabularies::calculateScore()

Implements \SiteAudit\Check\Abstract\calculateScore().

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Content/Vocabularies.php, line 90
Contains \SiteAudit\Check\Content\Vocabularies.

Class

SiteAuditCheckContentVocabularies
Class SiteAuditCheckContentVocabularies.

Code

public function calculateScore() {
  $vocabularies = \Drupal::entityManager()
    ->getBundleInfo("taxonomy_term");
  $sql_query = 'SELECT COUNT(tid) AS count, vid ';
  $sql_query .= 'FROM {taxonomy_term_field_data} ';
  $sql_query .= 'GROUP BY vid ';
  $sql_query .= 'ORDER BY count DESC ';
  $result = db_query($sql_query);
  $this->registry['vocabulary_counts'] = $this->registry['vocabulary_unused'] = array();
  foreach ($result as $row) {
    $label = $vocabularies[$row->vid]['label'];
    $this->registry['vocabulary_counts'][$label] = $row->count;
  }

  // Check for unused vocabularies.
  foreach ($vocabularies as $vocabulary) {
    if (array_search($vocabulary['label'], array_keys($this->registry['vocabulary_counts'])) === FALSE) {
      $this->registry['vocabulary_unused'][] = $vocabulary['label'];
      $this->registry['vocabulary_counts'][$vocabulary['label']] = 0;
    }
  }

  // No need to check for unused vocabularies if there aren't any.
  if (empty($this->registry['vocabulary_counts'])) {
    $this->abort = TRUE;
  }
  return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
}