Commit 6d54ed7a authored by alexpott's avatar alexpott
Browse files

Issue #1818568 by Berdir, das-peter: Convert files to the new Entity Field API.

parent db0104f4
......@@ -1156,22 +1156,22 @@ function file_save_upload($form_field_name, $validators = array(), $destination
if (!empty($extensions)) {
// Munge the filename to protect against possible malicious extension
// hiding within an unknown file type (ie: filename.html.foo).
$file->filename = file_munge_filename($file->filename, $extensions);
$file->setFilename(file_munge_filename($file->getFilename(), $extensions));
}
// Rename potentially executable files, to help prevent exploits (i.e. will
// rename filename.php.foo and filename.php to filename.php.foo.txt and
// filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads'
// evaluates to TRUE.
if (!config('system.file')->get('allow_insecure_uploads') && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
$file->filemime = 'text/plain';
$file->uri .= '.txt';
$file->filename .= '.txt';
if (!config('system.file')->get('allow_insecure_uploads') && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->getFilename()) && (substr($file->getFilename(), -4) != '.txt')) {
$file->setMimeType('text/plain');
$file->setFileUri($file->getFileUri() . '.txt');
$file->setFilename($file->getFilename() . '.txt');
// The .txt extension may not be in the allowed list of extensions. We have
// to add it here or else the file upload will fail.
if (!empty($extensions)) {
$validators['file_validate_extensions'][0] .= ' txt';
drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $file->filename)));
drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $file->getFilename())));
}
}
......@@ -1193,7 +1193,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
if (substr($destination, -1) != '/') {
$destination .= '/';
}
$file->destination = file_destination($destination . $file->filename, $replace);
$file->destination = file_destination($destination . $file->getFilename(), $replace);
// If file_destination() returns FALSE then $replace === FILE_EXISTS_ERROR and
// there's an existing file so we need to bail.
if ($file->destination === FALSE) {
......@@ -1210,7 +1210,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
// Check for errors.
if (!empty($errors)) {
$message = t('The specified file %name could not be uploaded.', array('%name' => $file->filename));
$message = t('The specified file %name could not be uploaded.', array('%name' => $file->getFilename()));
if (count($errors) > 1) {
$message .= theme('item_list', array('items' => $errors));
}
......@@ -1226,7 +1226,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
// directory. This overcomes open_basedir restrictions for future file
// operations.
$file->uri = $file->destination;
if (!drupal_move_uploaded_file($uploaded_files['files']['tmp_name'][$form_field_name][$i], $file->uri)) {
if (!drupal_move_uploaded_file($uploaded_files['files']['tmp_name'][$form_field_name][$i], $file->getFileUri())) {
form_set_error($form_field_name, t('File upload error. Could not move uploaded file.'));
watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
$files[$i] = FALSE;
......@@ -1234,14 +1234,14 @@ function file_save_upload($form_field_name, $validators = array(), $destination
}
// Set the permissions on the new file.
drupal_chmod($file->uri);
drupal_chmod($file->getFileUri());
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->uri));
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri()));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
$file->fid = $existing->id();
}
}
......
......@@ -157,7 +157,7 @@ public function submitForm(array &$form, array &$form_state) {
$data = '';
$validators = array('file_validate_extensions' => array('opml xml'));
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
$data = file_get_contents($file->uri);
$data = file_get_contents($file->getFileUri());
}
else {
// @todo Move this to a fetcher implementation.
......
......@@ -49,7 +49,7 @@ function hook_file_load($files) {
* This hook lets modules perform additional validation on files. They're able
* to report a failure by returning one or more error messages.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file entity being validated.
* @return
* An array of error messages. If there are no problems with the file return
......@@ -57,13 +57,13 @@ function hook_file_load($files) {
*
* @see file_validate()
*/
function hook_file_validate(Drupal\file\File $file) {
function hook_file_validate(Drupal\file\FileInterface $file) {
$errors = array();
if (empty($file->filename)) {
if (!$file->getFilename()) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
if (strlen($file->filename) > 255) {
if (strlen($file->getFilename()) > 255) {
$errors[] = t("The file's name exceeds the 255 characters limit. Please rename the file and try again.");
}
......@@ -77,10 +77,10 @@ function hook_file_validate(Drupal\file\File $file) {
* doesn't distinguish between files created as a result of a copy or those
* created by an upload.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file entity that is about to be created or updated.
*/
function hook_file_presave(Drupal\file\File $file) {
function hook_file_presave(Drupal\file\FileInterface $file) {
// Change the file timestamp to an hour prior.
$file->timestamp -= 3600;
}
......@@ -92,10 +92,10 @@ function hook_file_presave(Drupal\file\File $file) {
* doesn't distinguish between files created as a result of a copy or those
* created by an upload.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file that has been added.
*/
function hook_file_insert(Drupal\file\File $file) {
function hook_file_insert(Drupal\file\FileInterface $file) {
// Add a message to the log, if the file is a jpg
$validate = file_validate_extensions($file, 'jpg');
if (empty($validate)) {
......@@ -108,60 +108,57 @@ function hook_file_insert(Drupal\file\File $file) {
*
* This hook is called when an existing file is saved.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file that has just been updated.
*/
function hook_file_update(Drupal\file\File $file) {
$file_user = user_load($file->uid);
function hook_file_update(Drupal\file\FileInterface $file) {
// Make sure that the file name starts with the owner's user name.
if (strpos($file->filename, $file_user->name) !== 0) {
$old_filename = $file->filename;
$file->filename = $file_user->name . '_' . $file->filename;
if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
$old_filename = $file->getFilename();
$file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->filename)));
watchdog('file', t('%source has been renamed to %destination', array('%source' => $old_filename, '%destination' => $file->getFilename())));
}
}
/**
* Respond to a file that has been copied.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The newly copied file entity.
* @param Drupal\file\File $source
* @param \Drupal\file\FileInterface $source
* The original file before the copy.
*
* @see file_copy()
*/
function hook_file_copy(Drupal\file\File $file, Drupal\file\File $source) {
$file_user = user_load($file->uid);
function hook_file_copy(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) {
// Make sure that the file name starts with the owner's user name.
if (strpos($file->filename, $file_user->name) !== 0) {
$file->filename = $file_user->name . '_' . $file->filename;
if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
$file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
watchdog('file', t('Copied file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
}
}
/**
* Respond to a file that has been moved.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The updated file entity after the move.
* @param Drupal\file\File $source
* @param \Drupal\file\FileInterface $source
* The original file entity before the move.
*
* @see file_move()
*/
function hook_file_move(Drupal\file\File $file, Drupal\file\File $source) {
$file_user = user_load($file->uid);
function hook_file_move(Drupal\file\FileInterface $file, Drupal\file\FileInterface $source) {
// Make sure that the file name starts with the owner's user name.
if (strpos($file->filename, $file_user->name) !== 0) {
$file->filename = $file_user->name . '_' . $file->filename;
if (strpos($file->getFilename(), $file->getOwner()->name) !== 0) {
$file->setFilename($file->getOwner()->name . '_' . $file->getFilename());
$file->save();
watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->filename)));
watchdog('file', t('Moved file %source has been renamed to %destination', array('%source' => $source->filename, '%destination' => $file->getFilename())));
}
}
......@@ -171,16 +168,16 @@ function hook_file_move(Drupal\file\File $file, Drupal\file\File $source) {
* This hook is invoked when deleting a file before the file is removed from the
* filesystem and before its records are removed from the database.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file that is about to be deleted.
*
* @see hook_file_delete()
* @see Drupal\file\FileStorageController::delete()
* @see upload_file_delete()
*/
function hook_file_predelete(Drupal\file\File $file) {
function hook_file_predelete(Drupal\file\FileInterface $file) {
// Delete all information associated with the file.
db_delete('upload')->condition('fid', $file->fid)->execute();
db_delete('upload')->condition('fid', $file->id())->execute();
}
/**
......@@ -189,15 +186,15 @@ function hook_file_predelete(Drupal\file\File $file) {
* This hook is invoked after the file has been removed from
* the filesystem and after its records have been removed from the database.
*
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file that has just been deleted.
*
* @see hook_file_predelete()
* @see Drupal\file\FileStorageController::delete()
*/
function hook_file_delete(Drupal\file\File $file) {
function hook_file_delete(Drupal\file\FileInterface $file) {
// Delete all information associated with the file.
db_delete('upload')->condition('fid', $file->fid)->execute();
db_delete('upload')->condition('fid', $file->id())->execute();
}
/**
......@@ -209,9 +206,9 @@ function hook_file_delete(Drupal\file\File $file) {
*
* @param $field
* The field to which the file belongs.
* @param Drupal\Core\Entity\EntityInterface $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity which references the file.
* @param Drupal\file\File $file
* @param \Drupal\file\FileInterface $file
* The file entity that is being requested.
*
* @return
......@@ -221,7 +218,7 @@ function hook_file_delete(Drupal\file\File $file) {
*
* @see hook_field_access().
*/
function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\File $file) {
function hook_file_download_access($field, Drupal\Core\Entity\EntityInterface $entity, Drupal\file\FileInterface $file) {
if ($entity->entityType() == 'node') {
return node_access('view', $entity);
}
......
......@@ -211,7 +211,7 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l
$items[$id][$delta] = NULL;
}
else {
$items[$id][$delta] = array_merge($item, (array) $files[$item['fid']]);
$items[$id][$delta]['entity'] = $files[$item['fid']];
}
}
}
......@@ -419,7 +419,7 @@ function file_field_widget_multiple_count_validate($element, &$form_state, $form
$removed_names = array();
foreach ($removed_files as $fid) {
$file = file_load($fid);
$removed_names[] = $file->filename;
$removed_names[] = $file->getFilename();
}
drupal_set_message(
t(
......@@ -654,7 +654,7 @@ function theme_file_widget($variables) {
if (!empty($element['fids']['#value'])) {
// Add the file size after the file name.
$file = reset($element['#files']);
$element['file_' . $file->fid]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->filesize) . ')</span> ';
$element['file_' . $file->id()]['filename']['#markup'] .= ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
$output .= drupal_render_children($element);
$output .= '</div>';
......@@ -861,8 +861,8 @@ function theme_file_formatter_table($variables) {
$rows = array();
foreach ($variables['items'] as $delta => $item) {
$rows[] = array(
theme('file_link', array('file' => (object) $item)),
format_size($item['filesize']),
theme('file_link', array('file' => $item['entity'])),
format_size($item['entity']->getSize()),
);
}
......
......@@ -118,7 +118,7 @@ function file_load_multiple(array $fids = NULL, $reset = FALSE) {
* @param $reset
* Whether to reset the internal file_load_multiple() cache.
*
* @return Drupal\file\File
* @return \Drupal\file\FileInterface
* A file entity or FALSE if the file was not found.
*
* @see hook_file_load()
......@@ -175,34 +175,33 @@ function file_usage() {
*/
function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
if (($realpath = drupal_realpath($source->uri)) !== FALSE) {
watchdog('file', 'File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => $realpath, '%destination' => $destination));
if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
watchdog('file', 'File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
}
else {
watchdog('file', 'File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->uri, '%destination' => $destination));
watchdog('file', 'File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
}
drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
return FALSE;
}
if ($uri = file_unmanaged_copy($source->uri, $destination, $replace)) {
$file = clone $source;
$file->fid = NULL;
$file->uri = $uri;
$file->filename = drupal_basename($uri);
if ($uri = file_unmanaged_copy($source->getFileUri(), $destination, $replace)) {
$file = $source->createDuplicate();
$file->setFileUri($uri);
$file->setFilename(drupal_basename($uri));
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
$file->filename = $existing->filename;
$file->fid = $existing->id();
$file->setFilename($existing->getFilename());
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
$file->filename = drupal_basename($destination);
$file->setFilename(drupal_basename($destination));
}
$file->save();
......@@ -250,34 +249,34 @@ function file_copy(File $source, $destination = NULL, $replace = FILE_EXISTS_REN
*/
function file_move(File $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
if (($realpath = drupal_realpath($source->uri)) !== FALSE) {
watchdog('file', 'File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => $realpath, '%destination' => $destination));
if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
watchdog('file', 'File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination));
}
else {
watchdog('file', 'File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%destination' => $destination));
watchdog('file', 'File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->getFileUri(), '%destination' => $destination));
}
drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', array('%file' => $source->getFileUri())), 'error');
return FALSE;
}
if ($uri = file_unmanaged_move($source->uri, $destination, $replace)) {
if ($uri = file_unmanaged_move($source->getFileUri(), $destination, $replace)) {
$delete_source = FALSE;
$file = clone $source;
$file->uri = $uri;
$file->setFileUri($uri);
// If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$delete_source = TRUE;
$file->fid = $existing->fid;
$file->fid = $existing->id();
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
$file->filename = drupal_basename($destination);
$file->setFilename(drupal_basename($destination));
}
$file->save();
......@@ -342,10 +341,10 @@ function file_validate(File $file, $validators = array()) {
function file_validate_name_length(File $file) {
$errors = array();
if (empty($file->filename)) {
if (!$file->getFilename()) {
$errors[] = t("The file's name is empty. Please give a name to the file.");
}
if (strlen($file->filename) > 240) {
if (strlen($file->getFilename()) > 240) {
$errors[] = t("The file's name exceeds the 240 characters limit. Please rename the file and try again.");
}
return $errors;
......@@ -369,7 +368,7 @@ function file_validate_extensions(File $file, $extensions) {
$errors = array();
$regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $file->filename)) {
if (!preg_match($regex, $file->getFilename())) {
$errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions));
}
return $errors;
......@@ -397,13 +396,13 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
global $user;
$errors = array();
if ($file_limit && $file->filesize > $file_limit) {
$errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
if ($file_limit && $file->getSize() > $file_limit) {
$errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->getSize()), '%maxsize' => format_size($file_limit)));
}
// Save a query by only calling spaceUsed() when a limit is provided.
if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->uid) + $file->filesize) > $user_limit) {
$errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
if ($user_limit && (Drupal::entityManager()->getStorageController('file')->spaceUsed($user->uid) + $file->getSize()) > $user_limit) {
$errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->getSize()), '%quota' => format_size($user_limit)));
}
return $errors;
......@@ -423,7 +422,7 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
function file_validate_is_image(File $file) {
$errors = array();
$info = image_get_info($file->uri);
$info = image_get_info($file->getFileUri());
if (!$info || empty($info['extension'])) {
$errors[] = t('Only JPEG, PNG and GIF images are allowed.');
}
......@@ -458,13 +457,13 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi
$errors = array();
// Check first that the file is an image.
if ($info = image_get_info($file->uri)) {
if ($info = image_get_info($file->getFileUri())) {
if ($maximum_dimensions) {
// Check that it is smaller than the given dimensions.
list($width, $height) = explode('x', $maximum_dimensions);
if ($info['width'] > $width || $info['height'] > $height) {
// Try to resize the image to fit the dimensions.
if ($image = image_load($file->uri)) {
if ($image = image_load($file->getFileUri())) {
image_scale($image, $width, $height);
image_save($image);
$file->filesize = $image->info['file_size'];
......@@ -506,7 +505,7 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi
* unique.
* - FILE_EXISTS_ERROR - Do nothing and return FALSE.
*
* @return Drupal\file\File
* @return \Drupal\file\FileInterface
* A file entity, or FALSE on error.
*
* @see file_unmanaged_save_data()
......@@ -535,14 +534,14 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
$existing_files = entity_load_multiple_by_properties('file', array('uri' => $uri));
if (count($existing_files)) {
$existing = reset($existing_files);
$file->fid = $existing->fid;
$file->filename = $existing->filename;
$file->fid = $existing->id();
$file->setFilename($existing->getFilename());
}
}
// If we are renaming around an existing file (rather than a directory),
// use its basename for the filename.
elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
$file->filename = drupal_basename($destination);
$file->setFilename(drupal_basename($destination));
}
$file->save();
......@@ -562,12 +561,12 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
* \Symfony\Component\HttpFoundation\StreamedResponse.
*/
function file_get_content_headers(File $file) {
$name = mime_header_encode($file->filename);
$type = mime_header_encode($file->filemime);
$name = mime_header_encode($file->getFilename());
$type = mime_header_encode($file->getMimeType());
return array(
'Content-Type' => $type,
'Content-Length' => $file->filesize,
'Content-Length' => $file->getSize(),
'Cache-Control' => 'private',
);
}
......@@ -619,7 +618,7 @@ function file_file_download($uri, $field_type = 'file') {
foreach ($files as $item) {
// Since some database servers sometimes use a case-insensitive comparison
// by default, double check that the filename is an exact match.
if ($item->uri === $uri) {
if ($item->getFileUri() === $uri) {
$file = $item;
break;
}
......@@ -637,7 +636,7 @@ function file_file_download($uri, $field_type = 'file') {
// temporary files where the host entity has not yet been saved (for example,
// an image preview on a node/add form) in which case, allow download by the
// file's owner.
if (empty($references) && ($file->status == FILE_STATUS_PERMANENT || $file->uid != $user->uid)) {
if (empty($references) && ($file->isPermanent() || $file->getOwner()->id() != $user->uid)) {
return;
}
......@@ -709,15 +708,15 @@ function file_cron() {
if ($file = file_load($row->fid)) {
$references = file_usage()->listUsage($file);
if (empty($references)) {
if (file_exists($file->uri)) {
if (file_exists($file->getFileUri())) {
$file->delete();
}
else {
watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->uri), WATCHDOG_ERROR);
watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array('%path' => $file->getFileUri()), WATCHDOG_ERROR);
}
}
else {
watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->uri, '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array('%path' => $file->getFileUri(), '%modules' => implode(', ', array_keys($references))), WATCHDOG_INFO);
}
}
}
......@@ -1033,7 +1032,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
$fids = array();
foreach ($input['fids'] as $key => $fid) {
if ($file = file_load($fid)) {
$fids[] = $file->fid;
$fids[] = $file->id();
}
}
}
......@@ -1056,7 +1055,7 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
$fids = array();
foreach ($default_fids as $key => $fid) {
if ($file = file_load($fid)) {
$fids[] = $file->fid;
$fids[] = $file->id();
}
}
}
......@@ -1081,7 +1080,7 @@ function file_managed_file_validate(&$element, &$form_state) {
$fids = $element['fids']['#value'];
foreach ($fids as $fid) {
if ($file = file_load($fid)) {
if ($file->status == FILE_STATUS_PERMANENT) {
if ($file->isPermanent()) {
$references = file_usage()->listUsage($file);
if (empty($references)) {
form_error($element, t('The file used in the !name field may not be referenced.', array('!name' => $element['#title'])));
......@@ -1145,8 +1144,8 @@ function file_managed_file_submit($form, &$form_state) {
// If it's a temporary file we can safely remove it immediately, otherwise
// it's up to the implementing module to remove usages of files to have them
// removed.
if ($element['#files'][$fid] && $element['#files'][$fid]->status == 0) {