diff --git a/Repository/ConfigRepository.php b/Repository/ConfigRepository.php new file mode 100644 index 0000000..044065e --- /dev/null +++ b/Repository/ConfigRepository.php @@ -0,0 +1,45 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationConnector\Repository; + +use Doctrine\DBAL\Connection; + +class ConfigRepository extends AbstractRepository +{ + /** + * @phpstan-ignore-next-line intentionally different return type, returns key-value config map + * + * @return array + */ + public function fetch($offset = 0, $limit = 250) + { + $configNames = [ + 'esdKey', + 'installationDate', + ]; + + $query = $this->connection->createQueryBuilder(); + + $query->select('config.name', 'config.value') + ->from('s_core_config_elements', 'config') + ->where('config.name IN (:configNames)') + ->setParameter('configNames', $configNames, Connection::PARAM_STR_ARRAY); + + $rows = $query->execute()->fetchAll(); + + $result = []; + + foreach ($rows as $row) { + $value = \unserialize($row['value'], ['allowed_classes' => false]); + + $result[$row['name']] = $value; + } + + return $result; + } +} diff --git a/Resources/services.xml b/Resources/services.xml index b374380..e49030d 100644 --- a/Resources/services.xml +++ b/Resources/services.xml @@ -10,6 +10,7 @@ + %shopware.release.version% %shopware.release.version_text% @@ -177,6 +178,12 @@ + + + + diff --git a/Service/EnvironmentService.php b/Service/EnvironmentService.php index 901a3af..1c1d643 100644 --- a/Service/EnvironmentService.php +++ b/Service/EnvironmentService.php @@ -10,6 +10,7 @@ use Shopware\Components\Model\ModelManager; use Shopware\Models\Shop\Currency; use Shopware\Models\Shop\Shop; +use SwagMigrationConnector\Repository\ConfigRepository; use SwagMigrationConnector\Repository\EnvironmentRepository; class EnvironmentService extends AbstractApiService @@ -22,7 +23,12 @@ class EnvironmentService extends AbstractApiService /** * @var EnvironmentRepository */ - private $repository; + private $environmentRepository; + + /** + * @var ConfigRepository + */ + private $configRepository; /** * @var PluginInformationService @@ -52,13 +58,15 @@ class EnvironmentService extends AbstractApiService public function __construct( ModelManager $modelManager, EnvironmentRepository $environmentRepository, + ConfigRepository $configRepository, PluginInformationService $pluginInformationService, $version, $versionText, $revision ) { $this->modelManager = $modelManager; - $this->repository = $environmentRepository; + $this->environmentRepository = $environmentRepository; + $this->configRepository = $configRepository; $this->pluginInformationService = $pluginInformationService; $this->version = $version; $this->versionText = $versionText; @@ -81,6 +89,8 @@ public function getEnvironmentInformation() 'default' => 1, ]); + $config = $this->configRepository->fetch(); + $resultSet = [ 'defaultShopLanguage' => $locale, 'defaultCurrency' => $defaultCurrency->getCurrency(), @@ -89,6 +99,7 @@ public function getEnvironmentInformation() 'revision' => $this->revision, 'additionalData' => $this->getAdditionalData(), 'updateAvailable' => $this->pluginInformationService->isUpdateRequired($locale), + 'config' => $config, ]; return $resultSet; @@ -99,7 +110,7 @@ public function getEnvironmentInformation() */ private function getAdditionalData() { - $fetchedShops = $this->repository->getShops(); + $fetchedShops = $this->environmentRepository->getShops(); $shops = $this->mapData($fetchedShops, [], ['shop']); foreach ($shops as $key => &$shop) { diff --git a/Tests/Functional/Repository/ConfigRepositoryTest.php b/Tests/Functional/Repository/ConfigRepositoryTest.php new file mode 100644 index 0000000..d826dc2 --- /dev/null +++ b/Tests/Functional/Repository/ConfigRepositoryTest.php @@ -0,0 +1,59 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationConnector\Tests\Functional\Repository; + +use Doctrine\DBAL\Connection; +use PHPUnit\Framework\TestCase; +use SwagMigrationConnector\Repository\ConfigRepository; +use SwagMigrationConnector\Tests\Functional\DatabaseTransactionTrait; + +class ConfigRepositoryTest extends TestCase +{ + use DatabaseTransactionTrait; + + /** + * @var Connection + */ + private $connection; + + /** + * @return void + */ + public function testFetchReturnsUnserializedValues() + { + $repository = $this->getConfigRepository(); + + $result = $repository->fetch(); + + static::assertCount(2, $result); + + static::assertArrayHasKey('esdKey', $result); + static::assertFalse(\strpos($result['esdKey'], 's:') !== false); + + static::assertArrayHasKey('installationDate', $result); + static::assertFalse(\strpos($result['installationDate'], 's:') !== false); + } + + /** + * @before + * + * @return void + */ + protected function setUpMethod() + { + $this->connection = $this->getContainer()->get('dbal_connection'); + } + + /** + * @return ConfigRepository + */ + private function getConfigRepository() + { + return new ConfigRepository($this->connection); + } +}