fetchAssociative example


        $emotion = $this->connection->createQueryBuilder()
            ->select([
                'emotion.id',
                'emotion.device as devices',
                'emotion.show_listing as showListing',
            ])
            ->from('s_emotion', 'emotion')
            ->where('emotion.id = :emotionId')
            ->setParameter(':emotionId', $emotionId)
            ->execute()
            ->fetchAssociative();

        if (!\is_array($emotion)) {
            return [];
        }

        return $emotion;
    }

    /** * {@inheritdoc} */
    

#[Package('core')] class Migration1671723392AddWebhookLifetimeConfig extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1671723392;
    }

    public function update(Connection $connection): void
    {
        $config = $connection->fetchAssociative(
            'SELECT * FROM system_config WHERE configuration_key = \'core.webhook.entryLifetimeSeconds\''
        );

        if ($config !== false) {
            return;
        }

        $connection->insert('system_config', [
            'id' => Uuid::randomBytes(),
            'configuration_key' => 'core.webhook.entryLifetimeSeconds',
            'configuration_value' => '{"_value": "1209600"}', // 2 weeks
'A cms-aware custom entity should be connected to the categories'
        );

        $idColumn = match ($entity::class) {
            AppEntity::class => 'app_id',
            PluginEntity::class => 'plugin_id',
            default => throw new \Exception('Wrong Entity!')
        };
        $cmsAwareAndAdminUiSettings = $this->connection->executeQuery(
            "SELECT flags FROM custom_entity WHERE $idColumn = :id",
            ['id' => Uuid::fromHexToBytes($entity->getId())]
        )->fetchAssociative();

        static::assertNotFalse($cmsAwareAndAdminUiSettings);
        static::assertCount(2, $cmsAwareAndAdminUiSettings);

        static::assertIsString($flagsJson = file_get_contents(__DIR__ . '/_fixtures/other/flags.json'));
        static::assertEquals(
            $this->jsonDecode($flagsJson),
            $this->jsonDecode($cmsAwareAndAdminUiSettings['flags'])
        );
    }

    
// test variants should inherit the parent categories         $this->assertCategoriesInheritance($ids->get('parent')$ids->get('parent'));
        $this->assertCategoriesInheritance($ids->get('variant-1')$ids->get('parent'));
        $this->assertCategoriesInheritance($ids->get('variant-2')$ids->get('parent'));
    }

    private function assertManufacturerInheritance(string $id, ?string $fk, ?string $association): void
    {
        $connection = $this->getContainer()->get(Connection::class);

        $inheritance = $connection->fetchAssociative(
            'SELECT LOWER(HEX(product_manufacturer_id)) as fk, LOWER(HEX(manufacturer)) as association FROM product WHERE id = :id',
            ['id' => Uuid::fromHexToBytes($id)]
        );

        static::assertIsArray($inheritance);
        static::assertEquals($fk$inheritance['fk']);
        static::assertEquals($association$inheritance['association']);

        $context = Context::createDefaultContext();
        $context->setConsiderInheritance(true);

        
$this->connection = $this->getContainer()->get(Connection::class);
        $this->flowRepository = $this->getContainer()->get('flow.repository');
        $this->migration = new Migration1636362839FlowBuilderGenerateMultipleDoc();
        $this->ids = new TestDataCollection();
    }

    public function testMigration(): void
    {
        $this->createFlow();
        $this->migration->update($this->connection);

        $actionGenerateDocs = $this->connection->fetchAssociative(
            'SELECT id, action_name, config FROM flow_sequence WHERE action_name = :actionName',
            [
                'actionName' => 'action.generate.document',
            ]
        );

        static::assertIsArray($actionGenerateDocs);
        $newConfig = json_decode((string) $actionGenerateDocs['config'], true, 512, \JSON_THROW_ON_ERROR);
        static::assertNotNull($newConfig['documentTypes']);
    }

    

