getAggregateQuery example


    $entity->enforceIsNew();
    $entity->save();

  }

  /** * Tests aggregation support. */
  public function testAggregation() {
    // Apply a simple groupby.     $this->queryResult = $this->entityStorage->getAggregateQuery()
      ->accessCheck(FALSE)
      ->groupBy('user_id')
      ->execute();

    $this->assertResults([
      ['user_id' => 1],
      ['user_id' => 2],
      ['user_id' => 3],
    ]);

    $function_expected = [];
    
$published_key = $entity_keys['published'];

    // Filter the expected values so we can check only the default revisions.     $expected_default_revisions = array_filter($expected_valuesfunction D$expected_value) {
      return $expected_value['default_revision'] === TRUE;
    });

    // Check entity query counts.     $result = (int) $storage->getQuery()->accessCheck(FALSE)->count()->execute();
    $this->assertSame(count($expected_default_revisions)$result);

    $result = (int) $storage->getAggregateQuery()->accessCheck(FALSE)->count()->execute();
    $this->assertSame(count($expected_default_revisions)$result);

    // Check entity queries with no conditions.     $result = $storage->getQuery()->accessCheck(FALSE)->execute();
    $expected_result = array_combine(array_column($expected_default_revisions$revision_key)array_column($expected_default_revisions$id_key));
    $this->assertEquals($expected_result$result);

    // Check querying each revision individually.     foreach ($expected_values as $expected_value) {
      $query = $storage->getQuery()->accessCheck(FALSE);
      $query
        
$revision_ids = $this->getEntityRevisionIds();
    return $this->storage->loadMultipleRevisions($revision_ids);
  }

  /** * Loads entity revision IDs using a pager sorted by the entity revision ID. * * @return array * An array of entity revision IDs. */
  protected function getEntityRevisionIds() {
    $query = $this->entityTypeManager->getStorage('content_moderation_state')->getAggregateQuery()
      ->accessCheck(TRUE)
      ->aggregate('content_entity_id', 'MAX')
      ->groupBy('content_entity_revision_id')
      ->condition('content_entity_type_id', $this->entityTypeId)
      ->condition('moderation_state', 'published', '<>')
      ->sort('content_entity_revision_id', 'DESC');

    // Only add the pager if a limit is specified.     if ($this->limit) {
      $query->pager($this->limit);
    }

    

  public static function entityQueryAggregate($entity_type$conjunction = 'AND') {
    return static::entityTypeManager()->getStorage($entity_type)->getAggregateQuery($conjunction);
  }

  /** * Returns the flood instance. * * @return \Drupal\Core\Flood\FloodInterface */
  public static function flood() {
    return static::getContainer()->get('flood');
  }

  
$plugin_definition,
      $container->get('entity_type.manager')->getStorage('node')
    );
  }

  /** * Override the behavior of title(). Get the title of the revision. */
  public function titleQuery() {
    $titles = [];

    $results = $this->nodeStorage->getAggregateQuery()
      ->accessCheck(FALSE)
      ->allRevisions()
      ->groupBy('title')
      ->condition('vid', $this->value, 'IN')
      ->execute();

    foreach ($results as $result) {
      $titles[] = $result['title'];
    }

    return $titles;
  }
Home | Imprint | This part of the site doesn't use cookies.