function tripal_mviews_action

2.x tripal_core.DEPRECATED.api.inc tripal_mviews_action($op, $mview_id, $redirect = FALSE)
3.x tripal_core.DEPRECATED.inc tripal_mviews_action($op, $mview_id, $redirect = FALSE)
1.x tripal_core_mviews.api.inc tripal_mviews_action($op, $mview_id, $redirect = FALSE)

Does the specified action for the specified Materialized View

Parameters

$op: The action to be taken. One of update or delete

$mview_id: The unique ID of the materialized view for the action to be performed on

$redirect: TRUE/FALSE depending on whether you want to redirect the user to admin/tripal/mviews

Related topics

4 calls to tripal_mviews_action()
1 string reference to 'tripal_mviews_action'
tripal_core_menu in tripal_core/tripal_core.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal_core/api/tripal_core_mviews.api.inc, line 297
Contains functions for the Materialized Views API

Code

function tripal_mviews_action($op, $mview_id, $redirect = FALSE) {
  global $user;

  $args = array("$mview_id");
  if (!$mview_id) {
    return '';
  }

  // get this mview details
  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
  $mview = db_fetch_object(db_query($sql, $mview_id));

  // add a job or perform the action based on the given operation
  if ($op == 'update') {
    tripal_add_job("Populate materialized view '$mview->name'", 'tripal_core', 
    'tripal_update_mview', $args, $user->uid);
  }
  if ($op == 'delete') {
    // remove the mview from the tripal_mviews table
    $sql = "DELETE FROM {tripal_mviews} " .
      "WHERE mview_id = $mview_id";
    db_query($sql);
    // drop the table from chado if it exists
    $previous_db = tripal_db_set_active('chado'); // use chado database
    if (db_table_exists($mview->mv_table)) {
      $sql = "DROP TABLE $mview->mv_table";
      db_query($sql);
    }
    tripal_db_set_active($previous_db); // now use drupal database
  }

  // Redirect the user
  if ($redirect) {
    drupal_goto("admin/tripal/mviews");
  }
}