Fatal error: Cannot use object of type stdClass as array on line 387
| Project: | Comment Upload |
| Version: | 6.x-1.0-alpha5 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
I'm using Comment Upload with Listhandler and Mailsave (all Recommended versions for Drupal 6 -- I'm using 6.11 -- as of 7/26/09).
Attachments aren't moving from the mailing list to the forum or from the forum to the mailing list. All other functionality seems to work.
When I send a message with an attachment to the mailing list, and then try to retrieve it using Mailhandler, this error is reported:
An error occurred. [Drupal_dir]/batch?id=55&op=do <br /> <b>Fatal error</b>: Cannot use object of type stdClass as array in <b>[Drupal_install_abs_path]\sites\all\modules\comment_upload\comment_upload.module</b> on line <b>387</b><br /> I tried changing some array references to object references, e.g., in line 387, I changed:
$file['remove']
to
$file->removeSo this function:
/**
* Save the changes made to attachments.
*
* @param array $comment
*/
function comment_upload_save($comment) {
if (!user_access('upload files to comments')) {
return;
}
if (!isset($comment['files']) || !is_array($comment['files'])) {
return;
}
foreach ($comment['files'] as $fid => $file) {
if (!empty($file['remove'])) {
comment_upload_delete_file($file);
}
if (!empty($file['new'])) {
db_query("INSERT INTO {comment_upload} (fid, cid, nid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $fid, $comment['cid'], $comment['nid'], $file['list'], $file['description'], $file['weight']);
$file = (object)$file;
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
db_query("UPDATE {comment_upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d", $file['list'], $file['description'], $file['weight'], $fid);
}
}
}Read like this:
/**
* Save the changes made to attachments.
*
* @param array $comment
*/
function comment_upload_save($comment) {
if (!user_access('upload files to comments')) {
return;
}
if (!isset($comment['files']) || !is_array($comment['files'])) {
return;
}
foreach ($comment['files'] as $fid => $file) {
if (!empty($file->remove)) {
comment_upload_delete_file($file);
}
if (!empty($file->new)) {
db_query("INSERT INTO {comment_upload} (fid, cid, nid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $fid, $comment['cid'], $comment['nid'], $file['list'], $file['description'], $file['weight']);
$file = (object)$file;
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
db_query("UPDATE {comment_upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d", $file->list, $file->description, $file->weight, $fid);
}
}
}That did eliminate the fatal errors, but attachments still aren't going in either direction (from the list to comments in the forum, or from forum comments to the list).
Any ideas on this? The Comment_Upload, Listhandler, Mailhandler, MailSave integration would be great to get working. Thank you.

#1
...Seem to have this working...
--To start -- the final code box above has some errors, use the code provided below instead.
Steps to reproduce:
1) In comment_upload.module, replace the function comment_upload_save with the function provided in the text box below. The only change is to replace array notation used to get data from $file with object notation.
2) Make the change to the Mailsave module described in this issue: http://drupal.org/node/297220
***
With those two changes, email sent to the mailbox I set up to receive mailing list email gets appropriately posted as forum comments by Listhandler, including attachments. I don't know if there's a way to get this working otherwise -- I haven't been able to. I've only tested with this, not deployed to production. Would appreciate hearing if it works for others (or if there's a better way to get the functionality).
/**
* Save the changes made to attachments.
*
* @param array $comment
*/
function comment_upload_save($comment) {
if (!user_access('upload files to comments')) {
return;
}
if (!isset($comment['files']) || !is_array($comment['files'])) {
return;
}
foreach ($comment['files'] as $fid => $file) {
if (!empty($file->remove)) {
comment_upload_delete_file($file);
}
if (!empty($file->new)) {
db_query("INSERT INTO {comment_upload} (fid, cid, nid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $fid, $comment['cid'], $comment['nid'], $file->list, $file->description, $file->weight);
$file = (object)$file;
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
db_query("UPDATE {comment_upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d", $file->list, $file->description, $file->weight, $fid);
}
}
}
Thanks
#2
Sorry, hadn't adequately tested -- when the change above is combined with the change suggested in http://drupal.org/node/297220 , links do appear at the bottom of comments, as they should, but they link to the sites/default/files directory, and the files are not being moved there. Instead, files are being left in the Drupal installation's root directory.
Can anyone help with this?
#3
Opened a new issue for the problem described in comment #2, and have a possible method of addressing it here: http://drupal.org/node/533602
Would really appreciate someone else's take on these...
#4
This is great - thanks for your work here. It's fantastic to think that we may, through mail2og and mail2web and this module finally be able to come close to replicating mailing list type functionality.
I am interested in this functionality working properly as well. I don't have a sandbox set up currently so am unable to test right away, but will do so soon.
Cheers,
Tobias
#5
Ok, I made at least one large error in my previous post. After some testing, discovered that it was very wrong to change these:
$file['list'], $file['description'], $file['weight']to these
$file->list, $file->description, $file->weightin retrospect, I should have known better.
Now, my (apparently working) edited function looks like this:
/**
* Save the changes made to attachments.
*
* @param array $comment
*/
function comment_upload_save($comment) {
if (!user_access('upload files to comments')) {
return;
}
if (!isset($comment['files']) || !is_array($comment['files'])) {
return;
}
foreach ($comment['files'] as $fid => $file) {
if (!empty($file->remove)) {
comment_upload_delete_file($file);
}
if (!empty($file->new)) {
db_query("INSERT INTO {comment_upload} (fid, cid, nid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $fid, $comment['cid'], $comment['nid'], $file['list'], $file['description'], $file['weight']);
$file = (object)$file;
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
db_query("UPDATE {comment_upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d", $file['list'], $file['description'], $file['weight'], $fid);
}
}
}
Would appreciate others' thoughts/observations. Thanks.
#6
Hello,
I was previously having the same issue until I found your (3) postings.
After making the changes you specified on October 23, I was still experiencing the same issue. I went ahead and made the modifications you specified on July 27, and everything appears to work correctly.
You stated that the change on July 27 was erroneous, but it seems that the erroneous change is the only change that will work with my site.
Why did you state that you had made an error? I have not seen anything horrible pop up, yet. I am waiting for it, though.
Thank you very much for the help you've provided the community,
-Matthew C Moss-
#7
Well, I think it seemed like a predictable error because it's a fairly substantial change to code I didn't understand all that well, and it ended up making that code not work. I'm still a little puzzled by the behavior though -- sometimes the attachments were showing up fine, sometimes they weren't. At this point (with the last change), they seem to be showing up correctly and can be unlisted or listed as expected.
It seems to me though, that there still may be an issue where once an attachment is sent to a thread in a comment, it appears in all additional comments on that thread. The remaining changed line from my suggested changes to address this issue is:
$file['remove']to
$file->remove
So, if things aren't being removed appropriately, that seems a likely place to look. Of course, without that change, the whole thing wasn't working. I'll be watching the issue for a while and will report back if I learn anything further.
#8
I started getting this error after upgrading a site to drupal 6. On drupal 5 I had listhandler, mailhandler, comment_upload, and mailsave working nicely with a mailing list / drupal forum.
So I went through your steps. This is what worked for me:
I tired the code in post #5 along with making the mailsave modification, I simply used the mailsave.module file posted: http://drupal.org/files/issues/mailsave.module.gz
I still got the error. So I tried the code from post #1 and I was able to download emails with attachments and links for the images were showing up at the bottom of forum posts created from mailing list messages. I did get a number of errors about images which I and number of messages came up about files being renamed to 'unnamed attachment'. Other than that it does appear to be working.
So to summarize what worked for me:
I made this change to comment_upload.module
/**
* Save the changes made to attachments.
*
* @param array $comment
*/
function comment_upload_save($comment) {
if (!user_access('upload files to comments')) {
return;
}
if (!isset($comment['files']) || !is_array($comment['files'])) {
return;
}
foreach ($comment['files'] as $fid => $file) {
if (!empty($file->remove)) {
comment_upload_delete_file($file);
}
if (!empty($file->new)) {
db_query("INSERT INTO {comment_upload} (fid, cid, nid, list, description, weight) VALUES (%d, %d, %d, %d, '%s', %d)", $fid, $comment['cid'], $comment['nid'], $file->list, $file->description, $file->weight);
$file = (object)$file;
file_set_status($file, FILE_STATUS_PERMANENT);
}
else {
db_query("UPDATE {comment_upload} SET list = %d, description = '%s', weight = %d WHERE fid = %d", $file->list, $file->description, $file->weight, $fid);
}
}
}
And used this mailsave.module file: http://drupal.org/files/issues/mailsave.module.gz
I attempted to make the change in http://drupal.org/node/533602 for 'attachments saving to root' but could not find this line in mailsave.module (using the mailsave.module file linked above).:
// Create temporary name/path for newly uploaded files.//if (!$dest) {
$dest = file_destination(file_create_path($file->filename), FILE_EXISTS_RENAME);
//}
Thanks to sjtout for getting into the code and linking all these issues linked together.
It would be awesome if there was some sort of "mailing-list-drupal-forum" module to replace this 'hack' to get mailing lists to work with drupal forums using so many different modules.
It has really been a hassle to get all these modules to play nice together. In addition to setting input filters for emails etc. AND then doing an upgrade to Drupal6... and discovering even more errors. fun fun.
I attached the mailsave.module and comment_upload.module files I used to get this working.
#9
Interesting -- thanks for adding the attachments. I'll be curious to learn whether you see the problem where attachments arriving via email on comments don't appear. That issue was what led me to return the db_query parameters to array notation (which, oddly, no longer provoked the fatal error). A behavior that seemed associated with being unable to change the setting for the 'list' checkbox for an attachment when editing a comment. Good luck with it.
#10
#11
Well, my site had this error on a Cron run:
Fatal error: Cannot use object of type stdClass as array in G:\wamp\www\boost\sites\all\modules\comment_upload\comment_upload.module on line 392
Not sure why it waited this long to have it. I returned line 392 to object notation, and the Cron succeeded. I'm expecting to see the problem with being unable to show attachments, but don't have time to test right now. This really feels like a bug rather than a feature request.
#12
Interop with mailsave & listhandler is a feature request for comment upload.
#13
That makes sense. It just seems odd that the error appears to be addressed by changing between array and object notation. That seems more relevant to php versioning or drupal versioning or something. I don't understand how mailsave and/or listsave could be changing the characteristics of objects used by comment upload (to make manipulation by a given operator work or not work) --it seems like the error we're reporting is an issue with the comment upload code itself, rather than with it's interaction with those other modules. The logic of the module seems to work, but there seem to be compatibility errors.
#14
I meant -- the logic seems to interact with the other modules well, but there seem to be -- maybe versioning? -- compatibility issues.