Revert "Issue #2802803 by Berdir, AdamPS, Darren Oh, Munavijayalakshmi, jackbravo, slashrsm, mmbk, Dane Powell, LittleCoding, gapple, catch, wiifm, alexpott, quantumized, acbramley: Temporary files whose files are missing on the disk result in never-ending error log messages"
This reverts commit e4188e4dec.
			
			
				merge-requests/1119/head
			
			
		
							parent
							
								
									91dc88316b
								
							
						
					
					
						commit
						01efa20b62
					
				| 
						 | 
				
			
			@ -728,18 +728,13 @@ function file_cron() {
 | 
			
		|||
    foreach ($files as $file) {
 | 
			
		||||
      $references = \Drupal::service('file.usage')->listUsage($file);
 | 
			
		||||
      if (empty($references)) {
 | 
			
		||||
        if (!file_exists($file->getFileUri())) {
 | 
			
		||||
          if (!file_valid_uri($file->getFileUri())) {
 | 
			
		||||
            \Drupal::logger('file system')->warning('Temporary file "%path" that was deleted during garbage collection did not exist on the filesystem. This could be caused by a missing stream wrapper.', ['%path' => $file->getFileUri()]);
 | 
			
		||||
        if (file_exists($file->getFileUri())) {
 | 
			
		||||
          $file->delete();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            \Drupal::logger('file system')->warning('Temporary file "%path" that was deleted during garbage collection did not exist on the filesystem.', ['%path' => $file->getFileUri()]);
 | 
			
		||||
          \Drupal::logger('file system')->error('Could not delete temporary file "%path" during garbage collection', ['%path' => $file->getFileUri()]);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
        // Delete the file entity. If the file does not exist, this will
 | 
			
		||||
        // generate a second notice in the watchdog.
 | 
			
		||||
        $file->delete();
 | 
			
		||||
      }
 | 
			
		||||
      else {
 | 
			
		||||
        \Drupal::logger('file system')->info('Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', ['%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references))]);
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,29 +77,4 @@ class DeleteTest extends FileManagedUnitTestBase {
 | 
			
		|||
    $this->assertFalse(File::load($file->id()), 'File was removed from the database.');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Tries to run cron deletion on file deleted from the file-system.
 | 
			
		||||
   */
 | 
			
		||||
  public function testCronDeleteNonExistingTemporary() {
 | 
			
		||||
    $file = $this->createFile();
 | 
			
		||||
    // Delete the file, but leave it in the file_managed table.
 | 
			
		||||
    \Drupal::service('file_system')->delete($file->getFileUri());
 | 
			
		||||
    $this->assertFalse(file_exists($file->getFileUri()), 'File is deleted from the filesystem.');
 | 
			
		||||
    $this->assertTrue(File::load($file->id()), 'File exist in file_managed table');
 | 
			
		||||
 | 
			
		||||
    // Call file_cron() to clean up the file. Make sure the changed timestamp
 | 
			
		||||
    // of the file is older than the system.file.temporary_maximum_age
 | 
			
		||||
    // configuration value.
 | 
			
		||||
    \Drupal::database()->update('file_managed')
 | 
			
		||||
      ->fields([
 | 
			
		||||
        'changed' => \Drupal::time()->getRequestTime() - ($this->config('system.file')->get('temporary_maximum_age') + 1),
 | 
			
		||||
      ])
 | 
			
		||||
      ->condition('fid', $file->id())
 | 
			
		||||
      ->execute();
 | 
			
		||||
    \Drupal::service('cron')->run();
 | 
			
		||||
    file_test_reset();
 | 
			
		||||
 | 
			
		||||
    $this->assertFalse(File::load($file->id()), 'File was removed from the database.');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue