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' : ''));
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | node-4_6-delete_last_revision.patch | 877 bytes | dww |
| #2 | node_revision_delete.patch.txt | 706 bytes | Frenske |
Comments
Comment #1
Crell commentedThanks 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.
Comment #2
Frenske commentedOh, 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
Comment #3
dwwthe 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:
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
Comment #4
lisa commentedI 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.
Comment #5
lisa commentedI 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.patchSomeone else should still review this patch.
Comment #6
magico commentedComment #7
magico commentedIt works as expected. Ready to be applied.
Comment #8
dries commentedCommitted to DRUPAL-4-6.
Comment #9
(not verified) commented