execute example

public function __toString() {
    return (string) $this->entityType->getPluralLabel();
  }

  /** * Initializes the iterator with the source data. * * @return \Generator * A data generator for this source. */
  protected function initializeIterator() {
    $ids = $this->query()->execute();
    return $this->yieldEntities($ids);
  }

  /** * Loads and yields entities, one at a time. * * @param array $ids * The entity IDs. * * @return \Generator * An iterable of the loaded entities. */
public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['id'])
            ->orderBy('id');

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            return [];
        }

        return $this->router->generateList(
            array_map(
                function D$manufacturer) {
                    return ['sViewport' => 'listing', 'sAction' => 'manufacturer', 'sSupplier' => $manufacturer['id']];
                },
                $result
            ),

  public function execute() {
    $stmt = $this->connection->prepareStatement((string) $this$this->queryOptions, TRUE);
    try {
      $stmt->execute([]$this->queryOptions);
      return $stmt->rowCount();
    }
    catch (\Exception $e) {
      $this->connection->exceptionHandler()->handleExecutionException($e$stmt[]$this->queryOptions);
    }

    return NULL;
  }

  /** * Implements PHP magic __toString method to convert the query to a string. * * @return string * The prepared statement. */
$user_c = $this->createUser(['access user profiles']);

    $uids = [$user_a->id()$user_b->id()$user_c->id()];

    // These users should have a role     $connection = Database::getConnection();
    $query = $connection->select('user__roles', 'r');
    $roles_created = $query
      ->fields('r', ['entity_id'])
      ->condition('entity_id', $uids, 'IN')
      ->countQuery()
      ->execute()
      ->fetchField();

    $this->assertGreaterThan(0, $roles_created);
    // We should be able to load one of the users.     $this->assertNotNull(User::load($user_a->id()));
    // Delete the users.     $storage = $this->container->get('entity_type.manager')->getStorage('user');
    $users = $storage->loadMultiple($uids);
    $storage->delete($users);
    // Test if the roles assignments are deleted.     $query = $connection->select('user__roles', 'r');
    

    private function getLocalLicenseByPluginName($pluginName)
    {
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder
            ->select('license.*')
            ->from('s_core_licenses', 'license')
            ->where('license.module = :plugin')
            ->setParameter('plugin', $pluginName);

        return $queryBuilder->execute()->fetch();
    }

    /** * @param string $domain */
    private function createLocalLicenseInformation(PluginInformationStruct $plugin$domain)
    {
        $today = new DateTime();
        $data = [
            'module' => $plugin->getTechnicalName(),
            'host' => $domain,
            
$query->condition('id', $subquery, 'IN');

    $clone = clone $query;

    // Cloned query should have a different unique identifier.     $this->assertNotEquals($query->uniqueIdentifier()$clone->uniqueIdentifier());

    // Cloned query should not be altered by the following modification     // happening on original query.     $subquery->condition('age', 25, '>');

    $clone_result = $clone->countQuery()->execute()->fetchField();
    $query_result = $query->countQuery()->execute()->fetchField();

    // Make sure the cloned query has not been modified     $this->assertEquals(3, $clone_result, 'The cloned query returns the expected number of rows');
    $this->assertEquals(2, $query_result, 'The query returns the expected number of rows');
  }

  /** * Tests that nested SELECT queries are cloned properly. */
  public function testNestedQueryCloning() {
    
/** * Tests the media bulk form. */
  public function testBulkForm() {
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    // Check that all created items are present in the test view.     $view = Views::getView('test_media_bulk_form');
    $view->execute();
    $this->assertSame($view->total_rows, 5);

    // Check the operations are accessible to the logged in user.     $this->drupalGet('test-media-bulk-form');
    // Current available actions: Delete, Save, Publish, Unpublish.     $available_actions = [
      'media_delete_action',
      'media_publish_action',
      'media_save_action',
      'media_unpublish_action',
    ];
    
$receiver->expects($this->once())->method('find')->with(20)->willReturn(new Envelope(new \stdClass()));
        $serviceLocator = $this->createMock(ServiceLocator::class);
        $serviceLocator->expects($this->once())->method('has')->with($globalFailureReceiverName)->willReturn(true);
        $serviceLocator->expects($this->any())->method('get')->with($globalFailureReceiverName)->willReturn($receiver);

        $command = new FailedMessagesRemoveCommand(
            $globalFailureReceiverName,
            $serviceLocator
        );

        $tester = new CommandTester($command);
        $tester->execute(['id' => 20, '--force' => true]);

        $this->assertStringContainsString('Failed Message Details', $tester->getDisplay());
        $this->assertStringContainsString('Message with id 20 removed.', $tester->getDisplay());
    }

    public function testRemoveUniqueMessageWithServiceLocator()
    {
        $globalFailureReceiverName = 'failure_receiver';
        $receiver = $this->createMock(ListableReceiverInterface::class);
        $receiver->expects($this->once())->method('find')->with(20)->willReturn(new Envelope(new \stdClass()));
        $serviceLocator = $this->createMock(ServiceLocator::class);
        

        $qb = $this->getBaseQuery()
            ->addSelect(['DISTINCT details.articleID', 'details.ordernumber'])
            ->orderBy('details.articleID', 'ASC')
            ->setParameter(':shop', $context->getShopId());

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            return [];
        }

        return $this->router->generateList(
            array_map(
                function D$product) {
                    return ['controller' => 'detail', 'action' => 'index', 'sArticle' => $product['articleID'], 'number' => $product['ordernumber']];
                },
                $result
            ),
/** * Returns a shop page tree for the provided shop id. * * @param int $shopId * @param int|null $activeId * * @return array */
    public function getTree($shopId$activeId)
    {
        $data = $this->getQuery($shopId)->execute()->fetchAllAssociative();

        $menu = [];
        $links = [];

        foreach ($data as $site) {
            if (isset($site['mapping'])) {
                /** * If there's a mapping present, we're dealing with one of the * english legacy groups, so rename it to make it usable in the frontend. */
                $key = $site['mapping'];
            }
protected function doTestIdenticalUser() {
    /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
    $condition = \Drupal::service('plugin.manager.condition')
      ->createInstance('condition_test_dual_user')
      // Map the anonymous user to both contexts.       ->setContextMapping([
        'user1' => 'anonymous',
        'user2' => 'anonymous',
      ]);
    $contexts['anonymous'] = EntityContext::fromEntity($this->anonymous);
    \Drupal::service('context.handler')->applyContextMapping($condition$contexts);
    $this->assertTrue($condition->execute());
  }

  /** * Tests with each context mapped to different users. */
  protected function doTestDifferentUser() {
    /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
    $condition = \Drupal::service('plugin.manager.condition')
      ->createInstance('condition_test_dual_user')
      ->setContextMapping([
        'user1' => 'anonymous',
        

  public function testCaseSensitiveInsert() {
    $num_records_before = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();

    $this->connection->insert('test')
      ->fields([
        // A record already exists with name 'John'.         'name' => 'john',
        'age' => 2,
        'job' => 'Baby',
      ])
      ->execute();

    $num_records_after = $this->connection->query('SELECT COUNT(*) FROM {test}')->fetchField();
    $this->assertSame($num_records_before + 1, (int) $num_records_after, 'Record inserts correctly.');
    $saved_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'john'])->fetchField();
    $this->assertSame('2', $saved_age, 'Can retrieve after inserting.');
  }

}

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function delete($id) {
    try {
      $this->connection->delete('batch')
        ->condition('bid', $id)
        ->execute();
    }
    catch (\Exception $e) {
      $this->catchException($e);
    }
  }

  /** * {@inheritdoc} */
  public function update(array $batch) {
    try {
      
->orderBy('f.sticky', 'DESC')
      ->orderByHeader($header)
      ->limit($forum_per_page);

    $count_query = $this->connection->select('forum_index', 'f');
    $count_query->condition('f.tid', $tid);
    $count_query->addExpression('COUNT(*)');
    $count_query->addTag('node_access');
    $count_query->addMetaData('base_table', 'forum_index');

    $query->setCountQuery($count_query);
    $result = $query->execute();
    $nids = [];
    foreach ($result as $record) {
      $nids[] = $record->nid;
    }
    if ($nids) {
      $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);

      $query = $this->connection->select('node_field_data', 'n')
        ->extend(TableSortExtender::class);
      $query->fields('n', ['nid']);

      

    private function duplicateCategory(
        $categoryId,
        $newParentId,
        $copyProductAssociations,
        $newRootCategoryId = null
    ) {
        $newCategoryId = $this->container->get(CategoryDuplicator::class)->duplicateCategory($categoryId$newParentId$copyProductAssociations);
        $this->progressBar->advance();

        $childrenStmt = $this->container->get('db')->prepare('SELECT id FROM s_categories WHERE parent = :parent');
        $childrenStmt->execute([':parent' => $categoryId]);
        $children = $childrenStmt->fetchAll(PDO::FETCH_COLUMN);

        $newRootCategoryId = $newRootCategoryId ?: $newCategoryId;

        foreach ($children as $child) {
            $child = (int) $child;
            if ($child !== (int) $newRootCategoryId) {
                $this->duplicateCategory($child$newCategoryId$copyProductAssociations$newRootCategoryId);
            }
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.