Browse Source

Removes all nodes of type 'Blast Database' when module is uninstalled

E.Cannon 7 years ago
parent
commit
734d301968
1 changed files with 29 additions and 1 deletions
  1. 29 1
      blast_ui.install

+ 29 - 1
blast_ui.install

@@ -17,6 +17,34 @@ function blast_ui_install() {
    tripal_create_files_dir('tripal_blast');
 }
 
+/**
+ * Implements hook_uninstall().
+ */
+function blast_ui_uninstall() {
+  // Remove all nodes of type blastdb
+  
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', 'node')
+    // Restrict to BLASTDB nodes.
+    ->entityCondition('bundle', 'blastdb')
+    // Restrict to Published nodes.
+    ->propertyCondition('status', 1)
+    // Restrict to nodes the current user has permission to view.
+    ->addTag('node_access');
+  $entities = $query->execute();
+
+  // Get all BlastDB nodes and delete them
+  $nodes = node_load_multiple(array_keys($entities['node']));
+  foreach ($nodes as $node) {
+    print "Delete node " . $node->title . "\n";
+    $nrs = node_revision_list($node);
+    foreach ($nrs as $nr) {
+      node_revision_delete($nr->vid);
+    }
+    node_delete($node->nid);
+  }
+}
+
 /**
  * Implements hook_schema().
  * Create the blastdb database table for storing addditional info related to blastdb nodes.
@@ -24,7 +52,7 @@ function blast_ui_install() {
  * NOTE: This hook is called via Drupal magic during the installation process and no longer
  * needs to be called explicitly in hook_install().
  */
-function blast_ui_schema(){
+function blast_ui_schema() {
   // A table to keep extra information related to blastdb nodes.
   $schema['blastdb'] = array(
     'description' => t('The base table for blastdb node'),