You are here

function view_custom_table_uninstall in Views Custom Table 7

Implements hook_uninstall().

File

./view_custom_table.install, line 62
Installation functions for the View Custom Table module.

Code

function view_custom_table_uninstall() {

  // Remove views created from custom tables.
  if (db_table_exists('custom_table_view_data')) {
    $query = db_select('custom_table_view_data', 'ctvd')
      ->fields('ctvd', array(
      'table_name',
    ));
    $custom_tables = $query
      ->execute()
      ->fetchCol();
    if (!empty($custom_tables)) {
      $query = db_select('views_view', 'v')
        ->fields('v', array(
        'name',
      ))
        ->condition('base_table', $custom_tables, 'IN');
      $custom_table_view = $query
        ->execute()
        ->fetchCol();
      if (!empty($custom_table_view)) {
        foreach ($custom_table_view as $view_name) {
          $view = views_get_view($view_name);
          if (is_object($view)) {
            views_delete_view($view);
          }
        }
      }
    }
  }
}