Entry Trash is a Extension that will move an entry upon delete to the a trash, with all their associated data. From here you can view the entries and you can restore or delete the entries entirely from the database.
By using the Entry Trash, you never lost your entry data entirely or accidentally by deleting.
Make sure your system meets the minimum requirements:
The Entry Trah module is intend to save your deleted entries, with their associated data, to a Trash. This way you never lost your entry data entirely or accidentally by deleting.
When the user is deleting some entries on the 'content edit' page, the Trash module is intercepting the delete action, before the entries got deleted. In this action the Trash module will collect all data, associated with the entry and copy this data to the Trash. When this is done ExpressionEngine will delete the data as usually, so that the 'selected' entries got deleted form the entry database. In fact, the entry or entries and their data are copied to the trash before they deleted from the entry database.
When some entries are deleted, the user can see the deleted entries in the Trash CP. From here the user can restore the entry by simply clicking on the 'restore' button.
When the user hit the 'restore' button, the Trash module will re-insert the entry with their associated data. In fact, the Trash module will insert this entry as a new entry (a new entry_id is created)
To delete an entry permanently, you can hit the 'delete' button in the Trash CP. The entry, with all associated data will be deleted from the Trash module. There is no going back.date proces, by clicking on the "module update" buttondule page and trigger the update proces, by clicking on the "module update" buttonoces, by clicking on the "module update" button
A lot of modules use their own table in the database to keep their own data in one place. Take a look at the module 'Channel Images' from DevDemon. This module extend the entry functionality with the use of 'multiple' images in a brilliant way (http://devot-ee.com/add-ons/channel-files).
To accomplish this task they created their own table exp_channel_files
and exp_channel_files_download_log
to save their data to those tables in the database.
With no modification to the Trash functionality, all data of this module 'and many other addons' will be gone 'deleted' when you delete/restore an entry from the Trash.
Thats why the Trash Module comes with a couple of hooks to hook into the Trash functionality.
To hook into this functionality, you can use the entry_trash_add_to_trash
hook that will be called right after the delete action.
function entry_trash_add_to_trash($entry_id, $entry_trash)
{
//add your table also to the trash
$entry_trash->add_entry_to_trash($entry_id, 'your_table');
$entry_trash->add_entry_to_trash($entry_id, 'your_second_table');
//preform additional functions to save for example associated files
}
The above function is the hook function. It will receive as first param the entry_id
and second the entry_trash
object. With the entry_trash
object you can call the method add_entry_to_trash
to copy all data from one table with the specified entry_id to the trash table.
The Trash module self will query that table for the entry_id
.
After that, you have to do your own stuff to save for example associated files. To take Channel Images as example again; they have to keep the associated images on disk instead of deleting the images. When the user delete an entry from the Trash, Channel Images have to delete the images as well.
When an entry is restored from the Trash, the hook entry_trash_restore_from_trash
will be called. The developer can hook into this function to restore their data also.
function entry_trash_restore_from_trash($new_entry_id, $old_entry_id)
{
//preform your handlings for your module
}
The above function is the hook function. It will receive the new_entry_id
and the old_entry_id
. As you may know the trash will not restore the entry by its original entry_id
, but will create a new entry instead. This due some avoid conflicts with some default tables of ExpressionEngine.
To take Channel Images again as example, DevDemon have to use this hook to store all of their associated files to this new_entry_id
instead of the old_entry_id
.
When an entry got deleted from the trash, the hook entry_trash_delete_from_trash
got called. The developer can hook into this function to delete their own custom data (e.g. files, not the records from the Trash table, this will be handled by the Trash module)
function entry_trash_delete_from_trash($entry_id, $associated_data)
{
//preform your handlings for your module
}
The above function is the hook function. It will receive the original entry_id
and a associated_data array. The associated_data array will hold all data associated with the entry.
To take Channel Images again as example, DevDemon have to use this hook to delete the files from the disk.
When you are not quite sure if the entry can be restored (or partially). You can hit the 'test' button in the delete dialog. The system will check if you can restore the entry, and if you are losing some data.
Because the Trash module will only work out of the box with the native ExpressionEngine modules, it is limited in supporting other third party addons. Below is a list of addons that are supported and tested with the Trash module.
(Added in v.1.0)
This hook is triggered when an entry got moved to the trash
if ($this->EE->extensions->active_hook('entry_trash_add_to_trash') === TRUE)
{
$this->EE->extensions->call('entry_trash_add_to_trash', $entry_id, $this->EE->entry_trash);
}
(Added in v.1.0)
This hook is triggered when an entry got deleted from the trash
if ($this->EE->extensions->active_hook('entry_trash_delete_from_trash') === TRUE)
{
$this->EE->extensions->call('entry_trash_delete_from_trash', $entry_id, $associated_data);
}
(Added in v.1.0)
This hook is triggered when an entry got restored from the Trash to the Entry database
if ($this->EE->extensions->active_hook('entry_trash_restore_from_trash') === TRUE)
{
$this->EE->extensions->call('entry_trash_restore_from_trash', $new_entry_id, $old_entry_id);
}