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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | trash.tar_.gz | 4.47 KB | dawehner |
| #5 | trash.tar.gz | 5.7 KB | dawehner |
| #2 | trash.tar.gz | 5.03 KB | dawehner |
| #1 | trash.tar_.gz | 3.59 KB | dawehner |
Comments
Comment #1
dawehnermy 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
Comment #2
dawehneri 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
Comment #3
rötzi commentedIf 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.
Comment #4
dawehneri 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
Comment #5
dawehnerso i managed to save the node revisions by using hook_form_alter
Comment #6
cwgordon7 commented@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.
Comment #7
rötzi commentedIf 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.
Comment #8
dawehneryes 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?
Comment #9
dawehneri 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
Comment #10
kopo88 commentedHere's a quick and simple solution that doesn't require a module:
Congratulations, you've just created a recycle bin.
Comment #11
Babalu commentedsubscribing
D6 ?
Comment #12
Souvent22 commentedTo 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.
4. Set the workflow state programmatically.
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.
Comment #13
mxmilkiib commentedsubscribe