The file_move() function takes the source by reference and, in certain cases, replaces it with the filepath. In the case where the file cannot be moved due to improper permissions being set, the $video object gets replaced with the filepath.

Consequently, when the watchdog() call is made using $video->filepath in the message, an error results because $video is no longer an object, it's a string. This also means that the call to change the conversion status to FAILED fails, and so it's stuck as ACTIVE.

CommentFileSizeAuthor
#1 active-after-failure-1421540-1.patch670 byteskevin.dutra

Comments

kevin.dutra’s picture

Status: Active » Needs review
StatusFileSize
new670 bytes

Attaching a patch.

Jorrit’s picture

As far as I know, the $video is not replaced, but the filepath property is changed. This change is actually necessary for the functionality of the video module, because that change is saved to the database in the drupal_write_record() call just below the code you've changed.

Can you point to the line in the file_move() / file_copy() code that changes the type of the $file argument from object to string?

kevin.dutra’s picture

It's in file_copy(), line 242:

234  function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
235    $dest = file_create_path($dest);
236
237    $directory = $dest;
238    $basename = file_check_path($directory);
239
240    // Make sure we at least have a valid directory.
241    if ($basename === FALSE) {
242      $source = is_object($source) ? $source->filepath : $source;   <-- here's the problem
243      drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error');
244      watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR);
245      return 0;
246    }
...
Jorrit’s picture

Status: Needs review » Fixed

Thanks for your quick reply. It almost looks like a bug in the Drupal code, because it is very bad when a param gets changed from object to string. I have changed the code similar like you suggested to work around this problem, but while making sure the right path is saved to the database.

Fixed in branch 6.x-4.x and 6.x-5.x, thanks for reporting!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.