| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 | 
							- <?php
 
- /**
 
-  * @file
 
-  * Contains functions used to install/uninstall tripal_core.
 
-  */
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_install() {
 
-   // make the data directory for this module
 
-   $data_dir = tripal_get_files_dir();
 
-   if (!file_prepare_directory($data_dir, FILE_CREATE_DIRECTORY)) {
 
-     $message = "Cannot create directory $data_dir. This module may not " .
 
-                "behave correctly without this directory.  Please  create " .
 
-                "the directory manually or fix the problem and reinstall.";
 
-     drupal_set_message(check_plain($message), 'error');
 
-     tripal_report_error('tripal_core', TRIPAL_ERROR, $message, array());
 
-   }
 
-   // the foreign key specification doesn't really add one to the
 
-   // Drupal schema, it is just used internally, but we want one
 
-   db_query('
 
-       ALTER TABLE {tripal_custom_tables}
 
-       ADD CONSTRAINT tripal_custom_tables_fk1
 
-       FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
 
-       ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
 
-   ');
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_schema() {
 
-   // get the schemas defined by this install file
 
-   $schema = tripal_core_get_schemas();
 
-   // if this module is already installed and enabled, then we want to provide
 
-   // the schemas for all of the custom tables.  This will allow Views to
 
-   // see the schemas.  We check if the module is installed because during
 
-   // installation we don't want to make these custom tables available as we don't
 
-   // want them created in the Drupal database.  The custom tables go in the
 
-   // Chado database.
 
-   if (db_table_exists('tripal_custom_tables')) {
 
-     $sql = 'SELECT * FROM {tripal_custom_tables}';
 
-     $results = db_query($sql);
 
-     foreach ($results as $custom) {
 
-       $schema[$custom->table_name] = unserialize($custom->schema);
 
-     }
 
-   }
 
-   return $schema;
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_uninstall() {
 
-   // drop the foreign key between tripal_custom_tables and tripal_mviews
 
-   // so that Drupal can then drop the tables
 
-   db_query('
 
-     ALTER TABLE {tripal_custom_tables}
 
-     DROP CONSTRAINT IF EXISTS tripal_custom_tables_fk1 CASCADE
 
-   ');
 
- }
 
- /**
 
-  * This function simply defines all tables needed for the module to work
 
-  * correctly.  By putting the table definitions in a separate function we
 
-  * can easily provide the entire list for hook_install or individual
 
-  * tables for an update.
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_get_schemas() {
 
-   $schema = array();
 
-   // get all the various schema parts and join them together
 
-   $temp = tripal_core_jobs_schema();
 
-   foreach ($temp as $table => $arr) {
 
-     $schema[$table] = $arr;
 
-   }
 
-   $temp = tripal_core_mviews_schema();
 
-   foreach ($temp as $table => $arr) {
 
-     $schema[$table] = $arr;
 
-   }
 
-   $temp = tripal_core_custom_tables_schema();
 
-   foreach ($temp as $table => $arr) {
 
-     $schema[$table] = $arr;
 
-   }
 
-   $temp = tripal_core_tripal_token_schema();
 
-   foreach ($temp as $table => $arr) {
 
-     $schema[$table] = $arr;
 
-   }
 
-   $temp = tripal_core_tripal_toc_schema();
 
-   foreach ($temp as $table => $arr) {
 
-     $schema[$table] = $arr;
 
-   }
 
-   return $schema;
 
- }
 
- /**
 
-  * Describes the Tripal Materialized View (tripal_mviews) table
 
-  * This table keeps track of all materialized views created by Tripal and stored in chado
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_mviews_schema() {
 
-   $schema = array();
 
-   $schema['tripal_mviews'] = array(
 
-     'fields' => array(
 
-       'mview_id' => array(
 
-         'type' => 'serial',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'name' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'modulename' => array(
 
-         'type' => 'varchar',
 
-         'length' => 50,
 
-         'not NULL' => TRUE,
 
-         'description' => 'The module name that provides the callback for this job'
 
-       ),
 
-       'mv_table' => array(
 
-         'type' => 'varchar',
 
-         'length' => 128,
 
-         'not NULL' => FALSE
 
-       ),
 
-       'mv_specs' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'mv_schema' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'indexed' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'query' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => TRUE
 
-       ),
 
-       'special_index' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'last_update' => array(
 
-         'type' => 'int',
 
-         'not NULL' => FALSE,
 
-         'description' => 'UNIX integer time'
 
-       ),
 
-       'status'        => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'comment' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'mview_id' => array('mview_id')
 
-     ),
 
-     'unique keys' => array(
 
-       'mv_table' => array('mv_table'),
 
-       'mv_name' => array('name'),
 
-     ),
 
-     'primary key' => array('mview_id'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Describes the Tripal Jobs (tripal_jobs) table
 
-  * This table keeps track of all tripal jobs including their current status and is used
 
-  * by tripal_launch_jobs to determine which jobs need to be run
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_jobs_schema() {
 
-   $schema = array();
 
-   $schema['tripal_jobs'] = array(
 
-     'fields' => array(
 
-       'job_id' => array(
 
-         'type' => 'serial',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'uid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => TRUE,
 
-         'description' => 'The Drupal userid of the submitee'
 
-       ),
 
-       'job_name' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'modulename' => array(
 
-         'type' => 'varchar',
 
-         'length' => 50,
 
-         'not NULL' => TRUE,
 
-         'description' => 'The module name that provides the callback for this job'
 
-       ),
 
-       'callback' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'arguments' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'progress' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'default' => 0,
 
-         'not NULL' => FALSE,
 
-         'description' => 'a value from 0 to 100 indicating percent complete'
 
-       ),
 
-       'status' => array(
 
-         'type' => 'varchar',
 
-         'length' => 50,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'submit_date' => array(
 
-         'type' => 'int',
 
-         'not NULL' => TRUE,
 
-         'description' => 'UNIX integer submit time'
 
-       ),
 
-       'start_time' => array(
 
-         'type' => 'int',
 
-         'not NULL' => FALSE,
 
-         'description' => 'UNIX integer start time'
 
-       ),
 
-       'end_time' => array(
 
-         'type' => 'int',
 
-         'not NULL' => FALSE,
 
-         'description' => 'UNIX integer end time'
 
-       ),
 
-       'error_msg' => array(
 
-         'type' => 'text',
 
-         'size' => 'normal',
 
-         'not NULL' => FALSE
 
-       ),
 
-       'pid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => FALSE,
 
-         'description' => 'The process id for the job'
 
-       ),
 
-       'priority' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => TRUE,
 
-         'default' => '0',
 
-         'description' => 'The job priority'
 
-       ),
 
-       'mlock' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => FALSE,
 
-         'description' => 'If set to 1 then all jobs for the module are held until this one finishes'
 
-       ),
 
-       'lock' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => FALSE,
 
-         'description' => 'If set to 1 then all jobs are held until this one finishes'
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'job_id' => array('job_id'),
 
-       'job_name' => array('job_name')
 
-     ),
 
-     'primary key' => array('job_id'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Describes the Tripal Custom Tables (tripal_custom_tables) table
 
-  * This keeps track of tables created by Tripal and stored in chado that may or may not
 
-  * also be materialized views.
 
-  *
 
-  * @ingroup tripal_core
 
-  */
 
- function tripal_core_custom_tables_schema() {
 
-   $schema = array();
 
-   $schema['tripal_custom_tables'] = array(
 
-     'fields' => array(
 
-       'table_id' => array(
 
-         'type' => 'serial',
 
-         'unsigned' => TRUE,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'table_name' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not NULL' => TRUE
 
-       ),
 
-       'schema' => array(
 
-         'type' => 'text',
 
-         'not NULL' => TRUE
 
-       ),
 
-       'mview_id' => array(
 
-         'type' => 'int',
 
-         'not NULL' => FALSE
 
-       )
 
-     ),
 
-     'indexes' => array(
 
-       'table_id' => array('table_id'),
 
-     ),
 
-     'primary key' => array('table_id'),
 
-     'foreign keys' => array(
 
-       'tripal_mviews' => array(
 
-         'table' => 'tripal_mviews',
 
-         'columns' => array(
 
-           'mview_id' => 'mview_id'
 
-         ),
 
-       ),
 
-     ),
 
-   );
 
-   return $schema;
 
- }
 
- function tripal_core_tripal_token_schema() {
 
-   $schema = array();
 
-   $schema['tripal_token_formats'] = array(
 
-     'fields' => array(
 
-       'tripal_format_id' => array(
 
-         'type' => 'serial',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE
 
-       ),
 
-       'content_type' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => TRUE
 
-       ),
 
-       'application' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => TRUE
 
-       ),
 
-       'format' => array(
 
-         'type' => 'text',
 
-         'not null' => TRUE
 
-       ),
 
-       'tokens' => array(
 
-         'type' => 'text',
 
-         'not null' => TRUE
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'tripal_format_id' => array('tripal_format_id'),
 
-       'type_application' => array('content_type', 'application'),
 
-     ),
 
-     'unique keys' => array(
 
-       'type_application' => array('content_type', 'application'),
 
-     ),
 
-     'primary key' => array('tripal_format_id'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * 
 
-  * 
 
-  */
 
- function tripal_core_tripal_toc_schema() {
 
-   $schema = array();
 
-   $schema['tripal_toc'] = array(
 
-     'fields' => array(
 
-       'toc_item_id' => array(
 
-         'type' => 'serial',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE
 
-       ),
 
-       'node_type' => array(
 
-         'type' => 'varchar',
 
-         'length' => 32,
 
-         'not null' => TRUE
 
-       ),
 
-       'key' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => TRUE,
 
-       ),
 
-       'title' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => FALSE
 
-       ),
 
-       'weight' => array(
 
-         'type' => 'int',
 
-         'not null' => FALSE
 
-       ),
 
-       'hide' => array(
 
-         'type' => 'int',
 
-         'size' => 'tiny',
 
-         'not null' => FALSE,
 
-         'default' => 0,
 
-       ),
 
-       'nid' => array(
 
-         'type' => 'int',
 
-         'not null' => FALSE,
 
-       )
 
-     ),
 
-     'indexes' => array(
 
-       'tripal_toc_idx1' => array('node_type', 'key'),
 
-       'tripal_toc_idx2' => array('node_type', 'key', 'nid'),
 
-     ),
 
-     'unique keys' => array(
 
-       'tripal_toc_uq1' => array('node_type', 'key', 'nid'),
 
-     ),
 
-     'primary key' => array('toc_item_id'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Adds an mview_id column to the tripal_custom_tables table and makes an assocation between the mview and the custom table
 
-  *
 
-  */
 
- function tripal_core_update_7200() {
 
-   try {
 
-     // add an mview column to the tripal_custom_tables table so we
 
-     // can associate which of the custom tables are also mviews
 
-     if (!db_field_exists('tripal_custom_tables', 'mview_id')) {
 
-       $spec = array(
 
-         'type' => 'int',
 
-         'not NULL' => FALSE
 
-       );
 
-       $keys = array(
 
-         'foreign keys' => array(
 
-           'tripal_mviews' => array(
 
-             'table' => 'tripal_mviews',
 
-             'columns' => array(
 
-               'mview_id' => 'mview_id'
 
-             ),
 
-           ),
 
-         ),
 
-       );
 
-       db_add_field('tripal_custom_tables', 'mview_id', $spec, $keys);
 
-       // the foreign key specification doesn't really add one to the
 
-       // Drupal schema, it is just used internally, but we want one
 
-       db_query('
 
-         ALTER TABLE {tripal_custom_tables}
 
-         ADD CONSTRAINT tripal_custom_tables_fk1
 
-         FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
 
-         ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
 
-       ');
 
-     }
 
-     // now link the materialized view to it's custom table entry
 
-     $mviews = db_select('tripal_mviews', 'tmv')
 
-       ->fields('tmv', array('mview_id', 'mv_table'))
 
-       ->execute();
 
-     foreach ($mviews as $mview) {
 
-       db_update('tripal_custom_tables')
 
-        ->fields(array(
 
-          'mview_id' => $mview->mview_id
 
-        ))
 
-        ->condition('table_name', $mview->mv_table)
 
-        ->execute();
 
-     }
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Could not update tripal_mviews table and link to custom tables: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Fixes missing language for nodes and URL aliases. This may take awhile...
 
-  *
 
-  */
 
- function tripal_core_update_7201() {
 
-   try {
 
-     $sql = "UPDATE {node} SET language = :language WHERE language = ''";
 
-     db_query($sql, array(':language' => LANGUAGE_NONE));
 
-     $sql = "UPDATE {url_alias} SET language = :language WHERE language = ''";
 
-     db_query($sql, array(':language' => LANGUAGE_NONE));
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Could not reset language for nodes and url aliases: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Adds a tripal_token_formats table for custom page titles and URL paths
 
-  */
 
- function tripal_core_update_7202() {
 
-   try {
 
-     $schema = drupal_get_schema_unprocessed('tripal_core', 'tripal_token_formats');
 
-     db_create_table('tripal_token_formats', $schema);
 
-   }
 
-   catch (Exception $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Could not add tripal_token_formats table: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Adds a tripal_toc table for customizing the table of contents on each Tripal page.
 
-  */
 
- function tripal_core_update_7203() {
 
-   try {
 
-     $schema = drupal_get_schema_unprocessed('tripal_core', 'tripal_toc');
 
-     db_create_table('tripal_toc', $schema);
 
-   }
 
-   catch (Exception $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Could not add tripal_toc table: '. $error);
 
-     
 
-   }
 
-   
 
- }
 
 
  |