#[Package('core')] class Migration1673946817FixMediaFolderAssociationFields extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1673946817;
    }

    public function update(Connection $connection): void
    {
        $data = $connection->fetchAssociative('SELECT id, association_fields FROM media_default_folder WHERE entity = :user', ['user' => 'user']);

        if (!$data) {
            return;
        }

        $fields = \json_decode((string) $data['association_fields'], true);

        if (!\is_array($fields) || empty($fields)) {
            return;
        }

        
if ($this->hasColumn('customer', 'account_type')) {
            $this->connection->executeStatement('ALTER TABLE `customer` DROP COLUMN `account_type`');
        }
    }

    /** * @return false|CustomerData */
    private function fetchCustomer(): false|array
    {
        /** @var false|CustomerData $results */
        $results = $this->connection->fetchAssociative(
            'SELECT LOWER(HEX(`customer`.`id`)) AS `id`, `customer`.`company`, `customer`.`account_type`, `customer`.`vat_ids`, `customer_address`.`company` as `billing_company` FROM `customer` JOIN `customer_address` ON `customer`.`default_billing_address_id` = `customer_address`.`id` WHERE `customer`.`id` = :customerId',
            [
$this->context = Context::createDefaultContext();
    }

    public function testImportExportLogSingleCreateSuccess(): void
    {
        $data = $this->prepareImportExportLogTestData();

        $id = array_key_first($data);

        $this->logRepository->create([$data[$id]]$this->context);

        $record = $this->connection->fetchAssociative('SELECT * FROM import_export_log WHERE id = :id', ['id' => $id]);
        static::assertIsArray($record);

        $expect = $data[$id];
        static::assertNotEmpty($record);
        static::assertEquals($id$record['id']);
        static::assertSame($expect['activity']$record['activity']);
        static::assertSame($expect['state']$record['state']);
        static::assertSame($expect['userId'], Uuid::fromBytesToHex($record['user_id']));
        static::assertSame($expect['profileId'], Uuid::fromBytesToHex($record['profile_id']));
        static::assertSame($expect['fileId'], Uuid::fromBytesToHex($record['file_id']));
        static::assertSame($expect['username']$record['username']);
        
$migrationCollection = $this->collectMigrations();

        foreach ($migrationCollection->getMigrationSteps() as $_className => $migration) {
            try {
                $migration->update($connection);
            } catch (\Exception $e) {
                static::fail($_className . \PHP_EOL . $e->getMessage());
            }

            if ($this->isBasicDataMigration($_className)) {
                $deLiLocale = $connection->fetchAssociative(
                    'SELECT * FROM `locale` WHERE `code` = :code',
                    [
                        'code' => 'de-LI',
                    ]
                );
                static::assertIsArray($deLiLocale);

                $connection->update(
                    'language',
                    [
                        'name' => 'ForeignLang',
                        
return $paramData;
    }

    /** * @throws Exception * * @return array<string, string|null> */
    private function getAppFlowActionData(string $appFlowActionId): array
    {
        return $this->connection->fetchAssociative(
            'SELECT `parameters`, `headers` FROM `app_flow_action` WHERE id = :id',
            ['id' => Uuid::fromHexToBytes($appFlowActionId)]
        ) ?: [];
    }
}


        $parameters = [
            'taxId' => $taxId,
            'areaId' => $areaId,
            'countryId' => $countryId,
            'stateId' => $stateId,
            'customerGroupId' => $customerGroupId,
        ];

        $dbalConnection = $this->getEntityManager()->getConnection();
        $taxRate = $dbalConnection->fetchAssociative($sql$parameters);

        if (empty($taxRate['id'])) {
            $taxRate = $dbalConnection->fetchAssociative('SELECT tax FROM s_core_tax WHERE id = ?', [$taxId]);
        }

        return $taxRate['tax'];
    }

    /** * @param array<string, mixed>|array<array{property: string, value: mixed, expression?: string, operator?: string|null}>|null $filters * @param array<array{property: string, direction?: string}>|null $orderBy * * @return Query<Tax> */
->setMaxResults(1)
                ->setParameter('language_id', Uuid::fromHexToBytes($languageId))
                ->setParameter('sales_channel_id', Uuid::fromHexToBytes($salesChannelId))
                ->setParameter('pathInfo', '/' . ltrim((string) $seoPath['pathInfo'], '/'));

            // we only have an id when the hit seo url was not a canonical url, save the one filter condition             if (isset($seoPath['id'])) {
                $query->andWhere('id != :id')
                    ->setParameter('id', $seoPath['id']);
            }

            $canonical = $query->executeQuery()->fetchAssociative();
            if ($canonical) {
                $seoPath['canonicalPathInfo'] = '/' . ltrim((string) $canonical['seoPathInfo'], '/');
            }
        }

        $seoPath['pathInfo'] = '/' . ltrim((string) $seoPath['pathInfo'], '/');

        return $seoPath;
    }
}
$sql = <<<SQL SELECT NUMERIC_PRECISION, NUMERIC_SCALE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tax' AND COLUMN_NAME = 'tax_rate' AND TABLE_SCHEMA = :dbName; SQL;

        $dbName = $this->connection->getDatabase();

        /** @var array{NUMERIC_PRECISION: string, NUMERIC_SCALE: string, COLUMN_TYPE: string} $tableColumn */
        $tableColumn = $this->connection->fetchAssociative($sql['dbName' => $dbName]);

        static::assertEquals('10', $tableColumn['NUMERIC_PRECISION']);
        static::assertEquals('3', $tableColumn['NUMERIC_SCALE']);
        static::assertEquals('decimal(10,3)', $tableColumn['COLUMN_TYPE']);
    }

    public function testChangeColumnTaxRateOnTaxRuleTable(): void
    {
        $migration = new Migration1676274910ChangeColumnTaxRateAllowThreeDecimal();

        $migration->update($this->connection);

        
static::assertFalse($exists, 'Failed asserting that trigger `' . $triggerName . '` does not exist');
    }

    /** * @return array<string, mixed>|false */
    private function getColumnInfo(string $table, string $column): array|false
    {
        $database = $this->connection->fetchOne('SELECT DATABASE();');

        return $this->connection->fetchAssociative(
            ' SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME = :table AND TABLE_SCHEMA = :database AND COLUMN_NAME = :column',
            [
                'table' => $table,
                'database' => $database,
                'column' => $column,
            ]
        );
    }
$initData = [
            'email' => 'test@example.com',
            'status' => 'optIn',
            'hash' => 'confirm-hash',
            'salesChannelId' => $this->salesChannelId,
            'confirmedAt' => $firstConfirmedAt,
        ];
        $newsletterRecipientRepository->upsert([$initData], Context::createDefaultContext());

        // 2: validate start data         /** @var array<string, string|null> $row */
        $row = $connection->fetchAssociative('SELECT * FROM newsletter_recipient WHERE email = "test@example.com"');
        static::assertSame('optIn', $row['status']);
        static::assertSame($firstConfirmedAt$row['confirmed_at']);

        // 3: unsubscribe         $this->browser
            ->request(
                'POST',
                '/store-api/newsletter/unsubscribe',
                [
                    'email' => 'test@example.com',
                ]
            );
Home | Imprint | This part of the site doesn't use cookies.