Upload Path and revisions: Fatal error: Cannot use object of type stdClass as array
druido - December 14, 2008 - 21:15
| Project: | Upload path |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I am using the core Upload module with Upload Path. I get the error in the subject every time I revert to a different revision of a node that has an attachment.
Fatal error: Cannot use object of type stdClass as array in /home/druido/www/drupal/sites/all/modules/uploadpath/uploadpath.module on line 36
The error does not seem to compromise anything, in the sense that the revision is corrected reverted when I go back in my browser.

#1
Confirmed. The following line is the culprit:
<?php// Only rewrite the path on new files to be saved
if ($file['new'] && !$file['remove']){
?>
$file is an object when reverting revisions, thus the error. Assuming that the logic in the comment is correct, we can safely add a further check to make sure that it's an array:
<?php// Only rewrite the path on new files to be saved
if (is_array($file) && $file['new'] && !$file['remove']){
?>
Patch attached.
#2
I confirm that your patch fixes the problem (Drupal 6.10).
#3
This problem also occurs with the workflow module when you try to change the state of a node with a file attached to it and upload path enabled. The patch fixes it in that case as well (Drupal 6.10).
#4
I can confirm it works with revisions created by node_save(), eg,
<?php$node = node_submit($node);
$node_save($node);
?>
#5
subscribe
#6
It also solves the problem with Workflow 6.x-1.1.
#7
subscribe
#8
This problem also occurs with the Fasttoggle module when you try to change the state of a node and UploadPath enabled. The patch fixes it in that case as well (Drupal 6.13).