Krang::Trash - data broker for TrashBin CGI
use Krang::ClassLoader 'Trash';
# get a list of objects on the current user's workspace
@objects = pkg('Trash')->find();
# get just the first 10, sorting by url:
@objects = pkg('Trash')->find(limit => 10,
offset => 0,
order_by => 'url');
This module provides a find() method which returns all objects living
in the trashbin. These are not full-fledged Story/Media/Template
objects, just hashes containing what we need to fill the trashbin's
pager view.
@objects = Krang::Trash->find()$count = Krang::Trash->find(count => 1)register_find_sql()).
Since the returned objects do not share single ID-space, the standard
ids_only mode is not supported.
Available search options are:
pkg('Trash')->register_find_sql(object => $moniker, user_sensitive => 0, sql => $sql)find() method. It should be called in a BEGIN block!
The SQL select command forms a fassade, mapping asset fields to trash object fields. Order matters! All fields must be present, though they might contain the empty string (as the 'class' field in the example below.
Also assumed in the custom objects' database table is the presence of a boolean column named 'trashed', which is supposed to be set to true if the object currently lives in the trashbin.
Class: Krang::Mailing Table: mailing
BEGIN {
pkg('Trash')->register_find_sql(object => 'mailing', user_sensitive => 0, sql => <<SQL);
SELECT mailing_id AS id,
'mailing' AS type,
subject AS title,
'' AS class,
url AS url,
mailing_date AS date,
'' AS version,
someperm AS may_see,
otherperm AS may_edit,
1 AS linkto # format the URL as a link
FROM mailing
WHERE trashed = 1
SQL
}
pkg('Trash')->store(object => $story)pkg('Trash')->store(object => $media)pkg('Trash')->store(object => $template)pkg('Trash')->store(object => $other)trash() method.
pkg('Trash')->prune()This class method is currently called at the end of each object delete (i.e. when moving an object into the trash).
prune() to
permanently delete trashed objects!
pkg('Trash')->delete(object => $story)pkg('Trash')->delete(object => $media)pkg('Trash')->delete(object => $template)pkg('Trash')->delete(object => $other)delete().
pkg('Trash')->restore(object => $story)pkg('Trash')->restore(object => $media)pkg('Trash')->restore(object => $template)pkg('Trash')->restore(object => $other)untrash() that does the heavy lifting.
pkg('Trash')->remove(object => $object)untrash() and delete() methods.