If there is only one revision of a node, and you are deleting this revision...an sql warning is shown.
warning: mysql_real_escape_string() expects parameter 1 to be string, array given in .../includes/database.mysql.inc on line 239.

You can reproduce this error:
1) Create a new node
2) Edit the node and create a new revision
3) Delete the just created revision.

The reason for this warning, is the empty array of revisions. If you replace the empty array with an empty string, the problem is solved!
I have wrote a simple check in the function node_revision_delete as shown below.
greetings!

/**
* Delete the revision with specified revision number.
*/
function node_revision_delete($nid, $revision) {
if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid));

unset($node->revisions[$revision]);

// if the array is empty, replace the array by an empty string.
// otherwise an sql warning will be showed!
if(count($node->revisions)>=0){
$node->revisions='';
}
node_save($node, array('nid', 'revisions'));

drupal_set_message(t('Deleted revision %revision of %title', array('%revision' => "#$revision", '%title' => theme('placeholder', $node->title))));
drupal_goto('node/'. $nid . (count($node->revisions) ? '/revisions' : ''));
}
}

Comments

Crell’s picture

Status: Needs review » Active

Thanks for the fix. This is not a proper patch, however. Please see http://drupal.org/diffandpatch for the sort of patch we need.

Is this a problem in both 4.6 and cvs? If so, please provide separate patches for each. Thanks.

Frenske’s picture

StatusFileSize
new706 bytes

Oh, yes.... well this is the patch for drupal 4.6.6. I will have a look to the current cvs version of drupal 4.6

dww’s picture

Assigned: Unassigned » dww
Status: Active » Needs review
StatusFileSize
new877 bytes

the previous patch was very broken. :( it would "fix" the SQL error by deleting all revisions of a node. ;) it also didn't follow the Drupal Coding Standards...

here's a new version that:

  • only converts the revisions array to an empty string if it's an empty array, which corrects the reported problem but but doesn't delete all revisions whenever deleting any of them
  • follows the coding standards

also, i tested 4.7 (cvs head) and this isn't a problem there. node revisions in 4.7 are totally different, so i'm not surprised this works there. however, there is a problem where after you delete the last revision, it tries to send you back to the revisions tab, which is now an invalid path since there are no revisions of the node. i've submitted a patch for this as a separate issue, node/55632.

if anyone else could review this patch and set to RTBC, that'd be great.

thanks,
-derek

lisa’s picture

I applied dww's patch to node.module in Drupal 4.6.6 and it seems to work. If I create a new revision, I can now choose to delete the revision. Revision is deleted and no error message is generated.

As a help to other newbies looking for the answer to this problem, here is how you apply the patch:

1. Copy delete_last revision.patch to your modules directory
2. From within the modules directory use this syntax:
patch node.module < delete_last revision.patch

Someone else should still review this patch.

lisa’s picture

I applied dww's patch to node.module in Drupal 4.6.6 and it seems to work. If I create a new revision, I can now choose to delete the revision. Revision is deleted and no error message is generated.

As a help to other newbies looking for the answer to this problem, here is how you apply the patch:

1. Copy delete_last revision.patch to your modules directory
2. From within the modules directory use this syntax:
patch node.module < delete_last revision.patch

Someone else should still review this patch.

magico’s picture

Version: 4.6.6 » 4.6.9
magico’s picture

Status: Needs review » Reviewed & tested by the community

It works as expected. Ready to be applied.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to DRUPAL-4-6.

Anonymous’s picture

Status: Fixed » Closed (fixed)