Commit 86aa636c authored by Dries's avatar Dries

- Patch #353207 by CitizenKane and drewish: cleaned up the FILE_STATUS_TEMPORARY field.

parent b3649703
......@@ -20,9 +20,10 @@
* - filepath - Path of the file relative to Drupal root.
* - filemime - The file's MIME type.
* - filesize - The size of the file in bytes.
* - status - A bitmapped field indicating the status of the file the least
* sigifigant bit indicates temporary (1) or permanent (0). Temporary files
* older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.
* - status - A bitmapped field indicating the status of the file. The first 8
* bits are reserved for Drupal core. The least sigifigant bit indicates
* temporary (0) or permanent (1). Temporary files older than
* DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during cron runs.
* - timestamp - UNIX timestamp for the date the file was added to the database.
*/
......@@ -68,19 +69,10 @@
define('FILE_EXISTS_ERROR', 2);
/**
* File status -- File has been temporarily saved to the {files} tables.
*
* Drupal's file garbage collection will delete the file and remove it from the
* files table after a set period of time.
*/
define('FILE_STATUS_TEMPORARY', 0);
/**
* File status -- File has been permanently saved to the {files} tables.
*
* If you wish to add custom statuses for use by contrib modules please expand
* as binary flags and consider the first 8 bits reserved.
* (0,1,2,4,8,16,32,64,128).
* File status -- This bit in the status indicates that the file is permanent
* and should not be deleted during file garbage collection process. Temporary
* files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during cron
* runs.
*/
define('FILE_STATUS_PERMANENT', 1);
......@@ -854,7 +846,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
// Begin building file object.
$file = new stdClass();
$file->uid = $user->uid;
$file->status = FILE_STATUS_TEMPORARY;
$file->status = 0;
$file->filename = file_munge_filename(trim(basename($_FILES['files']['name'][$source]), '.'), $extensions);
$file->filepath = $_FILES['files']['tmp_name'][$source];
$file->filemime = file_get_mimetype($file->filename);
......@@ -1138,7 +1130,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
$file->filename = basename($file->filepath);
$file->filemime = file_get_mimetype($file->filepath);
$file->uid = $user->uid;
$file->status = FILE_STATUS_PERMANENT;
$file->status |= FILE_STATUS_PERMANENT;
return file_save($file);
}
return FALSE;
......@@ -1758,7 +1750,6 @@ function file_get_mimetype($filename, $mapping = NULL) {
return 'application/octet-stream';
}
/**
* @} End of "defgroup file".
*/
......@@ -86,7 +86,7 @@ class FileTestCase extends DrupalWebTestCase {
$file->uid = 1;
$file->timestamp = REQUEST_TIME;
$file->filesize = filesize($file->filepath);
$file->status = FILE_STATUS_TEMPORARY;
$file->status = 0;
$this->assertNotIdentical(drupal_write_record('files', $file), FALSE, t('The file was added to the database.'));
return $file;
......
......@@ -263,12 +263,12 @@ class CronRunTestCase extends DrupalWebTestCase {
// Temporary file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$temp_old = file_save_data('');
db_query('UPDATE {files} SET status = :status, timestamp = :timestamp WHERE fid = :fid', array(':status' => FILE_STATUS_TEMPORARY, ':timestamp' => 1, ':fid' => $temp_old->fid));
db_query('UPDATE {files} SET status = :status, timestamp = :timestamp WHERE fid = :fid', array(':status' => 0, ':timestamp' => 1, ':fid' => $temp_old->fid));
$this->assertTrue(file_exists($temp_old->filepath), t('Old temp file was created correctly.'));
// Temporary file that is less than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$temp_new = file_save_data('');
db_query('UPDATE {files} SET status = :status WHERE fid = :fid', array(':status' => FILE_STATUS_TEMPORARY, ':fid' => $temp_new->fid));
db_query('UPDATE {files} SET status = :status WHERE fid = :fid', array(':status' => 0, ':fid' => $temp_new->fid));
$this->assertTrue(file_exists($temp_new->filepath), t('New temp file was created correctly.'));
// Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
......
......@@ -528,7 +528,7 @@ function upload_save(&$node) {
->condition('vid', $node->vid, '=')
->execute();
}
$file->status &= FILE_STATUS_PERMANENT;
$file->status |= FILE_STATUS_PERMANENT;
$file = file_save($file);
}
}
......
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