Loading core/modules/file/config/install/file.settings.yml +1 −1 Original line number Diff line number Diff line Loading @@ -3,4 +3,4 @@ description: length: 128 icon: directory: 'core/modules/file/icons' make_unused_managed_files_temporary: false core/modules/file/config/schema/file.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading core/modules/file/file.install +12 −0 Original line number Diff line number Diff line Loading @@ -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.'); } core/modules/file/file.services.yml +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 } core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php +5 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\file\FileUsage; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; use Drupal\file\FileInterface; Loading Loading @@ -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 Loading
core/modules/file/config/install/file.settings.yml +1 −1 Original line number Diff line number Diff line Loading @@ -3,4 +3,4 @@ description: length: 128 icon: directory: 'core/modules/file/icons' make_unused_managed_files_temporary: false
core/modules/file/config/schema/file.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
core/modules/file/file.install +12 −0 Original line number Diff line number Diff line Loading @@ -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.'); }
core/modules/file/file.services.yml +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 }
core/modules/file/src/FileUsage/DatabaseFileUsageBackend.php +5 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\file\FileUsage; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; use Drupal\file\FileInterface; Loading Loading @@ -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