Skip to content

Commit

Permalink
Fix usage of file_copy(), which does not update the file object by re…
Browse files Browse the repository at this point in the history
…ference, and seems to work better with a prescribed destination.
  • Loading branch information
becw committed Nov 30, 2015
1 parent 2c2c62a commit 357ef92
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,19 @@ public function findUserByName($userName)
*/
public function fileCreate($file)
{
$original = clone $file;

// Save the file.
file_copy($file);
$dest = file_build_uri(drupal_basename($file->uri));
$result = file_copy($file, $dest);

// Stash the file object for later cleanup.
if (!empty($file->fid)) {
$this->files[] = $file;
if (!empty($result->fid)) {
$this->files[] = $result;
}
else {
throw new \Exception(sprintf('File "%s" could not be copied from "%s" to "%s".', $original->filename, $original->uri, $file->uri));
throw new \Exception(sprintf('File "%s" could not be copied from "%s" to "%s".', $file->filename, $file->uri, $result->uri));
}

return $file;
return $result;
}

/**
Expand Down

0 comments on commit 357ef92

Please sign in to comment.