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.

Comments

Mark Theunissen’s picture

Status: Active » Needs review
StatusFileSize
new2.22 KB

Confirmed. The following line is the culprit:

// 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:

// Only rewrite the path on new files to be saved
if (is_array($file) && $file['new'] && !$file['remove']){

Patch attached.

lifepillar’s picture

I confirm that your patch fixes the problem (Drupal 6.10).

gourley’s picture

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).

markj’s picture

I can confirm it works with revisions created by node_save(), eg,

<?php
$node = node_submit($node);
$node_save($node);
?>
dugh’s picture

subscribe

NoRandom’s picture

It also solves the problem with Workflow 6.x-1.1.

berliner’s picture

subscribe

ChemAli’s picture

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).

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

So nothing dangerous here. Patch looks fine and seems rtbc to me.

agileware’s picture

Title: Upload Path and revisions: Fatal error: Cannot use object of type stdClass as array » PHP Fatal error: Cannot use object of type stdClass as array in uploadpath.module on line 36
StatusFileSize
new675 bytes

Patch works for me too.

Here is a new version of the patch that applies cleanly to 6.x-1.x-dev
and doesn't have the unnecessary line changes from the original patch.

Also, when it was happening for me it was not related to revisions at all. - So changing title

Note that in the current dev version the error is on is line 39.

agileware’s picture

Any chance this small patch can be committed, it's been a while and is still a problem.

Cheers!

mradcliffe’s picture

Ran into this issue as well while doing some node_save() on a $node object in a custom module.

Patch works for me.

xurubo93’s picture

Please commit this patch.

regards

Michel Poulain’s picture

Please commit this patch! It works for me too.