function DatabaseFileUsageBackend::delete
Same name in other branches
- 8.9.x core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete()
- 10 core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete()
- 11.x core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php \Drupal\file\FileUsage\DatabaseFileUsageBackend::delete()
Overrides FileUsageBase::delete
File
-
core/
modules/ file/ src/ FileUsage/ DatabaseFileUsageBackend.php, line 66
Class
- DatabaseFileUsageBackend
- Defines the database file usage backend. This is the default Drupal backend.
Namespace
Drupal\file\FileUsageCode
public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) {
// Delete rows that have an exact or less value to prevent empty rows.
$query = $this->connection
->delete($this->tableName)
->condition('module', $module)
->condition('fid', $file->id());
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->id());
if ($type && $id) {
$query->condition('type', $type)
->condition('id', $id);
}
$query->expression('count', '[count] - :count', [
':count' => $count,
]);
$query->execute();
}
parent::delete($file, $module, $type, $id, $count);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.