This module should act like a trash can - whenever deleting something, it goes to the trash.
The way to do this would be a hook_nodeapi op='delete', hook_comment op='delete', etc, which inserts the objects into the trash table.

Then, you must be able to go to admin/content/trash, which shows all items in the trash bin, and be able to restore them, or empty the trash.

Items which must be supported:

  • Nodes (CCK too)
  • Views (form_alter on the delete form to add your own submit function)
  • Panels v2 (same as views)
  • Comments
  • Users

The module must work in Drupal 5 and Drupal 6, however the Drupal 6 version won't have Views and Panels.

Comments

dawehner’s picture

StatusFileSize
new3.59 KB

my current state:
Comments, Users, Views work perfect
Node: problems with the revisions & automatic deleted comments
Panel: nothing yet, but should be the sume like views

dawehner’s picture

StatusFileSize
new5.03 KB

i have a very big problem
my sql code for normal nodes doesn't work
i want to get all data from {node} of a certain nid
so
$result = db_query("SELECT * from {node} WHERE nid = %d", $node->nid);+
its called after hook_nodeapi $OP ="delete", so there should still be the table row, but is always no result

the rest:
comments,views,users works perfect:
panelpages, panelmini works also perfect
but problem with restore the page_views
and the node problem

rötzi’s picture

If you look at node_delete (http://api.drupal.org/api/function/node_delete/5) you see that the node is deleted from the database before the nodeapi hook is called. So once you are in hook_nodeapi('delete') the database entry is already gone. But you should have all the information in the $node object, so the query is not necessary.

How do you plan to save additional information of other modules?
For example if you have the 'profile' module enabled, you need to restore the profile fields of the user.

dawehner’s picture

i have no ideas for other modules yet, i will have to code it
but the problem is that each node is connected to several revisions, and these revisions are deleted BEFORE the $OP = "delete" is called
in the $node object is only the current revision

dawehner’s picture

StatusFileSize
new5.7 KB

so i managed to save the node revisions by using hook_form_alter

cwgordon7’s picture

@dereine—Coding everything yourself, assuming you could actually do it, would be a nightmare. Use API functions such as node_save or node_save_revision, etc., to do that sort of thing for you.

rötzi’s picture

If you use node_save you will need to make sure the database row for the node you want to restore already exists. If you pass a $node object to node_save which already has a node id, it will just do an UPDATE and not an INSERT.

For Drupal 6 there is a new drupal_write_record function which you should have a look at.

dawehner’s picture

yes thats definitive the problem : I think the node should be restored to his old nid
perhaps it's possible to connect hook_nodeapi $op="insert" with $op="load" or sth. like that to get all fields of a node
but i have no correct idea yet
or is there another possible solution for saving all fields?

dawehner’s picture

StatusFileSize
new4.47 KB

i found yet no real solution for the node/user/comment...ID problem for drupal5 so i used the _save functions to restore the different kind of data

kopo88’s picture

Here's a quick and simple solution that doesn't require a module:

  1. If you're not already using it, add the Workflow module and either create a new workflow or modify the one you're already using.
  2. Apply the Workflow to all content types you want to pass through a "trash bin."
  3. Create any standard states you might need, e.g "Awaiting review" and "Published."
  4. Create a state called "Awaiting deletion."
  5. For all roles, disallow deleting any node that's not in the "Awaiting deletion" state.For all non-admin roles, disallow viewing these nodes.
  6. Create a view that shows all nodes in the "Awaiting deletion" state. You can title this view "Trash Bin."
  7. Add the Views Bulk Operations module and enable deletions for this view.

Congratulations, you've just created a recycle bin.

Babalu’s picture

subscribing
D6 ?

Souvent22’s picture

To expand on kopo88's "recipie":

1. Create a "softdelete" module...
2. Implement hook_form_alter
3. Catch all the node_delete_confirm form_id's.

  if($form_id == 'node_delete_confirm') {
    $node = node_load($form['nid']['#value']);
    // Check to see the type of the node, and if its something we want to stop.
    if($node->type == 'blog') {
      unset($form['#submit']); // Take total control of the submit.
      $form['#submit']['module_softdelete_submit'] = array();
    }
  }

4. Set the workflow state programmatically.

  $node = node_load($nid);
  $node->status = 0; // Unpublish
  $node->workflow = variable_get('my_softdelete_wf_state', 'Awaiting Deletion');
  $node->workflow_comment = $comment;
  $node->workflow_scheduled = t('Immediately');
  node_save($node);

This allows one to let the users sill use the delete button, and see no difference in functionality. Use the "bulk operations" from views to give an admin the ability to delete content.
Obv, provide your own filtering, etc. in the hook_alter, but the info above should get one started.

mxmilkiib’s picture

subscribe