/**
 * Implements hook_install().
 */
function PROFILE_install()
{
    global $base_url;
    $server_name = 'oauth2';
    $client_key = 'client1';
    $client_secret = md5(uniqid(rand(), TRUE));
    $redirect_uri = $base_url . '/oauth2/authorized';
    // Delete the client if already exists.
    $query = new EntityFieldQuery();
    $clients = $query->entityCondition('entity_type', 'oauth2_server_client')->propertyCondition('server', $server_name)->propertyCondition('client_key', $client_key)->execute();
    if (isset($clients['oauth2_server_client'])) {
        $cids = array_keys($clients['oauth2_server_client']);
        foreach ($cids as $cid) {
            entity_delete('oauth2_server_client', $cid);
        }
    }
    // Register a client on the oauth2 server.
    $client = entity_create('oauth2_server_client', array());
    $client->server = $server_name;
    $client->label = 'Test OAuth2 Client';
    $client->client_key = $client_key;
    $client->client_secret = $client_secret;
    $client->redirect_uri = $redirect_uri;
    $client->automatic_authorization = TRUE;
    $client->save();
}
 /**
  * Create a token for a user, and return its value.
  *
  * @param string $token
  *   The refresh token.
  *
  * @throws BadRequestException
  *
  * @return RestfulTokenAuth
  *   The new access token.
  */
 public function refreshToken($token)
 {
     // Check if there is a token that did not expire yet.
     /* @var \Drupal\restful\Plugin\resource\DataProvider\DataProviderEntityInterface $data_provider */
     $data_provider = $this->getDataProvider();
     $query = $data_provider->EFQObject();
     $results = $query->entityCondition('entity_type', $this->entityType)->entityCondition('bundle', 'refresh_token')->propertyCondition('token', $token)->range(0, 1)->execute();
     if (empty($results['restful_token_auth'])) {
         throw new BadRequestException('Invalid refresh token.');
     }
     // Remove the refresh token once used.
     $refresh_token = entity_load_single('restful_token_auth', key($results['restful_token_auth']));
     $uid = $refresh_token->uid;
     // Get the access token linked to this refresh token then do some cleanup.
     $access_token_query = new EntityFieldQuery();
     $access_token_reference = $access_token_query->entityCondition('entity_type', 'restful_token_auth')->entityCondition('bundle', 'access_token')->fieldCondition('refresh_token_reference', 'target_id', $refresh_token->id)->range(0, 1)->execute();
     if (!empty($access_token_reference['restful_token_auth'])) {
         $access_token = key($access_token_reference['restful_token_auth']);
         entity_delete('restful_token_auth', $access_token);
     }
     $refresh_token->delete();
     // Create the new access token and return it.
     /* @var \Drupal\restful_token_auth\Entity\RestfulTokenAuthController $controller */
     $controller = entity_get_controller($this->getEntityType());
     $token = $controller->generateAccessToken($uid);
     return $this->view($token->id);
 }
 /**
  * @AfterScenario
  */
 public function cleanUpEntities($event)
 {
     foreach ($this->content as $entityType => $bundles) {
         $entityInfo = entity_get_info($entityType);
         $idProperty = $entityInfo['entity keys']['id'];
         foreach ($bundles as $bundleType => $entities) {
             foreach ($entities as $entity) {
                 entity_delete($entityType, $entity->{$idProperty}->value());
             }
         }
     }
     $this->content = array();
 }
  /**
   * Create a token for a user, and return its value.
   *
   * @param string $token
   *   The refresh token.
   *
   * @throws RestfulBadRequestException
   *
   * @return \RestfulTokenAuth
   *   The new access token.
   */
  public function refreshToken($token) {
    // Check if there is a token that did not expire yet.
    $query = new EntityFieldQuery();
    $results = $query
      ->entityCondition('entity_type', $this->entityType)
      ->entityCondition('bundle', 'refresh_token')
      ->propertyCondition('token', $token)
      ->range(0, 1)
      ->execute();

    if (empty($results['restful_token_auth'])) {
      throw new \RestfulBadRequestException('Invalid refresh token.');
    }

    // Remove the refresh token once used.
    $refresh_token = entity_load_single('restful_token_auth', key($results['restful_token_auth']));
    $uid = $refresh_token->uid;

    // Get the access token linked to this refresh token then do some cleanup.
    $access_token_query = new EntityFieldQuery();
    $access_token_reference = $access_token_query
      ->entityCondition('entity_type', $this->getEntityType())
      ->entityCondition('bundle', $this->getBundle())
      ->fieldCondition('refresh_token_reference', 'target_id', $refresh_token->id)
      ->range(0, 1)
      ->execute();

    if (!empty($access_token_reference['restful_token_auth'])) {
      $access_token_id = key($access_token_reference['restful_token_auth']);
      entity_delete('restful_token_auth', $access_token_id);
    }

    $refresh_token->delete();

    // Create the new access token and return it.
    $controller = entity_get_controller($this->getEntityType());
    $token = $controller->generateAccessToken($uid);
    return $this->viewEntity($token->id);
  }
