Implements Drupal\file\FileUsage\FileUsageInterface::delete().
Overrides FileUsageBase::delete
public function delete(File $file, $module, $type = NULL, $id = NULL, $count = 1) {
// Delete rows that have a exact or less value to prevent empty rows.
$query = $this->connection
->delete($this->tableName)
->condition('module', $module)
->condition('fid', $file->fid);
if ($type && $id) {
$query
->condition('type', $type)
->condition('id', $id);
}
if ($count) {
$query
->condition('count', $count, '<=');
}
$result = $query
->execute();
// If the row has more than the specified count decrement it by that number.
if (!$result && $count > 0) {
$query = $this->connection
->update($this->tableName)
->condition('module', $module)
->condition('fid', $file->fid);
if ($type && $id) {
$query
->condition('type', $type)
->condition('id', $id);
}
$query
->expression('count', 'count - :count', array(
':count' => $count,
));
$query
->execute();
}
parent::delete($file, $module, $type, $id, $count);
}