⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.45
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
shopware
/
vendor
/
shopware
/
core
/
Test
/
View File Name :
FixtureLoader.php
<?php declare(strict_types=1); namespace Shopware\Core\Test; use Doctrine\DBAL\Connection; use Shopware\Core\Defaults; use Shopware\Core\Framework\Api\Sync\SyncOperation; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry; use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriter; use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriterInterface; use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteContext; use Shopware\Core\Framework\Test\IdsCollection; use Shopware\Core\Framework\Test\TestCaseBase\BasicTestDataBehaviour; use Symfony\Component\DependencyInjection\ContainerInterface; /** * @internal */ class FixtureLoader { use BasicTestDataBehaviour; private ContainerInterface $container; private EntityWriterInterface $writer; private Connection $connection; public function __construct( ContainerInterface $container ) { $this->container = $container; $this->connection = $container->get(Connection::class); $this->writer = $container->get(EntityWriter::class); } public function load(string $content, ?IdsCollection $ids = null): IdsCollection { if (!$ids) { $ids = new IdsCollection([ 'currency' => Defaults::CURRENCY, 'api-type' => Defaults::SALES_CHANNEL_TYPE_API, 'comparison-type' => Defaults::SALES_CHANNEL_TYPE_PRODUCT_COMPARISON, 'storefront-type' => Defaults::SALES_CHANNEL_TYPE_STOREFRONT, 'language' => Defaults::LANGUAGE_SYSTEM, 'locale' => $this->getLocaleIdOfSystemLanguage(), 'es-locale' => $this->getLocaleIdFromLocaleCode('es-ES'), ]); } $content = $this->replaceIds($ids, $content); $this->sync(\json_decode($content, true, 512, \JSON_THROW_ON_ERROR)); $this->container->get(EntityIndexerRegistry::class)->index(false); return $ids; } public function getContainer(): ContainerInterface { return $this->container; } private function replaceIds(IdsCollection $ids, string $content): string { return (string) \preg_replace_callback('/"{.*}"/mU', function (array $match) use ($ids) { $key = \str_replace(['"{', '}"'], '', $match[0]); return '"' . $ids->create($key) . '"'; }, $content); } /** * @param array<array<int, mixed>> $content */ private function sync(array $content): void { $operations = []; foreach ($content as $entity => $data) { $operations[] = new SyncOperation($entity, $entity, 'upsert', $data); } $this->writer->sync($operations, WriteContext::createFromContext(Context::createDefaultContext())); } private function getLocaleIdOfSystemLanguage(): string { return $this->connection ->fetchOne( 'SELECT LOWER(HEX(locale_id)) FROM language WHERE id = UNHEX(:systemLanguageId)', ['systemLanguageId' => Defaults::LANGUAGE_SYSTEM] ); } private function getLocaleIdFromLocaleCode(string $code): string { return $this->connection ->fetchOne( 'SELECT LOWER(HEX(id)) from locale WHERE code = :code', ['code' => $code] ); } }