<?php declare(strict_types=1);
namespace Swag\BasicExample\Migration;
use Doctrine\DBAL\Connection;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Migration\MigrationStep;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\Migration\Traits\ImportTranslationsTrait;
use Shopware\Core\Migration\Traits\Translations;
class Migration1616974646AddDocumentNumberRange extends MigrationStep
use ImportTranslationsTrait;
public function getCreationTimestamp(): int
public function update(Connection $connection): void
$numberRangeId = Uuid::randomBytes();
$numberRangeTypeId = Uuid::randomBytes();
$this->insertNumberRange($connection, $numberRangeId, $numberRangeTypeId);
$this->insertTranslations($connection, $numberRangeId, $numberRangeTypeId);
public function updateDestructive(Connection $connection): void
private function insertNumberRange(Connection $connection, string $numberRangeId, string $numberRangeTypeId): void
$connection->insert('number_range_type', [
'id' => $numberRangeTypeId,
'technical_name' => 'document_example',
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)
$connection->insert('number_range', [
'type_id' => $numberRangeTypeId,
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)
$storefrontSalesChannelId = $this->getStorefrontSalesChannelId($connection);
if (!$storefrontSalesChannelId) {
$connection->insert('number_range_sales_channel', [
'id' => Uuid::randomBytes(),
'number_range_id' => $numberRangeId,
'sales_channel_id' => $storefrontSalesChannelId,
'number_range_type_id' => $numberRangeTypeId,
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)
private function getStorefrontSalesChannelId(Connection $connection): ?string
$salesChannelId = $connection->fetchOne($sql, [
':typeId' => Uuid::fromHexToBytes(Defaults::SALES_CHANNEL_TYPE_STOREFRONT)
private function insertTranslations(Connection $connection, string $numberRangeId, string $numberRangeTypeId): void
$numberRangeTranslations = new Translations(
'number_range_id' => $numberRangeId,
'number_range_id' => $numberRangeId,
$numberRangeTypeTranslations = new Translations(
'number_range_type_id' => $numberRangeTypeId,
'type_name' => 'Beispiel',
'number_range_type_id' => $numberRangeTypeId,
'type_name' => 'Example',
$this->importTranslation(
'number_range_translation',
$numberRangeTranslations,
$this->importTranslation(
'number_range_type_translation',
$numberRangeTypeTranslations,