executeQuery example



        return $translations;
    }

    /** * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception */
    private function fetchSystemMailTemplateIdFromType(Connection $connection, string $type): ?string
    {
        $templateTypeId = $connection->executeQuery(' SELECT `id` from `mail_template_type` WHERE `technical_name` = :type ', ['type' => $type])->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;
        }

        
private function createNewLanguageEntry(string $iso): string
    {
        $id = Uuid::randomBytes();

        $stmt = $this->connection->prepare(
            ' SELECT LOWER (HEX(locale.id)) FROM `locale` WHERE LOWER(locale.code) = LOWER(?)'
        );
        $localeId = $stmt->executeQuery([$iso])->fetchOne();

        $stmt = $this->connection->prepare(
            ' SELECT LOWER(language.id) FROM `language` WHERE LOWER(language.name) = LOWER(?)'
        );
        $englishId = $stmt->executeQuery(['english'])->fetchOne();

        $stmt = $this->connection->prepare(
            ' SELECT locale_translation.name FROM `locale_translation` WHERE LOWER(HEX(locale_id)) = ? AND LOWER(language_id) = ?'

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

    public function update(Connection $connection): void
    {
        $id = $connection->executeQuery(
            'SELECT `id` FROM `import_export_profile` WHERE `name` = :name AND `system_default` = 1',
            ['name' => 'Default product']
        )->fetchOne();
        if ($id) {
            $productMappingProfile = require __DIR__ . '/../Fixtures/import-export-profiles/ProductMappingProfile.php';
            $connection->update('import_export_profile', ['mapping' => json_encode($productMappingProfile, \JSON_THROW_ON_ERROR)]['id' => $id]);
        }
    }

    public function updateDestructive(Connection $connection): void
    {
        
'country' => $address->getCountry() ? $address->getCountry()->getId() : null,
                'state' => $address->getState() ? $address->getState()->getId() : null,
            ]);
        }

        $storedData = [
            'customerId' => $customer->getId(),
            'register' => ['billing' => $mailContext], // This structure being required by \sAdmin::sSaveRegisterSendConfirmation             'fromCheckout' => $fromCheckout,
        ];

        $this->connection->executeQuery($sql[$customer->getDoubleOptinEmailSentDate()->format('Y-m-d H:i:s')$hashserialize($storedData)]);

        return (int) $this->connection->fetchColumn('SELECT id FROM `s_core_optin` WHERE `hash` = :hash', [':hash' => $hash]);
    }

    private function saveOptinIdToCustomer(int $optinId, Customer $customer): void
    {
        $customer->setRegisterOptInId($optinId);
        $this->modelManager->persist($customer);
        $this->modelManager->flush($customer);
    }
}
$serializedData = $this->filterData($type$data$merge ? $key : null);

        if (!empty($data)) {
            $sql = ' INSERT INTO `s_core_translations` ( `objecttype`, `objectdata`, `objectkey`, `objectlanguage`, `dirty` ) VALUES ( :type, :data, :key, :language, 1 ) ON DUPLICATE KEY UPDATE `objectdata`=VALUES(`objectdata`), `dirty` = 1; ';
            $this->connection->executeQuery(
                $sql,
                [
                    ':type' => $type,
                    ':data' => $serializedData,
                    ':key' => $merge ? 1 : $key,
                    ':language' => $language,
                ]
            );
        } else {
            $sql = ' DELETE FROM `s_core_translations` WHERE `objecttype`= :type AND `objectkey`= :key AND `objectlanguage`= :language ';


    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;
    }

    
