Commit 95e63c38 authored by catch's avatar catch

Issue #2251719 by sergeypavlenko, YesCT, chx, Pancho: Fixed Completely remove...

Issue #2251719 by sergeypavlenko, YesCT, chx, Pancho: Fixed Completely remove DRUPAL_MAXIMUM_TEMP_FILE_AGE.
parent aef08a5e
......@@ -35,7 +35,7 @@ public function retrieveTemporaryFiles() {
// of PHP. See http://drupal.org/node/352956.
return $this->database->query('SELECT fid FROM {' . $this->entityType->getBaseTable() . '} WHERE status <> :permanent AND changed < :changed', array(
':permanent' => FILE_STATUS_PERMANENT,
':changed' => REQUEST_TIME - DRUPAL_MAXIMUM_TEMP_FILE_AGE
':changed' => REQUEST_TIME - \Drupal::config('system.file')->get('temporary_maximum_age'),
));
}
}
......@@ -30,7 +30,10 @@ interface FileStorageInterface extends EntityStorageInterface {
public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT);
/**
* Retrieve temporary files that are older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
* Retrieves old temporary files.
*
* Get files older than the temporary maximum age,
* \Drupal::config('system.file')->get('temporary_maximum_age').
*
* @return array
* A list of files to be deleted.
......
<?php
/**
* @file
* Contains \Drupal\file\Tests\RetrieveTemporaryFilesTest.
*/
namespace Drupal\file\Tests;
/**
* Provides tests for retrieving temporary files.
*
* @see \Drupal\Core\Entity\ContentEntityDatabaseStorage::retrieveTemporaryFiles()
*/
class RetrieveTemporaryFilesTest extends FileManagedUnitTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Temporary files tests',
'description' => 'Tests the retrieveTemporaryFiles() function.',
'group' => 'File Managed API',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$max_age = $this->container->get('config.factory')->get('system.file')->get('temporary_maximum_age');
// Create an entry for the user with the date change.
$file_array = array('uid' => 2, 'uri' => 'public://example1.txt', 'status' => 2, 'changed' => REQUEST_TIME);
db_insert('file_managed')->fields($file_array)->execute();
// Create an entry for the user with an indication of the old date of the
// change.
$file_array = array('uid' => 2, 'uri' => 'public://example2.txt', 'status' => 2, 'changed' => REQUEST_TIME - ($max_age * 2));
db_insert('file_managed')->fields($file_array)->execute();
}
/**
* Tests finding stale files.
*/
function testRetrieveTemporaryFiles() {
$file_storage = $this->container->get('entity.manager')->getStorage('file');
$count_files = count($file_storage->retrieveTemporaryFiles()->fetchAssoc());
$this->assertEqual($count_files, 1);
}
}
<?php
/**
* @file
* Contains \Drupal\update\Tests\UpdateDeleteFileIfStaleTest.
*/
namespace Drupal\update\Tests;
/**
* Provides tests for update_delete_file_if_stale().
*/
class UpdateDeleteFileIfStaleTest extends UpdateTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('update');
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Deleting obsolete files tests.',
'description' => 'Tests the update_delete_file_if_stale() function.',
'group' => 'Update',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
}
/**
* Tests the deletion of stale files.
*/
function testUpdateDeleteFileIfStale() {
$file_name = file_unmanaged_save_data($this->randomName());
$this->assertNotNull($file_name);
// During testing the file change and the stale checking occurs in the same
// request, so the beginning of request will be before the file changes and
// REQUEST_TIME - $filectime is negative. Set the maximum age to a number
// even smaller than that.
$this->container->get('config.factory')
->get('system.file')
->set('temporary_maximum_age', -100000)
->save();
$file_path = drupal_realpath($file_name);
update_delete_file_if_stale($file_path);
$this->assertFalse(is_file($file_path));
}
}
......@@ -748,7 +748,9 @@ function update_clear_update_disk_cache() {
function update_delete_file_if_stale($path) {
if (file_exists($path)) {
$filectime = filectime($path);
if (REQUEST_TIME - $filectime > DRUPAL_MAXIMUM_TEMP_FILE_AGE || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
$max_age = \Drupal::config('system.file')->get('temporary_maximum_age');
if (REQUEST_TIME - $filectime > $max_age || (preg_match('/.*-dev\.(tar\.gz|zip)/i', $path) && REQUEST_TIME - $filectime > 300)) {
file_unmanaged_delete_recursive($path);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment