TRUE)); } } /** * Implements hook_requirements(). * * Performs check to see if all required dependencies are met. Drupal will * automatically check for module dependencies but here you can check for * other requirements. * * @ingroup tripal_example */ function tripal_example_requirements($phase) { $requirements = array(); if ($phase == 'install') { // EXPLANATION: It is essential that Chado be installed for almost all // Tripal modules. Therefore, the following code checks to ensure Chado // is installed and available. If your module does not require that // Chado be installed, you can remove the following check. // make sure chado is installed if (!$GLOBALS["chado_is_installed"]) { $requirements ['tripal_example'] = array( 'title' => "tripal_example", 'value' => "ERROR: Chado must be installed before this module can be enabled", 'severity' => REQUIREMENT_ERROR, ); } } return $requirements; } /** * Implements hook_install(). * * Performs actions when the modules is first installed. * * @ingroup tripal_example */ function tripal_example_install() { // EXPLANATION: If your module will making data publicly available for // download or use by the site you can create the directory using the // tripal_create_files_dir() function. This will create a directory // in the public access directory which will typcially be in // sites/default/files/tripal/[module name]/ // create the module's data directory tripal_create_files_dir('tripal_example'); // EXPLANATION: Here is a good place to add any materialized views, // controlled vocabularies CV, databases or CV terms needed by your module. // To keep this module code short, create functions to do each of those // tasks // add any materialized view tripal_example_add_mviews(); // add any external databases used by the example module. tripal_example_add_dbs(); // add any controlled vocabularies used by the example module. You may need // to add a vocabulary if you to set it as default (see next lines of code). // For example, the Sequence Ontology (SO) is used by the feature module as the // default vocabulary for the feature type_id field. But, that vocabulary // does not yet exist in Chado until after the SO is loaded using the // Tripal OBO loader. But, we can add it here as a placeholder so that we can // then set it as a default vocabulary (see below). tripal_example_add_cvs(); // EXPLANATION: Many tables in Chado have a 'type_id' column which allows for // association of controlled vocabulries to describe the record. Chado // places no restrictions on which vocabularies can be used, but Tripal can // be instructed to provide a default vocabulary for any given field. For // example, the feature.type_id column will typically use the Sequence Ontology // In that case, we can use the tripal_set_default_cv() function to specify // the Sequence Ontology (sequence) as the default vocabulary. tripal_set_default_cv('example', 'type_id', 'sequence'); tripal_set_default_cv('exampleprop', 'type_id', 'example_property'); tripal_set_default_cv('example_relationship', 'type_id', 'example_relationship'); } /** * Implements hook_uninstall(). * * Performs actions when the modules is uninstalled. * * @ingroup tripal_example */ function tripal_example_uninstall() { } /** * Implementation of hook_schema(). * * Provides a list of tables to be created inside of the Drupal schema * (the 'public' schema by default). It uses the Drupal Schema API * array structure to define the table, its indexes and constraints. * * Schema API documentation is here: * https://api.drupal.org/api/drupal/includes%21database%21schema.inc/group/schemaapi/7 * * @ingroup tripal_example */ function tripal_example_schema() { // EXPLANATION: If your module creates a node type for data in the Chado // database then you probably need to link Drupal nodes with a respective // ID in the Chado table. The following is an example array for a table // that will link the 'chado_example' node type (created by this example // module) with a record in the fake Chado example table. This table // will link the 'nid' of the node with the 'example_id' of the eample // record. $schema['chado_example'] = array( 'fields' => array( 'vid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'example_id' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0 ), 'sync_date' => array( 'type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer sync date/time' ), ), 'indexes' => array( 'chado_example_idx1' => array('example_id') ), 'unique keys' => array( 'chado_example_uq1' => array('nid', 'vid'), 'chado_example_uq2' => array('vid') ), 'primary key' => array('nid'), ); return $schema; }; /** * Creates a materialized view that stores the type & number of examples per organism * * @ingroup tripal_example */ function tripal_example_add_mviews() { // EXPLANATION: use the tripal_add_mview() function to add a materialized // view needed by your module. If you have more than one materialized view // it is best to create a single function for each one and call each // function here. Otherwise this function can become quite long. } /** * Add cvs related to publications * * @ingroup tripal_pub */ function tripal_example_add_cvs() { // EXPLANATION: use the tripal_cv_add_cv() function to add any // controlled vocabularies needed by your module. If the vocabulary already // exists then the function will gracefully return. } /** * This is the required update for tripal_example. */ function tripal_example_update_7200() { // EXPLANATION: as you create new releases of your module you may find that // tables your module created, or data may need to be adjusted. This function // allows you to do that. This function is executed using the // http://[your site]/update.php URL or using the drush command 'updatedb'. // This function should be named according to the instructions provided here: // https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_update_N/7 // // It is best not to use Tripal API calls inside of this function because an // upgarde from Drupal 6 to Drupal 7 requires that all modules be disabled // which means the Tripal API is not available. This is an unfortunate // requirement, but will prevent errors during a major upgrade. // it is good to wrap any database changes inside of a try catch block: try { // perform database changes } catch (\PDOException $e) { $error = $e->getMessage(); throw new DrupalUpdateException('Could not apply updates: '. $error); } } /** * Implementation of hook_update_dependencies(). It specifies a list of * other modules whose updates must be run prior to this one. */ function tripal_example_update_dependencies() { $dependencies = array(); // EXPLANATION: here we can specify which modules must be updated prior // to applying the updates in this module. This is useful because it // prevents updates from being executed out of order. The following // example code shows that the 'tripal_example' module update number 7200 // must be executed after the 'tripal_cv' module's 7200 update. $dependencies['tripal_example'][7200] = array( 'tripal_cv' => 7200 ); return $dependencies; }