protected function ListUsageController::checkHiddenUsages in Entity Usage 8.3
Checks whether there are hidden (past-revisions-only) usages.
Parameters
string $target_type: The entity type name.
string $target_id: The entity ID.
Return value
bool TRUE if there are usages recorded in past (non-default) revisions which ARE NOT present in current (default) revisions, FALSE otherwise.
1 call to ListUsageController::checkHiddenUsages()
- ListUsageController::listUsagePage in src/
Controller/ ListUsageController.php - Lists the usage of a given entity.
File
- src/
Controller/ ListUsageController.php, line 266
Class
- ListUsageController
- Controller for our pages.
Namespace
Drupal\entity_usage\ControllerCode
protected function checkHiddenUsages($target_type, $target_id) {
// For now deal only with nodes.
if (!$this
->moduleHandler()
->moduleExists('node') || !in_array('node', EntityUsageSourceLevel::getTopLevelEntityTypes())) {
return FALSE;
}
// @todo Use the DB API for this, and remove workarounds.
// What we want here is to check whether there are records in the
// entity_usage table that match this target type/id, and are NOT present
// in the node table, which means they are only present in past revisions.
$query_string = "SELECT DISTINCT node.vid FROM {entity_usage}\n LEFT JOIN {node}\n ON entity_usage.source_id = node.nid\n WHERE entity_usage.source_vid NOT IN (SELECT node.vid FROM {node})\n AND entity_usage.target_type = :target_type\n AND entity_usage.target_id = :target_id";
try {
$result = $this->database
->query($query_string, [
':target_type' => $target_type,
':target_id' => $target_id,
])
->fetchField();
} catch (DatabaseExceptionWrapper $e) {
return FALSE;
}
return !empty($result);
}