Commit e3ceb190 authored by catch's avatar catch
Browse files

Issue #2801777 by Berdir, Wim Leers, Pol, alexpott, dawehner, Jo Fitzgerald,...

Issue #2801777 by Berdir, Wim Leers, Pol, alexpott, dawehner, Jo Fitzgerald, Munavijayalakshmi, poornima.n, ifrik, Bojhan, catch: Prevent drupal from deleting temporary files
parent e0ea6c67
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,4 +3,4 @@ description:
  length: 128
icon:
  directory: 'core/modules/file/icons'
make_unused_managed_files_temporary: false
+3 −0
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@ file.settings:
        directory:
          type: path
          label: 'Directory'
    make_unused_managed_files_temporary:
      type: boolean
      label: 'Controls if unused files should be marked temporary'

field.storage_settings.file:
  type: base_entity_reference_field_settings
+12 −0
Original line number Diff line number Diff line
@@ -116,3 +116,15 @@ function file_requirements($phase) {

  return $requirements;
}

/**
 * Prevent unused files from being deleted.
 */
function file_update_8300() {
  // Disable deletion of unused permanent files.
  \Drupal::configFactory()->getEditable('file.settings')
    ->set('make_unused_managed_files_temporary', FALSE)
    ->save();

  return t('Files that have no remaining usages are no longer deleted by default.');
}
+1 −1
Original line number Diff line number Diff line
services:
  file.usage:
    class: Drupal\file\FileUsage\DatabaseFileUsageBackend
    arguments: ['@database']
    arguments: ['@database', 'file_usage', '@config.factory']
    tags:
      - { name: backend_overridable }
+5 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\file\FileUsage;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\file\FileInterface;

@@ -32,8 +33,11 @@ class DatabaseFileUsageBackend extends FileUsageBase {
   *   information.
   * @param string $table
   *   (optional) The table to store file usage info. Defaults to 'file_usage'.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   (optional) The config factory.
   */
  public function __construct(Connection $connection, $table = 'file_usage') {
  public function __construct(Connection $connection, $table = 'file_usage', ConfigFactoryInterface $config_factory = NULL) {
    parent::__construct($config_factory);
    $this->connection = $connection;

    $this->tableName = $table;
Loading