You are here

function farm_api_uninstall in farmOS 7

Same name and namespace in other branches
  1. 2.x modules/core/api/farm_api.install \farm_api_uninstall()

Implements hook_uninstall().

File

modules/farm/farm_api/farm_api.install, line 29
Farm API install file.

Code

function farm_api_uninstall() {

  // Assume that the user does not change the OAuth2 Server or Scope
  // because they are using this module with farmOS. Otherwise this could
  // potentially delete other configured OAuth2 Servers and Scopes.
  $server_name = variable_get('restws_oauth2_server_name', 'farmos_oauth');

  // Get enabled OAuth Clients.
  $enabled_clients = variable_get('farm_api_enabled_clients', array());
  foreach ($enabled_clients as $client_key) {

    // Delete OAuth Client.
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'oauth2_server_client')
      ->entityCondition('client_key', $client_key);
    $result = $query
      ->execute();
    if (isset($result['oauth2_server_client'])) {
      $client_id = array_keys($result['oauth2_server_client']);
      entity_delete('oauth2_server_client', $client_id);
    }
  }

  // Features will delete the OAuth2 Server entity.
  // Features does not delete the existing OAuth Scopes.
  // Delete farmOS OAuth Scopes.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'oauth2_server_scope')
    ->entityCondition('server', $server_name);
  $result = $query
    ->execute();
  if (isset($result['oauth2_server_scope'])) {
    $scope_ids = array_keys($result['oauth2_server_scope']);
    entity_delete('oauth2_server_scope', $scope_ids);
  }

  // Delete variables
  variable_del('restws_oauth2_server_name');
}