Exemplo n.º 5
0
 public function receive($endpoint, $payload = array())
 {
     if (!array_key_exists('entities', $payload)) {
         throw new MalformedRequestException('The payload must contain entities to delete, but it does not.');
     }
     $deleted[] = array();
     foreach ($payload['entities'] as $to_delete) {
         if (Entity::exists($to_delete['entity_uuid'], $to_delete['entity_type'])) {
             publisher_set_flag('publisher_deleting');
             $entity_ids = entity_get_id_by_uuid($to_delete['entity_type'], array($to_delete['entity_uuid']));
             $entity_id = count($entity_ids) > 0 ? reset($entity_ids) : false;
             if ($entity_id === false) {
                 continue;
             }
             entity_delete($to_delete['entity_type'], $entity_id);
             drupal_set_message(t('<strong>:type</strong> @title deleted successfully.', array(':type' => $to_delete['entity_type'], '@title' => $to_delete['entity_title'])));
             $deleted[] = $to_delete;
         } else {
             drupal_set_message(t('<strong>:type</strong> @title did not exist.', array(':type' => $to_delete['entity_type'], '@title' => $to_delete['entity_title'])));
             $deleted[] = $to_delete;
         }
     }
     return array('deleted' => $deleted);
 }
/**
 * Form submit handler.
 * @see entityqueue_subqueue_delete_form()
 */
function entityqueue_subqueue_delete_form_submit($form, &$form_state)
{
    $queue = $form['#queue'];
    $subqueue = $form['#subqueue'];
    $handler = entityqueue_get_handler($queue);
    if ($handler->canDeleteSubqueue($subqueue)) {
        entity_delete('entityqueue_subqueue', $subqueue->subqueue_id);
    }
    $form_state['redirect'] = 'admin/structure/entityqueue/list/' . $queue->name . '/subqueues';
}
Exemplo n.º 7
0
 /**
  * Delete the current entity from the database.
  */
 public function delete()
 {
     if ($this->getEntityType() == 'node') {
         node_delete($this->get('nid'));
     } else {
         entity_delete($this->getEntityType(), $this->get('id'));
     }
 }
 /**
  * Reverts configuration done by the context.
  *
  * @AfterScenario
  */
 public function revertConfiguration()
 {
     // Remove configuration entities.
     foreach ($this->configurationEntities as $configuration) {
         if ($configuration->entityType() == 'integration_consumer') {
             /** @var AbstractConsumer $consumer */
             $consumer = ConsumerFactory::getInstance($configuration->getMachineName());
             $consumer->processRollback();
             // Remove consumer & its corresponding migration.
             Migration::deregisterMigration('test_consumer');
         }
         $configuration->delete();
     }
     if ($this->backendWasConfigured) {
         entity_delete('integration_backend', 'http_mock');
     }
     if ($this->server && $this->server->isStarted()) {
         $this->server->stop();
     }
 }
Exemplo n.º 9
0
 public function delete()
 {
     return \entity_delete($this->type, $this->definition->id);
 }
Exemplo n.º 10
0
 protected function delete_product($spid)
 {
     entity_delete('wechat_scan_product', $spid);
 }
Exemplo n.º 11
0
function user_delete(&$user)
{
    entity_delete('users', $user);
}