function tripal_populate_mview

2.x tripal_populate_mview($mview_id)

Update a Materialized View


$mview_id: The unique identifier for the materialized view to be updated

Return value

True if successful, FALSE otherwise

Related topics

3 calls to tripal_populate_mview()
drush_tripal_core_tripal_update_mview in tripal_core/
DEPRECATED. Updates the specified materialized view.
drush_tripal_core_trp_refresh_mview in tripal_core/
Updates the specified materialized view
tripal_update_mview in tripal_core/api/
3 string references to 'tripal_populate_mview'
tripal_core_job_describe_args in tripal_core/tripal_core.module
Implements hook_job_describe_args(). Describes the arguments for the tripal_populate_mview job to allow for greater readability in the jobs details pages.
tripal_refresh_mview in tripal_core/api/
Populates the specified Materialized View
tripal_update_mview in tripal_core/api/


tripal_core/api/, line 429
Provides an application programming interface (API) to manage materialized views in Chado.


function tripal_populate_mview($mview_id) {
  $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  $results = db_query($sql, array(':mview_id' => $mview_id));
  $mview = $results->fetchObject();
  if ($mview) {
    // execute the query inside a transaction so that it doesn't destroy existing data
    // that may leave parts of the site unfunctional
    $transaction = db_transaction();
    try {
      $previous_db = chado_set_active('chado'); // use chado database
      $success = db_query("DELETE FROM {" . $mview->mv_table . "}");
      $success = db_query("INSERT INTO {" . $mview->mv_table . "} ($mview->query)");
      chado_set_active($previous_db); // now use drupal database
      // if success get the number of results and update the table record
      if ($success) {
        $sql = "SELECT count(*) as cnt FROM {" . $mview->mv_table . "}";
        $results = chado_query($sql);
        $count = $results->fetchObject();
        $record = new stdClass();
        $record->mview_id = $mview_id;
        $record->last_update = REQUEST_TIME;
        $record->status = "Populated with " . number_format($count->cnt) . " rows";
        drupal_write_record('tripal_mviews', $record, 'mview_id');
      // if not success then throw an error
      else {
        throw new Exception("ERROR populating the materialized view " . $mview->mv_table . ". See Drupal's recent log entries for details.");
    catch (Exception $e) {
      // print and save the error message
      $record = new stdClass();
      $record->mview_id = $mview_id;
      $record->status = "ERROR populating $mview->mv_table. See Drupal's recent log entries for details.\n";
      drupal_write_record('tripal_mviews', $record, 'mview_id');
      watchdog_exception('tripal_mviews', $e);
      return FALSE;
    print "Done.\n";
    return TRUE;