throw new Exception('No column type provided');
        }

        $sql = sprintf(
            'ALTER TABLE `%s` ADD `%s` %s NULL DEFAULT %s',
            $table,
            $column,
            $type,
            $defaultValue
        );

        $this->connection->executeQuery($sql);
    }

    /** * {@inheritdoc} * * @throws \Doctrine\DBAL\DBALException * @throws Exception */
    public function changeColumn($table$originalName$newName$type$defaultValue = null)
    {
        $this->validate($table$originalName);

        
$connectionVariables[] = 'SET @@session.time_zone = "UTC"';
            }

            if ($setSessionVariables) {
                $connectionVariables[] = 'SET @@group_concat_max_len = CAST(IF(@@group_concat_max_len > 320000, @@group_concat_max_len, 320000) AS UNSIGNED)';
                $connectionVariables[] = 'SET sql_mode=(SELECT REPLACE(@@sql_mode,\'ONLY_FULL_GROUP_BY\',\'\'))';
            }

            if (empty($connectionVariables)) {
                return;
            }
            $connection->executeQuery(implode(';', $connectionVariables));
        } catch (\Throwable) {
        }
    }

    /** * Dumps the preload file to an always known location outside the generated cache folder name */
    protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, string $class, string $baseClass): void
    {
        parent::dumpContainer($cache$container$class$baseClass);
        $cacheDir = $this->getCacheDir();
        
public function testTimestampIsCorrect(): void
    {
        $migration = new Migration1676272001AddAccountTypeToCustomerProfileImportExport();
        static::assertEquals('1676272001', $migration->getCreationTimestamp());
    }

    public function testPreventUpdateIfProfileNotExists(): void
    {
        $this->prepare();

        $this->connection->executeQuery(
            'DELETE FROM `import_export_profile` WHERE `source_entity` =:source_entity and `name` = :name AND `system_default` = 1',
            [
                'source_entity' => CustomerDefinition::ENTITY_NAME,
                'name' => 'Default customer',
            ]
        );

        $migration = new Migration1676272001AddAccountTypeToCustomerProfileImportExport();
        $migration->update($this->connection);
    }

    
break;
            }
        }

        // why do we have inline sql queries in here?         // because we want to avoid any other private functions that accidentally access         // the database. all private getters should only access the local in-memory list         // to avoid additional database queries.         $this->databasePromotions = [];
        if (!empty($promotionIds)) {
            $promotionQuery = $this->connection->executeQuery(
                'SELECT * FROM `promotion` WHERE `id` IN (:ids)',
                ['ids' => $promotionIds],
                ['ids' => ArrayParameterType::STRING]
            );

            $this->databasePromotions = $promotionQuery->fetchAllAssociative();
        }

        $this->databaseDiscounts = [];
        if (!empty($discountIds)) {
            $discountQuery = $this->connection->executeQuery(
                
public function getUserEntityByUserCredentials(
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    ): ?UserEntityInterface {
        $builder = $this->connection->createQueryBuilder();
        $user = $builder->select(['user.id', 'user.password'])
            ->from('user')
            ->where('username = :username')
            ->setParameter('username', $username)
            ->executeQuery()
            ->fetchAssociative();

        if (!$user) {
            return null;
        }

        if (!password_verify($password(string) $user['password'])) {
            return null;
        }

        return new User(Uuid::fromBytesToHex($user['id']));
    }
return $password;
    }

    private function userExists(string $username): bool
    {
        $builder = $this->connection->createQueryBuilder();

        return $builder->select('1')
            ->from('user')
            ->where('username = :username')
            ->setParameter('username', $username)
            ->executeQuery()
            ->rowCount() > 0;
    }

    private function getLocaleOfSystemLanguage(): string
    {
        $builder = $this->connection->createQueryBuilder();

        return (string) $builder->select('locale.id')
                ->from('language', 'language')
                ->innerJoin('language', 'locale', 'locale', 'language.locale_id = locale.id')
                ->where('language.id = :id')
                
$this->context
        );
    }

    private function resetSystemLanguage(): void
    {
        $this->setNewSystemLanguage('en-GB');
    }

    private function getIsoId(string $iso): string
    {
        $result = $this->connection->executeQuery('SELECT LOWER(HEX(id)) FROM locale WHERE code = ?', [$iso]);

        return (string) $result->fetchOne();
    }

    private function getMigrationCount(string $namespacePrefix): int
    {
        $result = $this->connection->executeQuery(
            'SELECT COUNT(*) FROM migration WHERE class LIKE :class',
            ['class' => addcslashes($namespacePrefix, '\\_%') . '%']
        )
            ->fetchOne();

        

    }

    private function addDefaultMediaFolder(Connection $connection): void
    {
        $defaultFolderId = Uuid::randomBytes();
        $configurationId = Uuid::randomBytes();

        $connection->executeQuery(
            'REPLACE INTO `media_default_folder` SET id = :id, entity = :entity, association_fields = :association_fields, created_at = :created_at;',
            [
                'id' => $defaultFolderId,
                'entity' => PaymentMethodDefinition::ENTITY_NAME,
                'association_fields' => '["paymentMethods"]',
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]
        );

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

    public function update(Connection $connection): void
    {
        $columns = $connection->executeQuery(' SELECT COLUMN_NAME,DATA_TYPE FROM information_schema.columns WHERE table_schema = :database AND table_name = \'state_machine_history\' AND (COLUMN_NAME = \'referenced_id\' OR COLUMN_NAME = \'referenced_version_id\'); ', ['database' => $connection->getDatabase()])->fetchAllAssociativeIndexed();

        if (!\array_key_exists('referenced_id', $columns)) {
            $connection->executeStatement(' ALTER TABLE `state_machine_history` ADD COLUMN `referenced_id` BINARY(16) GENERATED ALWAYS AS ( COALESCE(UNHEX(JSON_UNQUOTE(JSON_EXTRACT(`entity_id`, \'$.id\'))), 0x0) ) STORED; ');
Home | Imprint | This part of the site doesn't use cookies.