Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Repository/ConfigRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* (c) shopware AG <[email protected]>
* 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<string, string>
*/
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;
}
}
7 changes: 7 additions & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<service id="swag_migration_connector.service.environment_service" class="SwagMigrationConnector\Service\EnvironmentService" public="true">
<argument type="service" id="models" />
<argument type="service" id="swag_migration_connector.repository.environment_repository" />
<argument type="service" id="swag_migration_connector.repository.config_repository" />
<argument type="service" id="swag_migration_connector.service.plugin_information_service" />
<argument>%shopware.release.version%</argument>
<argument>%shopware.release.version_text%</argument>
Expand Down Expand Up @@ -177,6 +178,12 @@
<tag name="shopware.migration.connector.repository"/>
</service>

<service id="swag_migration_connector.repository.config_repository"
class="SwagMigrationConnector\Repository\ConfigRepository"
parent="SwagMigrationConnector\Repository\AbstractRepository">
<tag name="shopware.migration.connector.repository"/>
</service>

<service id="swag_migration_connector.repository.order_repository"
class="SwagMigrationConnector\Repository\OrderRepository"
parent="SwagMigrationConnector\Repository\AbstractRepository">
Expand Down
17 changes: 14 additions & 3 deletions Service/EnvironmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +23,12 @@ class EnvironmentService extends AbstractApiService
/**
* @var EnvironmentRepository
*/
private $repository;
private $environmentRepository;

/**
* @var ConfigRepository
*/
private $configRepository;

/**
* @var PluginInformationService
Expand Down Expand Up @@ -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;
Expand All @@ -81,6 +89,8 @@ public function getEnvironmentInformation()
'default' => 1,
]);

$config = $this->configRepository->fetch();

$resultSet = [
'defaultShopLanguage' => $locale,
'defaultCurrency' => $defaultCurrency->getCurrency(),
Expand All @@ -89,6 +99,7 @@ public function getEnvironmentInformation()
'revision' => $this->revision,
'additionalData' => $this->getAdditionalData(),
'updateAvailable' => $this->pluginInformationService->isUpdateRequired($locale),
'config' => $config,
];

return $resultSet;
Expand All @@ -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) {
Expand Down
59 changes: 59 additions & 0 deletions Tests/Functional/Repository/ConfigRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* (c) shopware AG <[email protected]>
* 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);
}
}