Skip to content
Snippets Groups Projects
Commit a227db18 authored by catch's avatar catch
Browse files

Issue #3021833 by pavnish, andypost, munish.kumar, kim.pepper, googletorp,...

Issue #3021833 by pavnish, andypost, munish.kumar, kim.pepper, googletorp, swatichouhan012, daffie, Berdir, alexpott, xjm: Move FILE_STATUS_PERMANENT to \Drupal\file\FileInterface
parent 4b4895c0
No related branches found
No related tags found
16 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!594Put each entity type table into a details element on admin/config/regional/content-language,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
Showing
with 47 additions and 31 deletions
......@@ -21,6 +21,12 @@
* configuration value will be, if clean-up not disabled, removed during cron
* runs, but permanent files will not be removed during the file garbage
* collection process.
*
* @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
* \Drupal\file\FileInterface::STATUS_PERMANENT or
* \Drupal\file\FileInterface::setPermanent() instead.
*
* @see https://www.drupal.org/node/3022147
*/
const FILE_STATUS_PERMANENT = 1;
......
......@@ -567,7 +567,7 @@
* Here is an example, using the core File entity:
* @code
* $fids = Drupal::entityQuery('file')
* ->condition('status', FILE_STATUS_PERMANENT, '<>')
* ->condition('status', \Drupal\file\FileInterface::STATUS_PERMANENT, '<>')
* ->condition('changed', REQUEST_TIME - $age, '<')
* ->range(0, 100)
* ->execute();
......
......@@ -152,9 +152,9 @@ public function testImageFieldSync() {
$field_values = [
'uri' => $this->files[$index]->uri,
'uid' => \Drupal::currentUser()->id(),
'status' => FILE_STATUS_PERMANENT,
];
$file = File::create($field_values);
$file->setPermanent();
$file->save();
$fid = $file->id();
$this->files[$index]->fid = $fid;
......
......@@ -444,8 +444,7 @@ function editor_entity_revision_delete(EntityInterface $entity) {
/**
* Records file usage of files referenced by formatted text fields.
*
* Every referenced file that does not yet have the FILE_STATUS_PERMANENT state,
* will be given that state.
* Every referenced file that is temporally saved will be resaved as permanent.
*
* @param array $uuids
* An array of file entity UUIDs.
......
......@@ -560,8 +560,8 @@ function file_save_data($data, $destination = NULL, $replace = FileSystemInterfa
$file = File::create([
'uri' => $uri,
'uid' => $user->id(),
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
// If we are replacing an existing file re-use its database record.
// @todo Do not create a new entity in order to update it. See
// https://www.drupal.org/node/2241865.
......@@ -709,7 +709,7 @@ function file_cron() {
if ($age) {
$fids = Drupal::entityQuery('file')
->accessCheck(FALSE)
->condition('status', FILE_STATUS_PERMANENT, '<>')
->condition('status', FileInterface::STATUS_PERMANENT, '<>')
->condition('changed', REQUEST_TIME - $age, '<')
->range(0, 100)
->execute();
......@@ -1782,7 +1782,7 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
function _views_file_status($choice = NULL) {
$status = [
0 => t('Temporary'),
FILE_STATUS_PERMANENT => t('Permanent'),
FileInterface::STATUS_PERMANENT => t('Permanent'),
];
if (isset($choice)) {
......
......@@ -124,7 +124,7 @@ public function getCreatedTime() {
* {@inheritdoc}
*/
public function isPermanent() {
return $this->get('status')->value == FILE_STATUS_PERMANENT;
return $this->get('status')->value == static::STATUS_PERMANENT;
}
/**
......@@ -138,7 +138,7 @@ public function isTemporary() {
* {@inheritdoc}
*/
public function setPermanent() {
$this->get('status')->value = FILE_STATUS_PERMANENT;
$this->get('status')->value = static::STATUS_PERMANENT;
}
/**
......
......@@ -13,6 +13,15 @@
*/
interface FileInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
/**
* Indicates that the file is permanent and should not be deleted.
*
* Temporary files older than the system.file.temporary_maximum_age will be
* removed during cron runs if cleanup is not disabled. (Permanent files will
* not be removed during the file garbage collection process.)
*/
const STATUS_PERMANENT = 1;
/**
* Returns the name of the file.
*
......
......@@ -12,7 +12,7 @@ class FileStorage extends SqlContentEntityStorage implements FileStorageInterfac
/**
* {@inheritdoc}
*/
public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT) {
public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT) {
$query = $this->database->select($this->entityType->getBaseTable(), 'f')
->condition('f.status', $status);
$query->addExpression('SUM([f].[filesize])', 'filesize');
......
......@@ -17,11 +17,11 @@ interface FileStorageInterface extends ContentEntityStorageInterface {
* non-temporary files.
* @param int $status
* (Optional) The file status to consider. The default is to only
* consider files in status FILE_STATUS_PERMANENT.
* consider files in status FileInterface::STATUS_PERMANENT.
*
* @return int
* An integer containing the number of bytes used.
*/
public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT);
public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT);
}
......@@ -3,6 +3,7 @@
namespace Drupal\file\Plugin\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\file\FileInterface;
/**
* Provides specific access control for the file entity type.
......@@ -28,7 +29,7 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
// become "permanent" after the containing entity gets validated and
// saved.)
$query->condition($query->orConditionGroup()
->condition('status', FILE_STATUS_PERMANENT)
->condition('status', FileInterface::STATUS_PERMANENT)
->condition('uid', $this->currentUser->id()));
return $query;
}
......
......@@ -227,8 +227,8 @@ protected function createFile() {
'filemime' => 'text/plain',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
......
......@@ -80,7 +80,7 @@ protected function createEntity() {
$file->setFilename('drupal.txt');
$file->setMimeType('text/plain');
$file->setFileUri('public://drupal.txt');
$file->set('status', FILE_STATUS_PERMANENT);
$file->setPermanent();
$file->save();
file_put_contents($file->getFileUri(), 'Drupal');
......
......@@ -131,8 +131,8 @@ public function testFileCacheability() {
'filename' => 'green-scarf',
'uri' => 'private://green-scarf',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
$file->save();
\Drupal::service('session')->set('anonymous_allowed_file_ids', [$file->id() => $file->id()]);
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
......@@ -48,7 +49,7 @@ public function testFileAccess() {
'uid' => 1,
'filename' => 'drupal.txt',
'uri' => 'public://drupal.txt',
'status' => FILE_STATUS_PERMANENT,
'status' => FileInterface::STATUS_PERMANENT,
]);
$file_public->save();
......@@ -63,7 +64,7 @@ public function testFileAccess() {
'uid' => 1,
'filename' => 'drupal.txt',
'uri' => 'private://drupal.txt',
'status' => FILE_STATUS_PERMANENT,
'status' => FileInterface::STATUS_PERMANENT,
]);
$file_private->save();
......
......@@ -26,8 +26,8 @@ public function testCustomFileUriField() {
'filename' => 'druplicon.txt',
'uri' => $uri,
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
file_put_contents($file->getFileUri(), 'hello world');
$file->save();
......
......@@ -44,8 +44,8 @@ protected function setUp(): void {
'filemime' => 'text/plain',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
$file->enforceIsNew();
file_put_contents($file->getFileUri(), 'hello world');
......
......@@ -18,8 +18,8 @@ public function testFileSave() {
'filename' => 'druplicon.txt',
'uri' => 'public://druplicon.txt',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
......@@ -61,8 +61,8 @@ public function testFileSave() {
'filename' => 'DRUPLICON.txt',
'uri' => 'public://DRUPLICON.txt',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
];
$file->setPermanent();
$uppercase_file = File::create($uppercase_values);
file_put_contents($uppercase_file->getFileUri(), 'hello world');
$violations = $uppercase_file->validate();
......@@ -90,8 +90,8 @@ public function testFileSave() {
'filename' => 'no-druplicon.txt',
'uri' => 'public://no-druplicon.txt',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
file_put_contents($file->getFileUri(), '');
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
/**
* Tests the spaceUsed() function.
......@@ -40,7 +41,7 @@ protected function setUp(): void {
* @return \Drupal\Core\Entity\EntityInterface
* The file entity.
*/
protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) {
protected function createFileWithSize($uri, $size, $uid, $status = FileInterface::STATUS_PERMANENT) {
file_put_contents($uri, $this->randomMachineName($size));
$file = File::create([
'uri' => $uri,
......@@ -63,15 +64,15 @@ public function testFileSpaceUsed() {
// Test the status fields
$this->assertEquals(4, $file->spaceUsed(NULL, 0));
$this->assertEquals(370, $file->spaceUsed(NULL, FILE_STATUS_PERMANENT));
$this->assertEquals(370, $file->spaceUsed());
// Test both the user and status.
$this->assertEquals(0, $file->spaceUsed(1, 0));
$this->assertEquals(0, $file->spaceUsed(1, FILE_STATUS_PERMANENT));
$this->assertEquals(0, $file->spaceUsed(1));
$this->assertEquals(1, $file->spaceUsed(2, 0));
$this->assertEquals(70, $file->spaceUsed(2, FILE_STATUS_PERMANENT));
$this->assertEquals(70, $file->spaceUsed(2));
$this->assertEquals(3, $file->spaceUsed(3, 0));
$this->assertEquals(300, $file->spaceUsed(3, FILE_STATUS_PERMANENT));
$this->assertEquals(300, $file->spaceUsed(3));
}
}
......@@ -82,9 +82,8 @@ public function testViewsHandlerRelationshipUserFileData() {
'filemime' => 'image/jpeg',
'created' => 1,
'changed' => 1,
'status' => FILE_STATUS_PERMANENT,
]);
$file->enforceIsNew();
$file->enforceIsNew()->setPermanent();
file_put_contents($file->getFileUri(), file_get_contents('core/tests/fixtures/files/image-1.png'));
$file->save();
......
......@@ -34,10 +34,10 @@ public function testNormalize() {
'filename' => 'test_1.txt',
'uri' => 'public://test_1.txt',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
];
// Create a new file entity.
$file = File::create($file_params);
$file->setPermanent();
file_put_contents($file->getFileUri(), 'hello world');
$file->save();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment