fetchAllAssociative example

#[Package('core')] trait EnsureThumbnailSizesTrait
{
    /** * @param list<array{width: int, height: int}> $thumbnailSizes * * @return string[] */
    final protected function ensureThumbnailSizes(array $thumbnailSizes, Connection $connection): array
    {
        /** @var list<array{id: string, width: string, height: string}> $allSizes */
        $allSizes = $connection->fetchAllAssociative(
            'SELECT `id`, `width`, `height` FROM `media_thumbnail_size`'
        );

        $insertStatement = $connection->prepare(' INSERT INTO `media_thumbnail_size` (`id`, `width`, `height`, created_at) VALUES (:id, :width, :height, :createdAt) ');

        $sizes = [];
        foreach ($thumbnailSizes as $thumbnailSize) {
            $result = array_filter($allSizesfunction D$var) use ($thumbnailSize) {
                
$this->joinBasic($definition$context$table$query$fields$criteria$partial);

        if (!empty($criteria->getIds())) {
            $this->queryHelper->addIdCondition($criteria$definition$query);
        }

        if ($criteria->getTitle()) {
            $query->setTitle($criteria->getTitle() . '::read');
        }

        return $query->executeQuery()->fetchAllAssociative();
    }

    /** * @param EntityCollection<Entity> $collection * @param array<string, mixed> $partial */
    private function loadManyToMany(
        Criteria $criteria,
        ManyToManyAssociationField $association,
        Context $context,
        EntityCollection $collection,
        
$commandTester = new CommandTester($this->adminRefreshIndexCommand);
        $commandTester->execute([]);

        $message = $commandTester->getDisplay();

        static::assertStringContainsString('Are you sure you want to reset the Admin Elasticsearch indexing?', $message);
        static::assertStringContainsString('Admin Elasticsearch indices deleted and queue cleared', $message);

        $client = $this->getDiContainer()->get(Client::class);
        $client->indices()->get(['index' => EnvironmentHelper::getVariable('SHOPWARE_ADMIN_ES_INDEX_PREFIX') . '*']);

        $tasks = $this->connection->fetchAllAssociative('SELECT `index` FROM admin_elasticsearch_index_task');

        static::assertEmpty($tasks);
    }

    protected function getDiContainer(): ContainerInterface
    {
        return $this->getContainer();
    }
}
'id' => $id,
                        'name' => 'test child',
                    ],
                    'cascades' => [
                        ['id' => $id, 'name' => 'test child'],
                    ],
                ],
            ],
            WriteContext::createFromContext(Context::createDefaultContext())
        );

        $parents = $this->connection->fetchAllAssociative('SELECT * FROM delete_cascade_parent');
        static::assertCount(1, $parents);

        $children = $this->connection->fetchAllAssociative('SELECT * FROM delete_cascade_child');
        static::assertCount(1, $children);

        $this->writer->delete(
            $this->getContainer()->get(DeleteCascadeParentDefinition::class),
            [
                ['id' => $id],
            ],
            WriteContext::createFromContext(Context::createDefaultContext())
        );
private function hasBoundAccount(string $email): bool
    {
        $query = $this->connection->createQueryBuilder();

        /** @var array{email: string, guest: int, bound_sales_channel_id: string|null}[] $results */
        $results = $query
            ->select('LOWER(HEX(bound_sales_channel_id)) as bound_sales_channel_id')
            ->from('customer')
            ->where($query->expr()->eq('email', $query->createPositionalParameter($email)))
            ->executeQuery()
            ->fetchAllAssociative();

        foreach ($results as $result) {
            if ($result['bound_sales_channel_id']) {
                return true;
            }
        }

        return false;
    }

    private function requiredVatIdField(string $countryId, SalesChannelContext $context): bool
    {
public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }

    /** * @return array<int|string, array<string, mixed>> */
    private function getDefaultMailTemplates(Connection $connection): array
    {
        $mailTemplates = $connection->fetchAllAssociative(' SELECT LOWER(HEX(mail_template.id)) as mail_template_id, LOWER(HEX(mail_template.mail_template_type_id)) as mail_template_type_id, mail_template_type.technical_name FROM mail_template INNER JOIN mail_template_type ON mail_template_type.id = mail_template.mail_template_type_id WHERE mail_template.system_default = 1 ');

        $result = [];
        foreach ($mailTemplates as $mailTemplate) {
            $result[$mailTemplate['technical_name']] = [
                
static::assertNotNull($order);

        $event = new CheckoutOrderPlacedEvent(
            Context::createDefaultContext(),
            $order,
            Defaults::SALES_CHANNEL_TYPE_STOREFRONT
        );

        $updater = $this->getContainer()->get(PromotionRedemptionUpdater::class);
        $updater->orderPlaced($event);

        $promotions = $connection->fetchAllAssociative(
            'SELECT `id`, `orders_per_customer_count` FROM `promotion` WHERE `id` = :id',
            ['id' => Uuid::fromHexToBytes($voucherA)]
        );

        $expected_json = json_encode([$this->ids->get('customer') => 1], \JSON_THROW_ON_ERROR);
        static::assertIsString($expected_json);

        static::assertCount(1, $promotions);
        static::assertJsonStringEqualsJsonString(
            $expected_json,
            $promotions[0]['orders_per_customer_count']
        );

    public function getCreationTimestamp(): int
    {
        return 1625304609;
    }

    public function update(Connection $connection): void
    {
        $appNames = $this->getAllApps($connection);
        $privileges = $this->getAppPrivileges($appNames);

        $roles = $connection->fetchAllAssociative(
            'SELECT * from `acl_role` WHERE `id` IN (SELECT DISTINCT `acl_role_id` FROM `acl_user_role`)',
        );
        $updatedAt = (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_FORMAT);

        foreach ($roles as $role) {
            $currentPrivileges = json_decode((string) $role['privileges'], true, 512, \JSON_THROW_ON_ERROR);
            $currentPrivileges = array_merge($currentPrivileges$privileges);
            $currentPrivileges = array_unique($currentPrivileges);

            $role['privileges'] = json_encode($currentPrivileges, \JSON_THROW_ON_ERROR);
            $role['updated_at'] = $updatedAt;

            
AppScriptConditionEvents::APP_SCRIPT_CONDITION_WRITTEN_EVENT => 'updatePayloads',
        ];
    }

    /** * @param list<string> $ids * * @return array<string, array{payload: string|null, invalid: bool}> */
    public function update(array $ids): array
    {
        $conditions = $this->connection->fetchAllAssociative(
            'SELECT LOWER(HEX(rc.rule_id)) as array_key, rc.*, rs.script, rs.identifier, rs.updated_at as lastModified FROM rule_condition rc LEFT JOIN app_script_condition rs ON rc.script_id = rs.id AND rs.active = 1 WHERE rc.rule_id IN (:ids) ORDER BY rc.rule_id, rc.position',
            ['ids' => Uuid::fromHexToBytesList($ids)],
            ['ids' => ArrayParameterType::STRING]
        );

        $rules = FetchModeHelper::group($conditions);

        
$params = ['value' => $deleteId];

        $types = [];

        if (\count($excludeThisIds) > 0) {
            $sqlStatement .= ' AND id NOT IN (:excludedIds)';
            $params['excludedIds'] = $this->convertHexArrayToByteArray($excludeThisIds);
            $types['excludedIds'] = ArrayParameterType::STRING;
        }

        $results = $this->connection->executeQuery($sqlStatement$params$types)->fetchAllAssociative();

        if (\count($results) === 0) {
            return [];
        }

        foreach ($results as $row) {
            $affectedIds[] = $row['id'];

            $tags[] = Uuid::fromBytesToHex($row['id']);
        }

        


        foreach ($customFieldSets as $customFieldSet) {
            $this->customFieldSetRepository->upsert([$customFieldSet]$this->context);
        }

        $snippets = FetchModeHelper::group(
            $this->connection->executeQuery(' SELECT snippet_set.iso, snippet.* FROM snippet LEFT JOIN snippet_set ON snippet_set.id = snippet.snippet_set_id ')->fetchAllAssociative()
        );

        $snippetCount = $this->connection->executeQuery('SELECT count(*) FROM snippet')->fetchFirstColumn();

        static::assertSame($expectedCount(int) $snippetCount[0]);
        foreach ($snippets as $locale => $languageSnippets) {
            foreach ($languageSnippets as $snippet) {
                static::assertSame($expectedSnippets[$locale][$snippet['translation_key']]$snippet['value']);
            }
        }
    }

    
$query->andWhere('`category`.type != :linkType');

        $excludedCategoryIds = $this->getExcludedCategoryIds($context);
        if (!empty($excludedCategoryIds)) {
            $query->andWhere('`category`.id NOT IN (:categoryIds)');
            $query->setParameter('categoryIds', Uuid::fromHexToBytesList($excludedCategoryIds), ArrayParameterType::STRING);
        }

        $query->setParameter('versionId', Uuid::fromHexToBytes(Defaults::LIVE_VERSION));
        $query->setParameter('linkType', CategoryDefinition::TYPE_LINK);

        return $query->executeQuery()->fetchAllAssociative();
    }

    private function getExcludedCategoryIds(SalesChannelContext $salesChannelContext): array
    {
        $salesChannelId = $salesChannelContext->getSalesChannel()->getId();

        $excludedUrls = $this->configHandler->get(ConfigHandler::EXCLUDED_URLS_KEY);
        if (empty($excludedUrls)) {
            return [];
        }

        

    public function __construct(private readonly Connection $connection)
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);

        try {
            $this->connection->fetchAllAssociative('SHOW COLUMNS FROM migration');

            $io->success('Shopware is installed');

            return self::SUCCESS;
        } catch (\Exception) {
            $io->error('Shopware is not installed');

            return self::FAILURE;
        }
    }
}
        $num = 3;
        $data = $this->prepareImportExportProfileTestData($num);

        // do API calls         foreach ($data as $entry) {
            $this->getBrowser()->request('POST', $this->prepareRoute()[][][]json_encode($entry, \JSON_THROW_ON_ERROR));
            $response = $this->getBrowser()->getResponse();
            static::assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()$response->getContent());
        }

        // read created data from db         $records = $this->connection->fetchAllAssociative('SELECT * FROM import_export_profile');
        $translationRecords = $this->getTranslationRecords();

        // compare expected and resulting data         static::assertCount($num$records);
        foreach ($records as $record) {
            $expect = $data[$record['id']];
            static::assertSame($expect['name']$record['name']);
            static::assertSame($expect['label']$translationRecords[$record['id']]['label']);
            static::assertEquals($expect['systemDefault'](bool) $record['system_default']);
            static::assertSame($expect['sourceEntity']$record['source_entity']);
            static::assertSame($expect['fileType']$record['file_type']);
            
->select('state.short_code, state.id, state_translation.name')
            ->from('country_state', 'state')
            ->innerJoin(
                'state',
                'country_state_translation',
                'state_translation',
                'state.id = state_translation.country_state_id AND state_translation.language_id = :germanLanguageId'
            )->where('state.short_code IN (:shortCodes)')
            ->setParameter('germanLanguageId', $germanLanguageId)
            ->setParameter('shortCodes', array_keys($default), ArrayParameterType::STRING)
            ->executeQuery()
            ->fetchAllAssociative();

        foreach ($translations as $translation) {
            $shortCode = $translation['short_code'];

            if ($translation['name'] !== $default[$shortCode]) {
                continue;
            }

            $connection->update(
                'country_state_translation',
                ['name' => $germanTranslations[$shortCode]],
                [
Home | Imprint | This part of the site doesn't use cookies.