[development] node_delete on module specific node
Charlie Gordon
cwgordon7 at gmail.com
Tue Apr 28 21:12:39 UTC 2009
In order to delete nodes of a certain type (say, "quiz"), you can
execute a database query of the following form:
$result = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'quiz');
while ($node = db_fetch_object($result)) {
node_delete($node->nid);
}
However, this will encounter several scaling problems for sites with
many quiz nodes. You may want to investigate using the batch API for
something of this scale.
On the other hand, you probably shouldn't be deleting the nodes quiz
module created - "uninstalling" a module means removing any module
settings or data stored within the module: core poll module, for
example, does not delete its nodes upon uninstalling. You seem to be
aware of this in your message, and express concern that quiz nodes
promoted to the front page still exist; I would argue that it's not the
quiz module's place to be handling this problem.
This opens up a larger debate over whether node-type modules should
delete their own nodes upon deletion. In this case, I'd advise following
core's example and not worrying about orphaned quiz nodes.
-Charlie
sivaji j.g wrote:
> Hello folks
>
> I am a gsoc student working on quiz module. Quiz module treats quiz
> and its question types (multichoice, true/false etc) as a Drupal
> nodes. I would like to know whether i can delete a nodes specific to
> quiz module in hook_uninstall. My mentor and current maintainer of
> quiz module mbutcher is not sure about this. I have already asked this
> question in #drupal and came to know that core modules never deletes
> thier node with type story, page etc but nobody is sure about nodes
> specific modules.
>
> If you suggest me to leave quiz nodes untouched like core modules
> imagine the situation where i have some primary links to quiz nodes
> and quiz nodes promoted to front page they remains active even if i
> uninstall quiz module, how should i handle this situation ? or shall i
> unpublish the quiz nodes to tackle this situation ?
>
>
>
> --
> Thanks a lot
> -----------------------------------------
> http://ubuntuslave.blogspot.com/
>
More information about the development
mailing list