MultiInsertQueryQueue example

'ruleId' => null,
                        'position' => 1,
                        'trueCase' => 0,
                        'displayGroup' => 1,
                    ],
                ],
            ], \JSON_THROW_ON_ERROR);

            $flowTemplates[] = $flowTemplate;
        }

        $queue = new MultiInsertQueryQueue($connection);

        foreach ($flowTemplates as $flowTemplate) {
            $queue->addInsert(FlowTemplateDefinition::ENTITY_NAME, $flowTemplate);
        }

        $queue->execute();
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive


    /** * @param list<string> $foreignKeys * @param iterable<array<mixed>|Entity> $seoUrls */
    public function updateSeoUrls(Context $context, string $routeName, array $foreignKeys, iterable $seoUrls, SalesChannelEntity $salesChannel): void
    {
        $languageId = $context->getLanguageId();
        $canonicals = $this->findCanonicalPaths($routeName$languageId$foreignKeys);
        $dateTime = (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        $insertQuery = new MultiInsertQueryQueue($this->connection, 250, false, true);

        $updatedFks = [];
        $obsoleted = [];

        $processed = [];

        $salesChannelId = $salesChannel->getId();
        $updates = [];
        foreach ($seoUrls as $seoUrl) {
            if ($seoUrl instanceof \JsonSerializable) {
                $seoUrl = $seoUrl->jsonSerialize();
            }
public function update(Connection $connection): void
    {
        $countryId = $connection->fetchOne('SELECT id from country WHERE iso = \'CA\' AND iso3 = \'CAN\'');

        if (!$countryId) {
            return;
        }

        $createdAt = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        $queue = new MultiInsertQueryQueue($connection, \count(self::CANADA_STATES), false, true);
        $countryStateTranslations = [];

        $shortCodes = array_map(fn ($state) => $state['shortCode'], self::CANADA_STATES);

        $existStates = $connection->fetchFirstColumn(
            'SELECT short_code FROM country_state WHERE short_code IN (:shortCodes)',
            ['shortCodes' => $shortCodes],
            ['shortCodes' => ArrayParameterType::STRING]
        );

        foreach (self::CANADA_STATES as $state) {
            
$parentId,
                    1,
                    $actionSequence['flow_id'],
                    $actionSequence['rule_id'],
                    $actionSequence['action_name'],
                    $createdAt,
                    $actionSequence['config'],
                );
            }
        }

        $queue = new MultiInsertQueryQueue($connection);

        foreach ($this->sequenceActions as $data) {
            $queue->addInsert(FlowSequenceDefinition::ENTITY_NAME, $data);
        }

        $queue->execute();

        foreach ($this->sequenceUpdate as $sequence) {
            $connection->executeStatement(
                'UPDATE `flow_sequence` SET `parent_id` = :parentId, `true_case` = :trueCase WHERE `id` = :id',
                [
                    
'language_id' => $languageDe,
            'name' => 'Deutsch',
            'territory' => 'Deutschland',
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);
    }

    private function createLocale(Connection $connection): void
    {
        $localeData = include __DIR__ . '/../../locales.php';

        $queue = new MultiInsertQueryQueue($connection);
        $languageEn = Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM);
        $languageDe = Uuid::fromHexToBytes($this->getDeDeLanguageId());

        foreach ($localeData as $locale) {
            if (\in_array($locale['locale']['en-GB', 'de-DE'], true)) {
                continue;
            }

            $localeId = Uuid::randomBytes();

            $queue->addInsert(
                


        $filter = $this->connection->fetchOne(
            'SELECT api_filter FROM product_stream WHERE invalid = 0 AND api_filter IS NOT NULL AND id = :id',
            ['id' => Uuid::fromHexToBytes($id)]
        );
        // if the filter is invalid         if ($filter === false) {
            return;
        }

        $insert = new MultiInsertQueryQueue($this->connection, 250, false, true);

        $version = Uuid::fromHexToBytes(Defaults::LIVE_VERSION);

        $filter = json_decode((string) $filter, true, 512, \JSON_THROW_ON_ERROR);

        $criteria = $this->getCriteria($filter);

        if ($criteria === null) {
            return;
        }

        
$params,
                ['ids' => ArrayParameterType::STRING]
            );
        });
    }

    /** * @param list<array{id: string, version_id: string, product_version_id: string, language_id: string, product_id: string, keyword: string, ranking: float, created_at: string}> $keywords */
    private function insertKeywords(array $keywords): void
    {
        $queue = new MultiInsertQueryQueue($this->connection, 50, true);
        foreach ($keywords as $insert) {
            $queue->addInsert(ProductSearchKeywordDefinition::ENTITY_NAME, $insert);
        }
        $queue->execute();
    }

    /** * @param array<string, array{id: string, language_id: string, keyword: string}> $dictionary */
    private function insertDictionary(array $dictionary): void
    {
        
/** * @internal */
class MultiInsertQueryQueueTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testNullableDatetime(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $query = new MultiInsertQueryQueue($connection);

        $date = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        $catA = Uuid::randomBytes();
        $catB = Uuid::randomBytes();

        $query->addInsert(
            'category',
            [
                'id' => $catA,
                'version_id' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION),
                
private readonly ?LoggerInterface $logger = null
    ) {
    }

    public function getName(): string
    {
        return $this->migrationSource->getName();
    }

    public function sync(): void
    {
        $insertQuery = new MultiInsertQueryQueue($this->connection, 250, true);

        foreach ($this->getMigrationSteps() as $className => $migrationStep) {
            $insertQuery->addInsert('migration', $this->getMigrationData($className$migrationStep));
        }

        $insertQuery->execute();
    }

    public function migrateInSteps(?int $until = null, ?int $limit = null): \Generator
    {
        return $this->migrationRuntime->migrate($this->migrationSource, $until$limit);
    }


    /** * @param array<array<string, string>> $inserts */
    private function insertTree(array $inserts): void
    {
        if (empty($inserts)) {
            return;
        }

        $queue = new MultiInsertQueryQueue($this->connection, 250, true);
        foreach ($inserts as $insert) {
            $queue->addInsert('product_category_tree', $insert);
        }
        $queue->execute();
    }

    /** * @param array<int, string> $ids * * @return array<string, array<string, string>> */
    
'SELECT configuration_key, id FROM system_config WHERE ' . $where . ' and configuration_key IN (:configurationKeys)',
                [
                    'salesChannelId' => $salesChannelId ? Uuid::fromHexToBytes($salesChannelId) : null,
                    'configurationKeys' => array_keys($values),
                ],
                [
                    'configurationKeys' => ArrayParameterType::STRING,
                ]
            );

        $toBeDeleted = [];
        $insertQueue = new MultiInsertQueryQueue($this->connection, 100, false, true);
        $events = [];

        foreach ($values as $key => $value) {
            $key = trim($key);
            $this->validate($key$salesChannelId);

            $event = new BeforeSystemConfigChangedEvent($key$value$salesChannelId);
            $this->eventDispatcher->dispatch($event);

            // Use modified value provided by potential event subscribers.             $value = $event->getValue();

            
\assert(\is_array($keys));

        if (empty($keys)) {
            $this->io->success('No carts found in Redis');

            return 0;
        }
        $this->progress = $this->io->createProgressBar(\count($keys));
        $this->progress->setFormat("<info>[%message%]</info>\n%current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%");
        $this->progress->setMessage('Migrating carts from Redis to SQL');

        $queue = new MultiInsertQueryQueue($this->connection, 50, false, true);

        // @deprecated tag:v6.6.0 - payload always exists         $payloadExists = EntityDefinitionQueryHelper::columnExists($this->connection, 'cart', 'payload');

        foreach ($keys as $index => $key) {
            if (\method_exists($this->redis, '_prefix')) {
                $key = \substr((string) $key, \strlen($this->redis->_prefix('')));
            }

            $value = $this->redis->get($key);
            if (!\is_string($value)) {
                
$createdAt = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);

        $defaultSearchData = [];
        if ($writeResult->hasWrittenEnglishTranslations()) {
            $defaultSearchData = $this->getConfigFieldDefaultData($searchConfigEnId$createdAt);
        }

        if ($writeResult->hasWrittenGermanTranslations()) {
            $defaultSearchData = [...$defaultSearchData, ...$this->getConfigFieldDefaultData($searchConfigDeId$createdAt)];
        }

        $queue = new MultiInsertQueryQueue($connection, 250);

        foreach ($defaultSearchData as $searchData) {
            $entityName = $searchData['table'];
            unset($searchData['table']);

            $queue->addInsert($entityName$searchData);
        }

        $queue->execute();
    }

    
'invalid' => 0,
                'custom_fields' => $flowValue['custom_fields'],
                'created_at' => $createdAt,
            ];

            $eventActionIds[] = [
                'flowId' => $flowId,
                'eventActionId' => $flowValue['event_action_id'],
            ];
        }

        $queue = new MultiInsertQueryQueue($connection);

        foreach ($this->ruleQueue as $data) {
            $queue->addInsert(RuleDefinition::ENTITY_NAME, $data);
        }

        foreach ($this->ruleConditionQueue as $data) {
            $queue->addInsert(RuleConditionDefinition::ENTITY_NAME, $data);
        }

        foreach ($this->flowQueue as $data) {
            $queue->addInsert(FlowDefinition::ENTITY_NAME, $data);
        }

        } elseif ($extensionEntityType === AppEntity::class && $extensionId) {
            $this->connection->executeStatement(
                'DELETE FROM custom_entity WHERE app_id = :id',
                ['id' => Uuid::fromHexToBytes($extensionId)]
            );
        } else {
            // custom entity without any app or plugin id --> created by the user and not by any extension             $this->connection->executeStatement('DELETE FROM custom_entity WHERE app_id IS NULL AND plugin_id IS NULL');
        }

        $inserts = new MultiInsertQueryQueue($this->connection, 25, false, true);
        foreach ($customEntities as $customEntity) {
            unset($customEntity['cmsAware']);

            $customEntity['plugin_id'] = $extensionEntityType === PluginEntity::class && $extensionId ? Uuid::fromHexToBytes($extensionId) : null;
            $customEntity['app_id'] = $extensionEntityType === AppEntity::class && $extensionId ? Uuid::fromHexToBytes($extensionId) : null;

            $customEntity['flags'] = json_encode($customEntity['flags'], \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION);
            $customEntity['fields'] = json_encode($customEntity['fields'], \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION);

            $customEntity['custom_fields_aware'] = ($customEntity['customFieldsAware'] ?? false) ? 1 : 0;
            $customEntity['label_property'] = $customEntity['labelProperty'] ?? null;
            
Home | Imprint | This part of the site doesn't use cookies.