Commit e7ac5c58 authored by webchick's avatar webchick

#308434 by drewish, dopry, quicksketch, aaron, jhedstrom, and friends: Massive...

#308434 by drewish, dopry, quicksketch, aaron, jhedstrom, and friends: Massive file.inc cleanup aaaaaand... tests! Yay! :D
parent 1806af90
This diff is collapsed.
......@@ -385,12 +385,12 @@ function blogapi_metaweblog_new_media_object($blogid, $username, $password, $fil
return blogapi_error(t('No file sent.'));
}
if (!$file = file_save_data($data, $name)) {
if (!$filepath = file_save_data($data, $name)) {
return blogapi_error(t('Error storing file.'));
}
// Return the successful result.
return array('url' => file_create_url($file), 'struct');
return array('url' => file_create_url($filepath), 'struct');
}
/**
* Blogging API callback. Returns a list of the taxonomy terms that can be
......
......@@ -435,8 +435,8 @@ function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
* Save the rewritten stylesheet to disk.
*/
function _color_save_stylesheet($file, $style, &$paths) {
file_save_data($style, $file, FILE_EXISTS_REPLACE);
$paths['files'][] = $file;
$filepath = file_save_data($style, $file, FILE_EXISTS_REPLACE);
$paths['files'][] = $filepath;
// Set standard file permissions for webserver-generated files.
@chmod($file, 0664);
......
......@@ -338,9 +338,9 @@ function system_theme_settings(&$form_state, $key = '') {
// The image was saved using file_save_upload() and was added to the
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
if (file_copy($file, $filename, FILE_EXISTS_REPLACE)) {
if ($filepath = file_copy($file->filepath, $filename, FILE_EXISTS_REPLACE)) {
$_POST['default_logo'] = 0;
$_POST['logo_path'] = $file->filepath;
$_POST['logo_path'] = $filepath;
$_POST['toggle_logo'] = 1;
}
}
......@@ -353,9 +353,9 @@ function system_theme_settings(&$form_state, $key = '') {
// The image was saved using file_save_upload() and was added to the
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
if (file_copy($file, $filename)) {
if ($filepath = file_copy($file->filepath, $filename, FILE_EXISTS_REPLACE)) {
$_POST['default_favicon'] = 0;
$_POST['favicon_path'] = $file->filepath;
$_POST['favicon_path'] = $filepath;
$_POST['toggle_favicon'] = 1;
}
}
......
......@@ -629,7 +629,7 @@ function system_schema() {
'description' => t('Stores information for uploaded files.'),
'fields' => array(
'fid' => array(
'description' => t('Primary Key: Unique files ID.'),
'description' => t('File ID.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
......@@ -642,7 +642,7 @@ function system_schema() {
'default' => 0,
),
'filename' => array(
'description' => t('Name of the file.'),
'description' => t('Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -656,7 +656,7 @@ function system_schema() {
'default' => '',
),
'filemime' => array(
'description' => t('The file MIME type.'),
'description' => t("The file's MIME type."),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
......@@ -670,7 +670,7 @@ function system_schema() {
'default' => 0,
),
'status' => array(
'description' => t('A flag indicating whether file is temporary (1) or permanent (0).'),
'description' => t('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.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
......
......@@ -420,13 +420,12 @@ function upload_save(&$node) {
// Create a new revision, or associate a new file needed.
if (!empty($node->old_vid) || isset($_SESSION['upload_files'][$fid])) {
db_query("INSERT INTO {upload} (fid, nid, vid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $file->fid, $node->nid, $node->vid, $file->list, $file->description, $file->weight);
file_set_status($file, FILE_STATUS_PERMANENT);
}
// Update existing revision.
else {
db_query("UPDATE {upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d AND vid = %d", $file->list, $file->description, $file->weight, $file->fid, $node->vid);
file_set_status($file, FILE_STATUS_PERMANENT);
}
file_set_status($file, FILE_STATUS_PERMANENT);
}
// Empty the session storage after save. We use this variable to track files
// that haven't been related to the node yet.
......
......@@ -106,7 +106,7 @@ class UploadTestCase extends DrupalWebTestCase {
// Attempt to upload .txt file when .test is only extension allowed.
$this->uploadFile($node, $files[0], FALSE);
$this->assertRaw(t('The selected file %name could not be uploaded. Only files with the following extensions are allowed: %files-allowed.', array('%name' => basename($files[0]), '%files-allowed' => $settings['upload_extensions'])), 'File '. $files[0] . ' was not allowed to be uploaded');
$this->assertRaw(t('The specified file %name could not be uploaded. Only files with the following extensions are allowed: %files-allowed.', array('%name' => basename($files[0]), '%files-allowed' => $settings['upload_extensions'])), 'File '. $files[0] . ' was not allowed to be uploaded');
// Attempt to upload .test file when .test is only extension allowed.
$this->uploadFile($node, $files[1]);
......@@ -143,7 +143,7 @@ class UploadTestCase extends DrupalWebTestCase {
$filename = basename($file);
$filesize = format_size($info['size']);
$maxsize = format_size(parse_size(($settings['upload_uploadsize'] * 1024) . 'KB')); // Won't parse decimals.
$this->assertRaw(t('The selected file %name could not be uploaded. The file is %filesize exceeding the maximum file size of %maxsize.', array('%name' => $filename, '%filesize' => $filesize, '%maxsize' => $maxsize)), t('File upload was blocked since it was larger than maxsize.'));
$this->assertRaw(t('The specified file %name could not be uploaded. The file is %filesize exceeding the maximum file size of %maxsize.', array('%name' => $filename, '%filesize' => $filesize, '%maxsize' => $maxsize)), t('File upload was blocked since it was larger than maxsize.'));
}
function setUploadSettings($settings, $rid = NULL) {
......
......@@ -414,9 +414,9 @@ function user_validate_picture(&$form, &$form_state) {
// files table as a temporary file. We'll make a copy and let the garbage
// collector delete the original upload.
$info = image_get_info($file->filepath);
$destination = variable_get('user_picture_path', 'pictures') . '/picture-' . $form['#uid'] . '.' . $info['extension'];
if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
$form_state['values']['picture'] = $file->filepath;
$destination = file_create_path(variable_get('user_picture_path', 'pictures') . '/picture-' . $form['#uid'] . '.' . $info['extension']);
if ($filepath = file_copy($file->filepath, $destination, FILE_EXISTS_REPLACE)) {
$form_state['values']['picture'] = $filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures'))));
......
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