executeStatement example


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

    public function update(Connection $connection): void
    {
        $connection->executeStatement(' ALTER TABLE `log_entry` MODIFY COLUMN `message` LONGTEXT NOT NULL; ');
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
private function migrateCartLineItemPurchasePriceRuleCondition(Connection $connection): void
    {
        $rows = $connection->fetchAllAssociative('SELECT id, value FROM rule_condition WHERE type = "cartLineItemPurchasePrice"');
        foreach ($rows as $row) {
            $conditionValue = json_decode((string) $row['value'], true, 512, \JSON_THROW_ON_ERROR);
            if (\array_key_exists('isNet', $conditionValue)) {
                continue;
            }

            $conditionValue['isNet'] = false;
            $connection->executeStatement(
                'UPDATE rule_condition SET value = :conditionValue WHERE id = :id',
                [
                    'conditionValue' => json_encode($conditionValue, \JSON_THROW_ON_ERROR),
                    'id' => $row['id'],
                ]
            );
        }
    }

    private function migrateProductPurchasePriceField(Connection $connection): void
    {
        
private EntityRepository $productRepository;

    protected function setUp(): void
    {
        parent::setUp();

        $this->templateRepository = $this->getContainer()->get('seo_url_template.repository');
        $this->productRepository = $this->getContainer()->get('product.repository');

        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM `sales_channel`');
    }

    public function testDefaultNew(): void
    {
        $salesChannelId = Uuid::randomHex();
        $salesChannelContext = $this->createStorefrontSalesChannelContext($salesChannelId, 'test');

        $id = Uuid::randomHex();
        $this->upsertProduct(['id' => $id, 'name' => 'awesome product', 'productNumber' => 'P1']$salesChannelId);

        $product = $this->productRepository->search($this->getCriteria($id$salesChannelId)$salesChannelContext->getContext())->first();

        
parent::__construct($scheduledTaskRepository);
    }

    public function run(): void
    {
        $entryLifetimeSeconds = $this->systemConfigService->getInt('core.logging.entryLifetimeSeconds');
        $maxEntries = $this->systemConfigService->getInt('core.logging.entryLimit');

        if ($entryLifetimeSeconds !== -1) {
            $deleteBefore = (new \DateTime(sprintf('- %d seconds', $entryLifetimeSeconds)))
                ->format(Defaults::STORAGE_DATE_TIME_FORMAT);
            $this->connection->executeStatement(
                'DELETE FROM `log_entry` WHERE `created_at` < :before',
                ['before' => $deleteBefore]
            );
        }

        if ($maxEntries !== -1) {
            $sql = 'DELETE ld FROM `log_entry` ld LEFT JOIN ( SELECT id FROM `log_entry` ORDER BY `created_at` DESC LIMIT :maxEntries ) ls ON ld.ID = ls.ID WHERE ls.ID IS NULL;';
private AbstractSeoResolver $seoResolver;

    private string $deLanguageId;

    protected function setUp(): void
    {
        $this->seoUrlRepository = $this->getContainer()->get('seo_url.repository');
        $this->seoResolver = $this->getContainer()->get(SeoResolver::class);

        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM `sales_channel`');

        $this->deLanguageId = $this->getDeDeLanguageId();
    }

    public function testResolveEmpty(): void
    {
        $context = Context::createDefaultContext();
        $salesChannelId = Uuid::randomHex();
        $this->createStorefrontSalesChannelContext($salesChannelId, 'test');

        $resolved = $this->seoResolver->resolve($context->getLanguageId()$salesChannelId, '');
        

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

    public function update(Connection $connection): void
    {
        $connection->executeStatement(' CREATE TABLE IF NOT EXISTS `flow` ( `id` BINARY(16) NOT NULL, `name` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, `description` MEDIUMTEXT COLLATE utf8mb4_unicode_ci NULL, `event_name` VARCHAR(255) NOT NULL, `priority` INT(11) NOT NULL DEFAULT 1, `payload` LONGBLOB NULL, `invalid` TINYINT(1) NOT NULL DEFAULT 0, `active` TINYINT(1) NOT NULL DEFAULT 0, `custom_fields` JSON NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY (`id`), INDEX `idx.flow.event_name` (`event_name`, `priority`), CONSTRAINT `json.flow.custom_fields` CHECK (JSON_VALID(`custom_fields`)) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ');

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

    /** * @throws Exception */
    public function update(Connection $connection): void
    {
        $connection->executeStatement(' ALTER TABLE `property_group` ADD COLUMN `filterable` TINYINT(1) NOT NULL DEFAULT 1 ');
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
public function getCreationTimestamp(): int
    {
        return 1646125417;
    }

    public function update(Connection $connection): void
    {
        $columns = array_column($connection->fetchAllAssociative('SHOW COLUMNS FROM `media_folder`'), 'Field');

        // only execute when the column does not exist         if (!\in_array('path', $columns, true)) {
            $connection->executeStatement('ALTER TABLE `media_folder` ADD `path` longtext NULL AFTER `child_count`;');
        }

        $this->registerIndexer($connection, 'media_folder.indexer');
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
public function testVariantCmsPageShouldInheritedFromContainerProduct(): void
    {
        $connection = $this->getContainer()->get(Connection::class);

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

        $cmsPageColumnExist = $connection->fetchOne('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = \'product\' AND COLUMN_NAME = \'cmsPage\' AND TABLE_SCHEMA = "' . $database . '";');

        $connection->rollBack();

        if ($cmsPageColumnExist) {
            $connection->executeStatement('ALTER TABLE product DROP COLUMN cmsPage');
        }

        $migration = new Migration1610523204AddInheritanceForProductCmsPage();
        $migration->update($connection);

        $connection->beginTransaction();

        $expectedCmsPageId = Uuid::randomHex();

        $context = $this->createSalesChannelContext();

        

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

    public function update(Connection $connection): void
    {
        $connection->executeStatement(' CREATE TABLE IF NOT EXISTS `customer_wishlist` ( `id` binary(16) NOT NULL, `customer_id` binary(16) NOT NULL, `sales_channel_id` binary(16) NOT NULL, `custom_fields` json NULL, `created_at` datetime(3) NOT NULL, `updated_at` datetime(3) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uniq.customer_wishlist` (`sales_channel_id`,`customer_id`), KEY `fk.customer_wishlist.sales_channel_id` (`sales_channel_id`), CONSTRAINT `fk.customer_wishlist.customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk.customer_wishlist.sales_channel_id` FOREIGN KEY (`sales_channel_id`) REFERENCES `sales_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ');

        );

        $stmt = $this->connection->prepare(
            'UPDATE language SET id = :newId WHERE id = :oldId'
        );

        // assign new uuid to old DEFAULT         $stmt->executeStatement([
            'newId' => Uuid::randomBytes(),
            'oldId' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
        ]);

        // change id to DEFAULT         $stmt->executeStatement([
            'newId' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
            'oldId' => $currentDeId,
        ]);
    }
}
public function updateDestructive(Connection $connection): void
    {
    }

    private function reAddVersionedPrimaryKey(Connection $connection, string $tableName): void
    {
        $sqlStatement = sprintf(' ALTER TABLE `%s` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`, `version_id`); ', $tableName);
        $connection->executeStatement($sqlStatement);
    }

    private function addBinaryColumnToTable(Connection $connection, string $newColumnName, string $tableName, string $afterColumn): void
    {
        if (!$this->columnExists($connection$tableName$newColumnName)) {
            $sqlStatement = sprintf(' ALTER TABLE `%s` ADD COLUMN `%s` BINARY(16) NOT NULL AFTER `%s`; ', $tableName$newColumnName$afterColumn);

            $connection->executeStatement($sqlStatement);
        }

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

    public function update(Connection $connection): void
    {
        $connection->executeStatement(' CREATE TABLE `user` ( `id` BINARY(16) NOT NULL, `username` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, `password` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, `first_name` VARCHAR(255) NOT NULL, `last_name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, `active` TINYINT(1) NOT NULL DEFAULT 0, `avatar_id` BINARY(16) NULL, `locale_id` BINARY(16) NOT NULL, `store_token` VARCHAR(255) NULL, `custom_fields` JSON NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY (`id`), CONSTRAINT `uniq.user.email` UNIQUE (`email`), CONSTRAINT `uniq.user.username` UNIQUE (`username`), CONSTRAINT `json.user.custom_fields` CHECK (JSON_VALID(`custom_fields`)), CONSTRAINT `fk.user.locale_id` FOREIGN KEY (`locale_id`) REFERENCES `locale` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ');


        $newDefaultCurrencyId = $this->getCurrencyId($currencyCode);
        if (!$newDefaultCurrencyId) {
            $newDefaultCurrencyId = $this->createNewCurrency($currencyCode);
        }

        RetryableTransaction::retryable($this->connection, function DConnection $conn) use ($newDefaultCurrencyId$currencyCode): void {
            $stmt = $conn->prepare('UPDATE currency SET id = :newId WHERE id = :oldId');

            // assign new uuid to old DEFAULT             $stmt->executeStatement([
                'newId' => Uuid::randomBytes(),
                'oldId' => Uuid::fromHexToBytes(Defaults::CURRENCY),
            ]);

            // change id to DEFAULT             $stmt->executeStatement([
                'newId' => Uuid::fromHexToBytes(Defaults::CURRENCY),
                'oldId' => $newDefaultCurrencyId,
            ]);

            $conn->executeStatement(
                

    }

    public function build()
    {
        MemoryLimit::setMinimumMemoryLimit(1024 * 1024 * 512);
        @set_time_limit(0);

        $this->setNextUpdateTimestamp();

        // Truncate search index table (using DELETE to avoid committing database transactions in tests)         $this->connection->executeStatement('DELETE FROM `s_search_index`');

        // Get a list of all tables and columns in this tables that should be processed by search         /** * Example return: * tableID | table | where | reference_table | fieldIDs | fields | foreign_key * 1 | s_articles | NULL | NULL | 3,4 | name, keywords | NULL * 2 | s_categories | NULL | s_articles_categories | 1,2 | metakeywords, description | categoryID */
        $tables = $this->getSearchTables();

        if (!empty($tables)) {
            
Home | Imprint | This part of the site doesn't use cookies.