Browse Source

Fixed problems with upgrade from T2 to T3

Stephen Ficklin 8 years ago
parent
commit
014b28ae8a

+ 11 - 0
tripal/api/tripal.entities.api.inc

@@ -322,6 +322,17 @@ function tripal_create_bundle($args, &$error = '') {
       $function = $module . '_bundle_postcreate';
       $function($bundle);
     }
+
+    // Finally set admin perimssions for the content type:
+//     $roles = user_roles();
+//     $admin_rid = variable_get('user_admin_role');
+//     $perms = user_role_permissions(array($admin_rid));
+//     dpm($perms);
+//     foreach ($perms[$admin_rid] as $perm => $value) {
+//       $perms[$admin_rid][$perm] = TRUE;
+//     }
+//     user_role_change_permissions($admin_rid, $perms[$admin_rid]);
+
   }
   catch (Exception $e) {
     $transaction->rollback();

+ 8 - 3
tripal/tripal.module

@@ -286,15 +286,18 @@ function tripal_permission() {
   $permissions = array(
     'administer tripal' => array(
       'title' => t('Administer Tripal'),
-      'description' => t('Allow the user to access administrative pages of Tripal. This includes management of jobs, the storage systems, extensions and the controlled vocabularies.')
+      'description' => t('Allow the user to access administrative pages of Tripal. This includes management of jobs, the storage systems, extensions and the controlled vocabularies.'),
+      'restrict access' => TRUE,
     ),
     'access tripal content overview' => array(
       'title' => t('Access the Tripal content overview page'),
-      'description' => t('Get an overview of all Tripal content')
+      'description' => t('Get an overview of all Tripal content'),
+      'restrict access' => TRUE,
     ),
     'manage tripal content types' => array(
       'title' => t('Manage Tripal content types'),
       'description' => t('Allows the user to create, update and delete Tripal content types.'),
+      'restrict access' => TRUE,
     ),
     'view dev helps' => array(
       'title' => t('View Developer Hints'),
@@ -304,7 +307,6 @@ function tripal_permission() {
           be disabled once developers are accustomed to these hints.'),
       'restrict access' => TRUE,
     ),
-
   );
 
   // Add permissions for each content type.
@@ -317,14 +319,17 @@ function tripal_permission() {
     $permissions['create ' . $bundle->name] = array(
       'title' => t('%label: Create Content', array('%label' => $bundle->label)),
       'description' => t('Allow the user to create %label content', array('%label' => $bundle->label)),
+      'restrict access' => TRUE,
     );
     $permissions['edit ' . $bundle->name] = array(
       'title' => t('%label: Edit Content', array('%label' => $bundle->label)),
       'description' => t('Allow the user to edit %label content', array('%label' => $bundle->label)),
+      'restrict access' => TRUE,
     );
     $permissions['delete ' . $bundle->name] = array(
       'title' => t('%label: Delete Content', array('%label' => $bundle->label)),
       'description' => t('Allow the user to delete %label content', array('%label' => $bundle->label)),
+      'restrict access' => TRUE,
     );
   }
   return $permissions;

+ 11 - 1
tripal_chado/includes/tripal_chado.setup.inc

@@ -74,38 +74,48 @@ function tripal_chado_load_ontologies() {
       'name' => 'Relationship Ontology (legacy)',
       'path' => '{tripal_chado}/files/legacy_ro.obo',
       'auto_load' => FALSE,
+      'cv_name' => 'ro'
     ),
     array(
       'name' => 'Gene Ontology',
       'path' => 'http://purl.obolibrary.org/obo/go.obo',
       'auto_load' => FALSE,
+      'cv_name' => 'cellualar_component'
     ),
     array(
       'name' => 'Taxonomic Rank',
       'path' => 'http://purl.obolibrary.org/obo/taxrank.obo',
       'auto_load' => TRUE,
+      'cv_name' => 'taxrank'
     ),
     array(
       'name' => 'Tripal Contact',
       'path' => '{tripal_chado}/files/tcontact.obo',
       'auto_load' => TRUE,
+      'cv_name' => 'tripal_contact'
     ),
     array(
       'name' => 'Tripal Publication',
       'path' => '{tripal_chado}/files/tpub.obo',
       'auto_load' => TRUE,
+      'cv_name' => 'tripal_pub'
     ),
     array(
       'name' => 'Sequence Ontology',
       'path' => 'http://purl.obolibrary.org/obo/so.obo',
       'auto_load' => TRUE,
+      'cv_name' => 'sequence'
     ),
 
   );
   for ($i = 0; $i < count($ontologies); $i++) {
     $obo_id = tripal_insert_obo($ontologies[$i]['name'], $ontologies[$i]['path']);
     if ($ontologies[$i]['auto_load'] == TRUE) {
-      tripal_chado_load_obo_v1_2_id($obo_id);
+      // Only load ontolgogies that are not already in the cv table.
+      $cv = tripal_get_cv(array('name' => $ontologies[$i]['cv_name']));
+      if (!$cv) {
+        tripal_chado_load_obo_v1_2_id($obo_id);
+      }
     }
   }
 }

+ 1 - 0
tripal_chado/tripal_chado.info

@@ -15,3 +15,4 @@ stylesheets[all][] = theme/css/tripal_chado.css
 dependencies[] = tripal
 dependencies[] = date
 dependencies[] = image
+dependencies[] = tripal_chado_views

+ 0 - 1
tripal_chado_views/tripal_chado_views.info

@@ -18,4 +18,3 @@ files[] = views/handlers/tripal_views_handler_field_aggregate.inc
 
 dependencies[] = views
 dependencies[] = tripal
-dependencies[] = tripal_chado

+ 147 - 20
tripal_chado_views/tripal_chado_views.install

@@ -4,26 +4,6 @@
  * Functions related to installing/uninstalling this module
  */
 
-/**
- * Implementation of hook_requirements().
- *
- * @ingroup tripal_chado_views
- */
-function tripal_chado_views_requirements($phase) {
-  $requirements = array();
-  if ($phase == 'install') {
-    // make sure chado is installed
-    if (!$GLOBALS["chado_is_installed"]) {
-      $requirements ['tripal_chado_views'] = array(
-        'title' => "tripal_chado_views",
-        'value' => "ERROR: Chado must be installed before this module can be enabled",
-        'severity' => REQUIREMENT_ERROR,
-      );
-    }
-  }
-  return $requirements;
-}
-
 /**
  * Implementation of hook_install().
  *
@@ -42,6 +22,21 @@ function tripal_chado_views_install() {
  * @ingroup tripal_chado_views
  */
 function tripal_chado_views_schema() {
+  // If Tripal v2 is already installed, then when the module is first enabled
+  // after an upgade, the installation of this module will try and recreate
+  // some of the tables created with tripal_core and the installation will fail.
+  // Therefore, we need to temporarily move those tables out of the way, let
+  // the module install and then move them back.
+  $migrated = variable_get('tripal_v2_upgrade_v3_check_chado_views', FALSE);
+  if (!$migrated) {
+    try {
+      tripal_chado_views_upgrade_v2_v3_pre_enable();
+      variable_set('tripal_v2_upgrade_v3_check_chado_views', TRUE);
+    }
+    catch(Exception $e) {
+      watchdog_exception('tripal_chado_views', $e);
+    }
+  }
   $schema = tripal_chado_views_get_schemas();
   return $schema;
 }
@@ -65,6 +60,18 @@ function tripal_chado_views_get_schemas() {
   return $schema;
 }
 
+/**
+ *
+ */
+function tripal_chado_views_enable() {
+  // If Tripal v2 is already installed, then when the module is first enabled
+  // after an upgade, the installation of this module will try and recreate
+  // some of the tables created with tripal_view and the installation will fail.
+  // Therefore, the tables were temporarily moved out of the way to preserve
+  // the data. Now we'll move them back.
+  tripal_chado_views_upgrade_v2_v3_enable();
+}
+
 /**
  * Describe the Tripal Views Schema
  *
@@ -297,3 +304,123 @@ function tripal_chado_views_views_schema() {
 
   return $schema;
 }
+
+
+/**
+ * This function should be executed only one time during upgrade of v2 to v3.
+ */
+function tripal_chado_views_upgrade_v2_v3_pre_enable() {
+  // If Tripal v2 is already installed, then when the module is first enabled
+  // after an upgade, the installation of this module will try and recreate
+  // some of the tables created with tripal_views and the installation will fail.
+  // Therefore, we need to temporarily move those tables out of the way, let
+  // the module install and then move them back.
+
+  if (db_table_exists('tripal_views')) {
+    // Move the tripal_mviews table out of the way.
+    $sql = "ALTER TABLE tripal_views RENAME TO tripal_views2";
+    db_query($sql);
+    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_views_pkey'")->fetchField()) {
+      $sql = "ALTER INDEX tripal_views_pkey RENAME TO tripal_views_pkey2";
+    }
+    else {
+      $sql = "CREATE UNIQUE INDEX tripal_views_pkey2 ON tripal_views2 USING btree (setup_id)";
+    }
+    db_query($sql);
+    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_views_priority_idx'")->fetchField()) {
+      $sql = "ALTER INDEX tripal_views_priority_idx RENAME TO tripal_views_priority_idx2";
+    }
+    else {
+      $sql = "CREATE UNIQUE INDEX tripal_views_priority_idx2 ON tripal_views2 USING btree (table_name, priority)";
+    }
+    db_query($sql);
+  }
+
+
+  if (db_table_exists('tripal_views_field')) {
+    // Move the tripal_mviews table out of the way.
+    $sql = "ALTER TABLE tripal_views_field RENAME TO tripal_views_field2";
+    db_query($sql);
+    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_views_field_pkey'")->fetchField()) {
+      $sql = "ALTER INDEX tripal_views_field_pkey RENAME TO tripal_views_field_pkey2";
+    }
+    else {
+      $sql = "CREATE UNIQUE INDEX tripal_views_field_pkey2 ON tripal_views_field2 USING btree (setup_id, column_name)";
+    }
+    db_query($sql);
+  }
+
+
+  if (db_table_exists('tripal_views_handlers')) {
+    // Move the tripal_mviews table out of the way.
+    $sql = "ALTER TABLE tripal_views_handlers RENAME TO tripal_views_handlers2";
+    db_query($sql);
+    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_views_handlers_pkey'")->fetchField()) {
+      $sql = "ALTER INDEX tripal_views_handlers_pkey RENAME TO tripal_views_handlers_pkey2";
+    }
+    else {
+      $sql = "CREATE UNIQUE INDEX tripal_views_handlers_pkey2 ON tripal_views_handlers2 USING btree (handler_id)";
+    }
+    db_query($sql);
+  }
+
+  if (db_table_exists('tripal_views_join')) {
+    // Move the tripal_mviews table out of the way.
+    $sql = "ALTER TABLE tripal_views_join RENAME TO tripal_views_join2";
+    db_query($sql);
+    if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_views_join_pkey'")->fetchField()) {
+      $sql = "ALTER INDEX tripal_views_join_pkey RENAME TO tripal_views_join_pkey2";
+    }
+    else {
+      $sql = "CREATE UNIQUE INDEX tripal_views_join_pkey2 ON tripal_views_join2 USING btree (view_join_id)";
+    }
+    db_query($sql);
+  }
+}
+/**
+ * This function should be executed only one time during upgrade of v2 to v3.
+ */
+function tripal_chado_views_upgrade_v2_v3_enable() {
+  // If Tripal v2 is already installed, the installation of this module
+  // will try and recreate some of the tables created with tripal_views and the
+  // installation will fail.  Therefore, in the install we renamed it. Now
+  // we want to move it back.
+  if (db_table_exists('tripal_views2')) {
+    // tripal_mviews
+    $sql = "DROP TABLE tripal_views";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_views2 RENAME to tripal_views";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_views_pkey2 RENAME TO tripal_views_pkey";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_views_priority_idx2 RENAME TO tripal_views_priority_idx";
+    db_query($sql);
+  }
+  if (db_table_exists('tripal_views_field2')) {
+    // tripal_mviews
+    $sql = "DROP TABLE tripal_views_field";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_views_field2 RENAME to tripal_views_field";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_views_field_pkey2 RENAME TO tripal_views_field_pkey";
+    db_query($sql);
+  }
+  if (db_table_exists('tripal_views_handlers2')) {
+    // tripal_mviews
+    $sql = "DROP TABLE tripal_views_handlers";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_views_handlers2 RENAME to tripal_views_handlers";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_views_handlers_pkey2 RENAME TO tripal_views_handlers_pkey";
+    db_query($sql);
+  }
+  if (db_table_exists('tripal_views_join2')) {
+    // tripal_mviews
+    $sql = "DROP TABLE tripal_views_join";
+    db_query($sql);
+    $sql = "ALTER TABLE tripal_views_join2 RENAME to tripal_views_join";
+    db_query($sql);
+    $sql = "ALTER INDEX tripal_views_join_pkey2 RENAME TO tripal_views_join_pkey";
+    db_query($sql);
+  }
+}