protected function AcsfDuplicationScrubCommentStorage::getOrphanedItems in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
- 8 src/Event/AcsfDuplicationScrubCommentStorage.php \Drupal\acsf\Event\AcsfDuplicationScrubCommentStorage::getOrphanedItems()
Gets a list of orphaned comment IDs.
'orphaned' means having an invalid user, commented entity, or parent comment. "Commented entity" is only checked for nodes (not other entity types).
Parameters
int $limit: (optional) Maximum number of comment IDs to fetch in one go.
int $already_processed_min_id: (optional) If specified and >0, only fetch IDs lower than this. 0 is interpreted as "no action is necessary".
Return value
array An indexed array indexed by the relevant comment IDs, with a value of 1 if the user and commented entity are valid (so only the parent comment is wrong), and 0 otherwise.
1 call to AcsfDuplicationScrubCommentStorage::getOrphanedItems()
- AcsfDuplicationScrubCommentStorage::deleteOrphanedItems in src/
Event/ AcsfDuplicationScrubCommentStorage.php - Deletes orphaned comments without having to load the full entities first.
File
- src/
Event/ AcsfDuplicationScrubCommentStorage.php, line 144
Class
- AcsfDuplicationScrubCommentStorage
- Comment storage class (using a SQL backend) which ignores load failures.
Namespace
Drupal\acsf\EventCode
protected function getOrphanedItems($limit = 0, $already_processed_min_id = -1) {
if ($already_processed_min_id == 0) {
return [];
}
$where = "u.uid IS NULL OR (n.nid IS NULL and c.entity_type = 'node')\n OR (pc.cid IS NULL AND c.pid > 0)";
$args = [];
if ($already_processed_min_id > 0) {
$where = "({$where}) AND c.cid < :processed";
$args[':processed'] = $already_processed_min_id;
}
$query = "SELECT c.cid, CASE WHEN u.uid IS NULL OR (n.nid IS NULL and c.entity_type = 'node') THEN 0 ELSE 1 END AS validref\n FROM {comment_field_data} c\n LEFT JOIN {users} u ON c.uid = u.uid\n LEFT JOIN {node} n ON c.entity_id = n.nid\n LEFT JOIN {comment} pc ON c.pid = pc.cid\n WHERE {$where} ORDER BY c.cid DESC";
$statement = $limit ? $this->database
->queryRange($query, 0, $limit, $args) : $this->database
->query($query, $args);
return $statement
->fetchAllKeyed();
}