You are here

public function SiteAuditCheckContentDuplicateTitles::calculateScore in Site Audit 7

Same name and namespace in other branches
  1. 8.2 Check/Content/DuplicateTitles.php \SiteAuditCheckContentDuplicateTitles::calculateScore()

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

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Content/DuplicateTitles.php, line 99
Contains \SiteAudit\Check\Content\DuplicateTitles.

Class

SiteAuditCheckContentDuplicateTitles
Class SiteAuditCheckContentDuplicateTitles.

Code

public function calculateScore() {
  if (empty($this->registry['content_type_counts'])) {
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
  }
  $sql_query = 'SELECT title, type, COUNT(0) AS duplicate_count ';
  $sql_query .= 'FROM {node} ';
  $sql_query .= 'GROUP BY title, type ';
  $sql_query .= 'HAVING (COUNT(0) > 1) ';
  $sql_query .= 'ORDER BY duplicate_count DESC, title ASC ';
  $result = db_query($sql_query);
  $this->registry['nodes_duplicate_titles'] = array();
  $this->registry['nodes_duplicate_title_count'] = 0;
  foreach ($result as $row) {
    $this->registry['nodes_duplicate_titles'][$row->type][check_plain($row->title)] = $row->duplicate_count;
    $this->registry['nodes_duplicate_title_count'] += $row->duplicate_count;
  }
  if (!empty($this->registry['nodes_duplicate_titles'])) {
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
  }
  return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
}