node_delete on module specific node
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/
Hi, You won't be able to the complete cleanup yourself -- what about existing views for example? -- and deleting nodes en masse is a recipe for catastrophe. Just IMO. Regards NK
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/
The question isn't *how* to delete them. The question is *should* we delete them. It does seem a little presumptuous to just delete all of the user-entered content. On the other hand, we can't really uninstall the schema if we are leaving the nodes -- that just leaves a heap of semi-functional (or non-functional) detritus. I'm imagining irate users who try re-installing the module only to discover that they have lost hundreds of quiz question nodes. On the other hand, uninstalling the schema (which, for quiz, includes tables for fields that augment the standard node fields) will cripple the nodes anyway. If that is going to cause irritation, then we might as well just delete the entire node. So the question is quite simply this: Should modules that provide their own content types delete all content of said types when the module is uninstalled? I'm remembering a particularly frustrating experience trying to uninstall a desktop application. The uninstaller was broken, and I had all kinds of mostly broken junk left on my system that I couldn't get rid of. I would hate to impose that experience on any Drupal user. As chx points out, removing all of the content may leave a site with broken views. As sivaji points out, it can mess with menus and other Drupal structures as well. So we have cases where removing nodes is going to have negative side-effects. And then, again, we have the case where we leave the nodes, but remove the module-specific data that is stored in the module-specific tables. That, too, leaves Drupal broken. So which kind of broken do we want? Matt On Tue, Apr 28, 2009 at 4:12 PM, Charlie Gordon <cwgordon7@gmail.com> wrote:
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/
On Apr 28, 2009, at 7:07 PM, Matt wrote:
I'm imagining irate users who try re-installing the module only to discover that they have lost hundreds of quiz question nodes. On the other hand, uninstalling the schema (which, for quiz, includes tables for fields that augment the standard node fields) will cripple the nodes anyway. If that is going to cause irritation, then we might as well just delete the entire node.
[snip]
And then, again, we have the case where we leave the nodes, but remove the module-specific data that is stored in the module-specific tables. That, too, leaves Drupal broken.
So which kind of broken do we want?
Neither. If you are really using Drupal's APIs properly, the amount of breakage is rather small. Here's a poll node I made: http://img.skitch.com/20090429-c13tjq8uijniq4twrxrxxxkdxd.png Here's the same poll node after turning off the poll module: http://img.skitch.com/20090429-kpkhegfackipiqbdjas26hqcud.png Not too bad. The only error I could find was from attempting to edit the poll. If you are disabling modules on your site and not smart enough to go and delete or unpublish the content created, I don't know if that's something we should watch for. It's not inconceivable that a user could disable or un-install a module unintentionally, so I think core has already adopted the best approach here. -Mike __________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
We're not talking about *disabled* modules. We're talking about *uninstalled* modules.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
That's not "neither" -- if there is still breakage, it is (by definition) broken. Quiz, like many other modules, has tight integration with views and other modules. Once I start deleting things upon uninstallation, I have all kinds of new issues to worry about. What do I do about that view of quiz nodes? Do I start scanning the Views and attempting to alter or delete those? (Earl, don't kill me. That was rhetorical.) There are many issues closely wrapped up here, but again, we're talking about what should be deleted when the module is uninstalled (Uninstalled -- not disabled. I'd be an idiot to delete content when a module was merely disabled.) Matt On Tue, Apr 28, 2009 at 9:35 PM, Michael Prasuhn <mike@mikeyp.net> wrote:
On Apr 28, 2009, at 7:07 PM, Matt wrote:
I'm imagining irate users who try re-installing the module only to discover that they have lost hundreds of quiz question nodes. On the other hand, uninstalling the schema (which, for quiz, includes tables for fields that augment the standard node fields) will cripple the nodes anyway. If that is going to cause irritation, then we might as well just delete the entire node.
[snip]
And then, again, we have the case where we leave the nodes, but remove the module-specific data that is stored in the module-specific tables. That, too, leaves Drupal broken.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
Here's a poll node I made: http://img.skitch.com/20090429-c13tjq8uijniq4twrxrxxxkdxd.png
Here's the same poll node after turning off the poll module: http://img.skitch.com/20090429-kpkhegfackipiqbdjas26hqcud.png
Not too bad. The only error I could find was from attempting to edit the poll.
If you are disabling modules on your site and not smart enough to go and delete or unpublish the content created, I don't know if that's something we should watch for. It's not inconceivable that a user could disable or un-install a module unintentionally, so I think core has already adopted the best approach here.
-Mike
__________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
Perhaps warning the user that they have N nodes of the content type supported by the module which is about to be uninstalled would be one idea? ..chris On Tue, Apr 28, 2009 at 9:44 PM, Matt <matt@aleph-null.tv> wrote:
We're not talking about *disabled* modules. We're talking about *uninstalled* modules.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
That's not "neither" -- if there is still breakage, it is (by definition) broken.
Quiz, like many other modules, has tight integration with views and other modules. Once I start deleting things upon uninstallation, I have all kinds of new issues to worry about. What do I do about that view of quiz nodes? Do I start scanning the Views and attempting to alter or delete those? (Earl, don't kill me. That was rhetorical.)
There are many issues closely wrapped up here, but again, we're talking about what should be deleted when the module is uninstalled (Uninstalled -- not disabled. I'd be an idiot to delete content when a module was merely disabled.)
Matt
On Tue, Apr 28, 2009 at 9:35 PM, Michael Prasuhn <mike@mikeyp.net> wrote:
On Apr 28, 2009, at 7:07 PM, Matt wrote:
I'm imagining irate users who try re-installing the module only to discover that they have lost hundreds of quiz question nodes. On the other hand, uninstalling the schema (which, for quiz, includes tables for fields that augment the standard node fields) will cripple the nodes anyway. If that is going to cause irritation, then we might as well just delete the entire node.
[snip]
And then, again, we have the case where we leave the nodes, but remove the module-specific data that is stored in the module-specific tables. That, too, leaves Drupal broken.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
Here's a poll node I made: http://img.skitch.com/20090429-c13tjq8uijniq4twrxrxxxkdxd.png
Here's the same poll node after turning off the poll module: http://img.skitch.com/20090429-kpkhegfackipiqbdjas26hqcud.png
Not too bad. The only error I could find was from attempting to edit the poll.
If you are disabling modules on your site and not smart enough to go and delete or unpublish the content created, I don't know if that's something we should watch for. It's not inconceivable that a user could disable or un-install a module unintentionally, so I think core has already adopted the best approach here.
-Mike
__________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
2009/4/29 Chris Johnson <cxjohnson@gmail.com>:
Perhaps warning the user that they have N nodes of the content type supported by the module which is about to be uninstalled would be one idea?
That's exactly what core does when deleting a custom content type: "Warning:</strong> there are currently @count %type posts on your site. They may not be able to be displayed or edited correctly, once you have removed this content type." So I guess modules doing the same thing on uninstall is a good practice. Henrique
..chris
On Tue, Apr 28, 2009 at 9:44 PM, Matt <matt@aleph-null.tv> wrote:
We're not talking about *disabled* modules. We're talking about *uninstalled* modules.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
That's not "neither" -- if there is still breakage, it is (by definition) broken.
Quiz, like many other modules, has tight integration with views and other modules. Once I start deleting things upon uninstallation, I have all kinds of new issues to worry about. What do I do about that view of quiz nodes? Do I start scanning the Views and attempting to alter or delete those? (Earl, don't kill me. That was rhetorical.)
There are many issues closely wrapped up here, but again, we're talking about what should be deleted when the module is uninstalled (Uninstalled -- not disabled. I'd be an idiot to delete content when a module was merely disabled.)
Matt
On Tue, Apr 28, 2009 at 9:35 PM, Michael Prasuhn <mike@mikeyp.net> wrote:
On Apr 28, 2009, at 7:07 PM, Matt wrote:
I'm imagining irate users who try re-installing the module only to discover that they have lost hundreds of quiz question nodes. On the other hand, uninstalling the schema (which, for quiz, includes tables for fields that augment the standard node fields) will cripple the nodes anyway. If that is going to cause irritation, then we might as well just delete the entire node.
[snip]
And then, again, we have the case where we leave the nodes, but remove the module-specific data that is stored in the module-specific tables. That, too, leaves Drupal broken.
So which kind of broken do we want?
Neither.
If you are really using Drupal's APIs properly, the amount of breakage is rather small.
Here's a poll node I made: http://img.skitch.com/20090429-c13tjq8uijniq4twrxrxxxkdxd.png
Here's the same poll node after turning off the poll module: http://img.skitch.com/20090429-kpkhegfackipiqbdjas26hqcud.png
Not too bad. The only error I could find was from attempting to edit the poll.
If you are disabling modules on your site and not smart enough to go and delete or unpublish the content created, I don't know if that's something we should watch for. It's not inconceivable that a user could disable or un-install a module unintentionally, so I think core has already adopted the best approach here.
-Mike
__________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net
On 29/04/2009, at 1:40 PM, Henrique Recidive wrote:
2009/4/29 Chris Johnson <cxjohnson@gmail.com>:
Perhaps warning the user that they have N nodes of the content type supported by the module which is about to be uninstalled would be one idea?
That's exactly what core does when deleting a custom content type:
"Warning:</strong> there are currently @count %type posts on your site. They may not be able to be displayed or edited correctly, once you have removed this content type."
So I guess modules doing the same thing on uninstall is a good practice.
Could also be helpful to have a link in that message to admin/content/ node with the type=<content_type_to_be_deleted> filter set so that they can easily review the impact/scope of their change. Regards, Nik
On Wed, Apr 29, 2009 at 10:29 AM, Nik Derewianka <nik@artofmultimedia.com.au> wrote:
"Warning:</strong> there are currently @count %type posts on your site. They may not be able to be displayed or edited correctly, once you have removed this content type."
So I guess modules doing the same thing on uninstall is a good practice.
Could also be helpful to have a link in that message to admin/content/node with the type=<content_type_to_be_deleted> filter set so that they can easily review the impact/scope of their change.
Thanks we like to go with this idea, *no* node_delete on uninstall :P -- Thanks a lot ----------------------------------------- http://ubuntuslave.blogspot.com/
Check how Delete All does it http://drupal.org/project/delete_all -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting. Simplicity is prerequisite for reliability. -- Edsger W.Dijkstra Simplicity is the ultimate sophistication. -- Leonardo da Vinci
IMHO, if you want to see a really good node module in action, check the FAQ module, which IIRC does delete its nodes on uninstall. Nancy E. Wichmann, PMP Injustice anywhere is a threat to justice everywhere. - Martin L. King, Jr. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org]On Behalf Of sivaji j.g Sent: Tuesday, April 28, 2009 4:58 PM To: development@drupal.org Subject: [development] node_delete on module specific node 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/ No virus found in this outgoing message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.12.6/2084 - Release Date: 4/28/2009 6:15 AM
participants (10)
-
Charlie Gordon -
Chris Johnson -
Henrique Recidive -
Karoly Negyesi -
Khalid Baheyeldin -
Matt -
Michael Prasuhn -
Nancy Wichmann -
Nik Derewianka -
sivaji j.g