Commit 188bd063 authored by Bryan Sharpe's avatar Bryan Sharpe
Browse files

Issue #3258670 by b_sharpe: Allow fetching the query of a plugin

parent b0fe01c2
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -93,10 +93,9 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface {
  /**
   * {@inheritdoc}
   */
  public function fetchUsageData($type, $eventType = NULL, $entityTypeId = NULL, $entityId = NULL, $count = TRUE, $conditions = []) {
  public function fetchUsageQuery($type, $eventType = NULL, $entityTypeId = NULL, $entityId = NULL) {
    // Make sure the table exists.
    $table = $this->tableName($type);
    if ($this->connection->schema()->tableExists($table)) {
    $query = $this->connection->select($table, 'u');

    if ($eventType) {
@@ -109,6 +108,18 @@ class UsageDataDatabaseStorage implements UsageDataStorageInterface {
      $query->condition('entity_id', $entityId);
    }

    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fetchUsageData($type, $eventType = NULL, $entityTypeId = NULL, $entityId = NULL, $count = TRUE, $conditions = []) {
    // Make sure the table exists.
    $table = $this->tableName($type);
    if ($this->connection->schema()->tableExists($table)) {
      $query = $this->fetchUsageQuery($type, $eventType, $entityTypeId, $entityId);

      if (!$count) {
        // @todo this could be configurable, just grab all for now.
        $query->fields('u');
+21 −0
Original line number Diff line number Diff line
@@ -30,6 +30,27 @@ interface UsageDataStorageInterface {
   */
  public function recordUsageByType($type, array $data);

  /**
   * Fetches usage data query for the appropriate table.
   *
   * NOTE: This function does NOT provide the fields() call as the entire
   * purpose is to allow altering of the query. Without adding this method
   * you will not be able to execute.
   *
   * @param string $type
   *   The type of usage data to fetch.
   * @param string $eventType
   *   The optional event type.
   * @param string $entityTypeId
   *   The optional entity type id.
   * @param string $entityId
   *   The optional entity id.
   *
   * @return \Drupal\Core\Database\Query\SelectInterface
   *   The query for the usage type.
   */
  public function fetchUsageQuery($type, $eventType = NULL, $entityTypeId = NULL, $entityId = NULL);

  /**
   * Fetches usage data from the appropriate table.
   *