Browse Source

Tripal Views: API updates including delete all views integrations and rebuild integrations

Lacey Sanderson 11 years ago
parent
commit
e7ebff38b3

+ 34 - 0
tripal_views/api/tripal_views.api.inc

@@ -157,6 +157,37 @@ function tripal_views_is_lightest_priority_setup($setup_id, $table_name) {
 
 }
 
+/**
+ * Purpose: Deletes ALL Tripal Views Integrations.
+ */
+function tripal_views_delete_all_integrations() {
+
+  db_query("DELETE FROM {tripal_views}");
+  db_query("DELETE FROM {tripal_views_field}");
+  db_query("DELETE FROM {tripal_views_handlers}");
+  db_query("DELETE FROM {tripal_views_join}");
+
+  drupal_set_message("Successfully deleted all views integration.");
+
+}
+
+
+/**
+ * Rebuilds all the default integrations
+ *
+ * @param $delete_first
+ *   If TRUE then all integrations are first deleted.
+ */
+function tripal_views_rebuild_views_integrations($delete_first = FALSE) {
+
+  if ($delete_first) {
+    tripal_views_delete_all_integrations();
+  }
+
+  tripal_views_integrate_all_chado_tables();
+  drupal_set_message('Successfully rebuilt default Tripal Views Integrations');
+}
+
 /**
  * Add views integration records into the tripal_views* tables
  *
@@ -668,6 +699,9 @@ function tripal_views_get_integration_array_for_chado_table($table_name, $base_t
       if ($field_name == 'type_id' OR $field_name == 'cvterm_id') {
         $defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_cvterm';
       }
+      if (preg_match('/name/',$field_name)) {
+        $defn_array['fields'][$field_name]['handlers']['filter']['name'] = 'tripal_views_handler_filter_select_string';
+      }
     }
   }
 

+ 61 - 3
tripal_views/includes/tripal_views_integration.inc

@@ -18,7 +18,10 @@
 function tripal_views_integration_setup_list() {
   $output = '';
 
-  $output .=  l(t('Add a New Entry'), "admin/tripal/views/integration/new") ;
+  $output .= '<ul class="action-links">';
+  $output .=  '<li>' . l(t('Add a New Entry'), "admin/tripal/views-integration/new") . '</li>';
+  $output .=  '<li style="float: right;">' . l(t('Delete ALL Entries'), "admin/tripal/views-integration/delete-all/confirm") . '</li>';
+  $output .= '</ul>';
 
   $output .= '<p>' . t('The following tables are available for integration with Drupal Views. If '
     . 'a table is integrated more than once, then the setup with the lightest '
@@ -27,7 +30,6 @@ function tripal_views_integration_setup_list() {
     . 'Priorities range from -10 to +10  where a setup with -10 has '
     . 'greater precedent than any other and +10 has the least.') . '</p>';
 
-
   // Start with materialized views
   $output .= '<br /><h3>Legacy Materialized Views</h3>';
   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Legacy?', 'Priority', 'Comment');
@@ -57,7 +59,6 @@ function tripal_views_integration_setup_list() {
   }
   else {
     $output .= '<p>There are currently no Materialized Views defined. ';
-    $output .=  l(t('Add a New Entry'), "admin/tripal/views/integration/new") . '</p>';
 
   }
 
@@ -136,6 +137,63 @@ function tripal_views_integration_delete($setup_id) {
 
 }
 
+/**
+ * Purpose: Deletes ALL Tripal Views Integrations.  This
+ *   function is meant to be called from a menu item. After completion it
+ *   redirects the user to the views intergation page.
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_views_integration_delete_all_form ($form, $form_state) {
+
+  $form['extra'] = array(
+    '#type' => 'item',
+    '#markup' => t('This will REMOVE ALL views integrations (both custom and default) '
+      . 'from your website. This allows integrations to be rebuilt to new default '
+      . 'settings and is especially useful after an upgrade to the views integration system.'),
+  );
+
+  $form['description'] = array(
+    '#type' => 'item',
+    '#markup' => t('Are you sure you want to REMOVE ALL Views Integrations (including custom integrations) from your system?'),
+  );
+
+  $form['actions'] = array('#type' => 'actions');
+
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Confirm'),
+  );
+
+  $form['actions']['cancel'] = array(
+    '#type' => 'link',
+    '#title' => t('Cancel'),
+    '#href' => 'admin/tripal/views-integration/list',
+  );
+
+  // By default, render the form using theme_confirm_form().
+  if (!isset($form['#theme'])) {
+    $form['#theme'] = 'confirm_form';
+  }
+
+  return $form;
+}
+
+/**
+ * Purpose: Deletes ALL Tripal Views Integrations.  This
+ *   function is meant to be called from a menu item. After completion it
+ *   redirects the user to the views intergation page.
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_views_integration_delete_all_form_submit ($form, &$form_state) {
+
+  tripal_views_rebuild_views_integrations(TRUE);
+
+  $form_state['redirect'] = 'admin/tripal/views-integration/list';
+
+}
+
 /**
  * Purpose: defines the web form used for specifing the base table, joins and
  *   handlers when integrating a table with views.  This form is used for both

+ 12 - 2
tripal_views/tripal_views.module

@@ -68,6 +68,14 @@ function tripal_views_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  $items['admin/tripal/views-integration/delete-all/confirm'] = array(
+    'title' => 'Delete ALL Views Integration',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_views_integration_delete_all_form'),
+    'access arguments' => array('manage tripal_views_integration'),
+    'type' => MENU_CALLBACK,
+  );
+
   $items['admin/tripal/views-integration/import'] = array(
     'title' => 'Import Views Integration',
     'description' => 'Import a Tripal Views Integration from another site.',
@@ -121,8 +129,10 @@ function tripal_views_init() {
   // exist in Drupal 6
   $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
   $tripal_views = $tripal_views->fetchObject();
-  if (isset($tripal_views->has_rows)) {
-    tripal_views_integrate_all_chado_tables();
+  if (isset($tripal_views)) {
+    if (!$tripal_views->has_rows) {
+      tripal_views_rebuild_views_integrations();
+    }
   }
 }