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

Mark Theunissen - March 4, 2009 - 13:34
Status:active» needs review

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.

AttachmentSize
uploadpath-revisions-346977-1.patch 2.22 KB

#2

druido - March 9, 2009 - 18:35

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

#3

gourley - April 9, 2009 - 12:13

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

markj - August 17, 2009 - 17:59

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

<?php
$node
= node_submit($node);
$node_save($node);
?>

#5

dugh - August 25, 2009 - 16:39

subscribe

#6

Macarro - October 22, 2009 - 11:13

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

#7

hadubard - October 27, 2009 - 19:21

subscribe

#8

ChemAli - November 17, 2009 - 11:20

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

 
 

Drupal is a registered trademark of Dries Buytaert.