fetchOne example

protected function setUp(): void
    {
        $this->connection = KernelLifecycleManager::getConnection();

        $getDeLanguageSql = <<<SQL SELECT language.id FROM language JOIN locale ON locale.id = language.locale_id WHERE locale.code = 'de-DE' SQL;

        $deLanguageId = $this->connection->fetchOne($getDeLanguageSql);

        $getEnLanguageSql = <<<SQL SELECT language.id FROM language JOIN locale ON locale.id = language.locale_id WHERE locale.code = 'en-GB' SQL;

        $enLanguageId = $this->connection->fetchOne($getEnLanguageSql);

        $this->languages = [
            
$this->browser
            ->request(
                'POST',
                '/store-api/newsletter/subscribe',
                [
                    'email' => 'test@test.de',
                    'option' => 'subscribe',
                    'storefrontUrl' => 'http://localhost',
                ]
            );

        $count = (int) $this->getContainer()->get(Connection::class)->fetchOne('SELECT COUNT(*) FROM newsletter_recipient WHERE email = "test@test.de"');
        static::assertSame(1, $count);
        $hash = $this->getContainer()->get(Connection::class)->fetchOne('SELECT hash FROM newsletter_recipient WHERE email = "test@test.de"');

        $this->browser
            ->request(
                'POST',
                '/store-api/newsletter/confirm',
                [
                    'email' => 'test@test.de',
                    'hash' => $hash,
                ]
            );

    private function getCurrentDbState(): array
    {
        $connection = Kernel::getConnection();

        $rawTables = $connection->fetchAllAssociative('SHOW TABLES');
        $stateResult = [];

        foreach ($rawTables as $nested) {
            $tableName = end($nested);
            $count = $connection->fetchOne('SELECT COUNT(*) FROM ' . $tableName);

            $stateResult[(string) $tableName] = (int) $count;
        }

        return $stateResult;
    }

    /** * @param array<mixed> $state * * @return array<mixed> */
self::checkVersion($connection);

        return $connection;
    }

    private static function checkVersion(Connection $connection): void
    {
        // https://developer.shopware.com/docs/guides/installation/overview#system-requirements         $mysqlRequiredVersion = '5.7.21';
        $mariaDBRequiredVersion = '10.3.22';

        $version = $connection->fetchOne('SELECT VERSION()');
        \assert(\is_string($version));
        if (\mb_stripos($version, 'mariadb') !== false) {
            if (version_compare($version$mariaDBRequiredVersion, '<')) {
                throw new DatabaseSetupException(sprintf(
                    'Your database server is running MariaDB %s, but Shopware 6 requires at least MariaDB %s OR MySQL %s',
                    $version,
                    $mariaDBRequiredVersion,
                    $mysqlRequiredVersion
                ));
            }

            
/** * @internal * * @covers \Shopware\Core\Migration\V6_5\Migration1688717599UpdateCreatedByIdAndUpdatedByIdInOrderAndCustomer */
class Migration1688717599UpdateCreatedByIdAndUpdatedByIdInOrderAndCustomerTest extends TestCase
{
    public function testUpdateRuleAssociationsToRestrict(): void
    {
        $conn = KernelLifecycleManager::getConnection();

        $database = $conn->fetchOne('select database();');

        $migration = new Migration1688717599UpdateCreatedByIdAndUpdatedByIdInOrderAndCustomer();
        $migration->update($conn);

        /** @var array<array<string, mixed>> $customerForeignKeyInfoUpdated */
        $customerForeignKeyInfoUpdated = $conn->fetchAllAssociative('SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE TABLE_NAME = "customer" AND REFERENCED_TABLE_NAME = "user" AND CONSTRAINT_SCHEMA = "' . $database . '";');

        static::assertCount(2, $customerForeignKeyInfoUpdated);
        static::assertEquals($customerForeignKeyInfoUpdated[0]['CONSTRAINT_NAME'], 'fk.customer.created_by_id');
        static::assertEquals($customerForeignKeyInfoUpdated[1]['CONSTRAINT_NAME'], 'fk.customer.updated_by_id');
        static::assertEquals($customerForeignKeyInfoUpdated[0]['DELETE_RULE'], 'SET NULL');
        
$this->getPaymentPaidPartiallyPlainTemplateDe()
        );
    }

    public function updateDestructive(Connection $connection): void
    {
    }

    private function fetchLanguageId(string $code, Connection $connection): ?string
    {
        /** @var string|null $langId */
        $langId = $connection->fetchOne(' SELECT `language`.`id` FROM `language` INNER JOIN `locale` ON `language`.`locale_id` = `locale`.`id` WHERE `code` = :code LIMIT 1 ', ['code' => $code]);

        if (!$langId && $code !== 'en-GB') {
            return null;
        }

        if (!$langId) {
            return Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM);
        }

        
/** @var ProductCollection $products */
        $products = $this->repository->search(new Criteria([$id]), Context::createDefaultContext())->getEntities();
        static::assertTrue($products->has($id));

        $product = $products->get($id);

        static::assertSame('Update', $product->getName());
        $currencyPrice = $product->getCurrencyPrice(Defaults::CURRENCY);
        static::assertInstanceOf(Price::class$currencyPrice);
        static::assertSame(12.0, $currencyPrice->getGross());

        $count = (int) $this->connection->fetchOne('SELECT COUNT(id) FROM product WHERE ean = :filterId', ['filterId' => $filterId]);
        static::assertSame(1, $count);
    }

    public function testSwitchVariantToFullProduct(): void
    {
        $id = Uuid::randomHex();
        $child = Uuid::randomHex();

        $filterId = Uuid::randomHex();
        $data = [
            ['id' => $id, 'productNumber' => Uuid::randomHex(), 'stock' => 10, 'name' => 'Insert', 'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 9, 'linked' => false]], 'tax' => ['name' => 'test', 'taxRate' => 10], 'manufacturer' => ['name' => 'test'], 'ean' => $filterId],
            [

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

    public function update(Connection $connection): void
    {
        $featureColumn = $connection->fetchOne(
            'SHOW COLUMNS FROM `event_action` WHERE `Field` LIKE :column;',
            ['column' => 'custom_fields']
        );

        if ($featureColumn === false) {
            $connection->executeStatement(
                'ALTER TABLE `event_action` ADD COLUMN `custom_fields` JSON NULL AFTER `config`, ADD CONSTRAINT `json.event_action.custom_fields` CHECK (JSON_VALID(`custom_fields`));'
            );
        }
    }
public function getCreationTimestamp(): int
    {
        return 1604499476;
    }

    public function update(Connection $connection): void
    {
        $createdAt = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        foreach (self::CONFIG_KEYS as $configKey) {
            $configPresent = $connection->fetchOne('SELECT 1 FROM `system_config` WHERE `configuration_key` = ?', [$configKey]);

            if ($configPresent !== false) {
                continue;
            }

            $connection->insert('system_config', [
                'id' => Uuid::randomBytes(),
                'configuration_key' => $configKey,
                'configuration_value' => '{"_value": true}',
                'created_at' => $createdAt,
            ]);
        }
$deLangId,
                $getHtmlTemplateDe,
                $getPlainTemplateDe
            );
        }
    }

    private function fetchSystemMailTemplateIdFromType(Connection $connection, string $mailTemplateType): ?string
    {
        $templateTypeId = $connection->executeQuery(' SELECT `id` from `mail_template_type` WHERE `technical_name` = :type ', ['type' => $mailTemplateType])->fetchOne();

        $templateId = $connection->executeQuery(' SELECT `id` from `mail_template` WHERE `mail_template_type_id` = :typeId AND `system_default` = 1 AND `updated_at` IS NULL ', ['typeId' => $templateTypeId])->fetchOne();

        if ($templateId === false || !\is_string($templateId)) {
            return null;
        }

        return $templateId;
    }

    
final public const DELIVERY_TIME_NAME_DE = 'Sofort verfügbar';

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

    public function update(Connection $connection): void
    {
        $downloadDeliveryTime = Uuid::randomBytes();

        $deliveryTimeTranslation = $connection->fetchOne(
            'SELECT LOWER(HEX(delivery_time_id)) FROM delivery_time_translation WHERE name = :deliveryTimeName',
            ['deliveryTimeName' => self::DELIVERY_TIME_NAME_EN]
        );

        if ($deliveryTimeTranslation) {
            return;
        }

        $connection->insert('delivery_time', [
            'id' => $downloadDeliveryTime,
            'min' => 0,
            
->addFilter(new EqualsFilter('handlerIdentifier', PrePayment::class));

        $id = $repository->searchIds($criteria, Context::createDefaultContext())->getIds()[0];
        static::assertIsString($id);

        return $id;
    }

    private function getStateId(string $state, string $machine): ?string
    {
        return $this->getContainer()->get(Connection::class)
            ->fetchOne(' SELECT LOWER(HEX(state_machine_state.id)) FROM state_machine_state INNER JOIN state_machine ON state_machine.id = state_machine_state.state_machine_id AND state_machine.technical_name = :machine WHERE state_machine_state.technical_name = :state ', [
                'state' => $state,
                'machine' => $machine,
            ]);
    }
}


    private function getLanguageIdByLocale(Connection $connection, string $locale): ?string
    {
        $sql = <<<'SQL' SELECT `language`.`id` FROM `language` INNER JOIN `locale` ON `locale`.`id` = `language`.`locale_id` WHERE `locale`.`code` = :code SQL;

        $languageId = $connection->executeQuery($sql['code' => $locale])->fetchOne();
        if (!$languageId && $locale !== 'en-GB') {
            return null;
        }

        if (!$languageId) {
            return Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM);
        }

        return $languageId;
    }
}
$migration->update($this->connection);
    }

    private function addCustomerWithDoubleOptInButNotConfirmed(string $customerId): int|string
    {
        $customerAddressId = Uuid::randomBytes();
        $now = new \DateTimeImmutable();

        return $this->connection->insert('customer', [
            'id' => $customerId,
            'customer_group_id' => Uuid::fromHexToBytes(TestDefaults::FALLBACK_CUSTOMER_GROUP),
            'default_payment_method_id' => $this->connection->fetchOne('SELECT id FROM `payment_method` WHERE `active` = 1'),
            'sales_channel_id' => Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL),
            'language_id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            'default_billing_address_id' => $customerAddressId,
            'default_shipping_address_id' => $customerAddressId,
            'customer_number' => '123',
            'first_name' => 'Bar',
            'last_name' => 'Foo',
            'email' => 'foo@bar.com',
            'active' => 0,
            'double_opt_in_registration' => 1,
            'double_opt_in_email_sent_date' => $now->format('Y-m-d H:i:s'),
            


        $currency = $context->getCurrency();
        if ($currencyId === $currency->getId()) {
            return $currency->getFactor();
        }

        if (\array_key_exists($currencyId$this->currencyFactor)) {
            return $this->currencyFactor[$currencyId];
        }

        $currencyFactor = $this->connection->fetchOne(
            'SELECT `factor` FROM `currency` WHERE `id` = :currencyId',
            ['currencyId' => Uuid::fromHexToBytes($currencyId)]
        );

        if (!$currencyFactor) {
            throw new EntityNotFoundException('currency', $currencyId);
        }

        return $this->currencyFactor[$currencyId] = (float) $currencyFactor;
    }

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