[development] deletion API summary, question
Larry Garfield
larry at garfieldtech.com
Fri Jul 21 23:14:48 UTC 2006
On Friday 21 July 2006 10:58, Chad Phillips -- Apartment Lines wrote:
> in working on the trashbin patch, i discovered that it's helpful to
> think of deletions as happening in packages. when you delete a node,
> you don't just delete something from the node table--there are
> related node tables, then hook_delete calls, then nodeapi delete
> calls (and possibly other calls initiated from the last two in that
> list). deletions in drupal proceed from the top down, recursing until
> all items are deleted. that's what i'm calling a package.
>
> my current work is based on that viewpoint. package deletions are
> started with a call to a helper function (called
> drupal_delete_package at the moment), all relevant deletion
> operations are passed into the package via drupal_delete, and then
> packages are deleted via another helper function
> (drupal_delete_execute).
>
> once a package is compiled, there are two hooks that are called:
>
> hook_delete_pre -- this is an opportunity for modules to throw
> objections to a package deletion. any module calling this hook will
> have access to the information in the entire deletion package, and
> can throw two kinds of objections: confirm and abort.
>
> hook_delete_execute -- this is an opportunity for modules to perform
> any last minute operations before the package is deleted. for
> example, a trashbin module would use this hook to store metadata
> about the package deletion.
>
> workflow is as follows:
*snip*
In OO circles, this is known as the Command Pattern, and is effectively THE
way to handle "undo" operations. In an OO system, you don't do an action.
You instantiate a command object for said action with the data it needs, then
call ->execute() on it and push it onto a stack. To undo, you simply pop off
the stack and call ->undo(). The object itself still "knows" how to undo
itself.
What you're calling a package sounds to me like a command object. The single
command "Delete node 123" has a whole bunch of things inside it that have to
be done (delete/trash from various tables, run hooks, delete/move files on
disk, etc.)
Now I am NOT bringing back the "we should use OO classes and objects" debate,
nosir. :-) I'm just wondering if there's some way we could leverage that
conceptual encapsulation here.
--
Larry Garfield AIM: LOLG42
larry at garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
More information about the development
mailing list