public function SiteAuditCheckContentDuplicateTitles::calculateScore in Site Audit 8.2
Same name and namespace in other branches
- 7 Check/Content/DuplicateTitles.php \SiteAuditCheckContentDuplicateTitles::calculateScore()
Implements \SiteAudit\Check\Abstract\calculateScore().
Overrides SiteAuditCheckAbstract::calculateScore
File
- Check/
Content/ DuplicateTitles.php, line 101 - Contains \SiteAudit\Check\Content\DuplicateTitles.
Class
- SiteAuditCheckContentDuplicateTitles
- Class SiteAuditCheckContentDuplicateTitles.
Code
public function calculateScore() {
if (empty($this->registry['content_entity_type_counts'])) {
return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
}
$sql_query = 'SELECT title, type, COUNT(0) AS duplicate_count ';
$sql_query .= 'FROM {node_field_data} ';
$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;
$content_types = $content_types = \Drupal::entityManager()
->getBundleInfo("node");
foreach ($result as $row) {
$label = $content_types[$row->type]['label'];
$title = Html::escape($row->title);
$this->registry['nodes_duplicate_titles'][$label][$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;
}