public function DatabaseFileUsageBackend::delete

Implements Drupal\file\FileUsage\FileUsageInterface::delete().

Overrides FileUsageBase::delete

File

drupal/core/modules/file/lib/Drupal/file/FileUsage/DatabaseFileUsageBackend.php, line 69
Definition of Drupal\file\FileUsage\DatabaseFileUsageBackend.

Class

DatabaseFileUsageBackend
Defines the database file usage backend. This is the default Drupal backend.

Namespace

Drupal\file\FileUsage

Code

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);
}