Converting comments between core and nodecomment looses file attachments. Fails converting back to core.

iva2k - June 29, 2009 - 01:57
Project:Node comments
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

Converting back to core comments fails with the following error:

An error occurred. /batch?id=44&op=do
Fatal error: Cannot use object of type stdClass as array in /sites/all/modules/comment_upload/comment_upload.module on line 387

#1

sjtout - July 24, 2009 - 21:24

I'm seeing this as well. I've got Mailhandler, Listhandler, MailSave and Comment Upload trying to work together. I see this error when I attempt to receive an email through Mailhandler that Listhandler will be adding as a comment to an already created forum node. The email does get processed, but if it has an attachment, the attachment is lost.

This is with Comment Upload 6.x-1.0-alpha5

Also:
Mailhandler 6.x-1.8
Listhandler 6.x-1.0
Mailsave 6.x-1.3

#2

merlinofchaos - August 10, 2009 - 23:04
Status:active» won't fix

Can you disable comment_upload.module and then try it? When the conversion is completely you can re-enable comment_upload. It's possible that it's expecting data that's not there when the comment is saved. I'm not sure there is much we can do to fix it. =(

#3

iva2k - August 12, 2009 - 04:43
Title:Converting back to core comments fails» Converting comments between core and nodecomment looses file attachments. Fails converting back to core.
Priority:normal» critical
Assigned to:Anonymous» iva2k
Status:won't fix» active

@merlinofchaos
Your suggestion helps - the conversion goes OK with disabled comment_upload.module. It is not a very robust solution though. In addition, conversion process looses all files attached to the comments, which is very destructive.

I will use this issue to track my progress on it, since I have few ideas on how to make it work.

First, I dug a little bit into the code, and made progress on plugging the error without disabling comment_upload.module. I figured that comment_upload.module stores files info as arrays, while upload.module stores files info as objects. I fixed that within the conversion process with two small pieces of code. (No patch yet - this code is not complete. just for illustration)

in function nodecomment_convert_batch_process() / file nodecomment.convert.inc add this:

  // Make comment_upload.module happy - convert each file entry to array instead of object.
      if (isset($comment->files) && count($comment->files)) {
        $new_files = array();
        foreach ($comment->files as $key => $file) {
          $new_files[$key] = (array)$file;
        }
        $comment->files = $new_files;
      }

before this:

      // Insert the new comment.
      $edit = (array) $comment;
      db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name, mail, homepage) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $edit['hostname'], $edit['timestamp'], $edit['status'], $edit['thread'], $edit['name'], $edit['mail'], $edit['homepage']);

and add this:

  // Make upload.module happy - convert each file entry to object instead of array.
      if (isset($node->files) && count($node->files)) {
        $new_files = array();
        foreach ($node->files as $key => $file) {
          $new_files[$key] = (object)$file;
        }
        $node->files = $new_files;
      }

before this:

      node_save($node);

Next, I will need to figure out how to deal with:

      node_invoke($node, 'delete');
      node_invoke_nodeapi($node, 'delete');

and
        comment_invoke_comment($item, 'delete');

so that the files are not erased but transferred to new comment format.

But that's for a later session...

#4

iva2k - August 12, 2009 - 06:49
Assigned to:iva2k» Anonymous
Status:active» needs review

I rolled a patch against latest -dev from CVS.

It works with the attached patch: file attachments are carried over from core comments/comment_upload.module to nodecomments/upload.module and back.

Please review for committing to 6.x.-2.x-dev.

AttachmentSize
nodecomment_convert_files_20090811.patch 3 KB

#5

iva2k - October 16, 2009 - 05:36

nag nag

Any chance of this being reviewed?

#6

merlinofchaos - October 22, 2009 - 18:00

Sorry, not one of my higher priorities. I'm keeping this on my radar, not sure when I will be able to get to it.

 
 

Drupal is a registered trademark of Dries Buytaert.