From 064cdd686ebf78c3ed44e84757133f29b0a46cee Mon Sep 17 00:00:00 2001 From: robertsaternus Date: Wed, 29 May 2024 11:46:05 +0200 Subject: [PATCH] FFWEB-3058: Remove FF version and API version Remove FF version and API version with refactoring. New SDK support only ng and v5 for API. --- .../Adminhtml/FieldRoles/Update.php | 4 +- .../TestConnection/TestConnection.php | 5 ++- src/Model/Api/CredentialsFactory.php | 4 +- src/Model/Api/PushImport.php | 25 +---------- src/Model/Config/AuthConfig.php | 12 ------ src/Model/Config/CommunicationConfig.php | 7 +--- src/Model/Config/ExportConfig.php | 6 +-- src/Model/Ssr/PriceFormatter.php | 6 +-- src/Model/Ssr/SearchAdapter.php | 5 +-- src/Plugin/MapFieldRoles.php | 5 +-- .../Unit/Model/Config/ExportConfigTest.php | 8 +--- src/Test/Unit/Plugin/MapFieldRolesTest.php | 8 ---- src/Test/Unit/ViewModel/CommunicationTest.php | 2 +- src/ViewModel/CategoryPath.php | 7 ---- src/ViewModel/Communication.php | 2 +- src/etc/adminhtml/system/general.xml | 42 +++++++------------ src/etc/config.xml | 4 -- 17 files changed, 35 insertions(+), 117 deletions(-) diff --git a/src/Controller/Adminhtml/FieldRoles/Update.php b/src/Controller/Adminhtml/FieldRoles/Update.php index a4624ec9..1a13fbaa 100644 --- a/src/Controller/Adminhtml/FieldRoles/Update.php +++ b/src/Controller/Adminhtml/FieldRoles/Update.php @@ -10,7 +10,6 @@ use Magento\Store\Model\StoreManagerInterface; use Omikron\FactFinder\Communication\Client\ClientBuilder; use Omikron\FactFinder\Communication\Resource\AdapterFactory; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Api\CredentialsFactory; use Omikron\Factfinder\Model\Config\CommunicationConfig; use Omikron\Factfinder\Model\FieldRoles; @@ -60,8 +59,7 @@ public function execute() $this->communicationConfig->getApiVersion() ); $searchAdapter = $adapterFactory->getSearchAdapter(); - $response = $searchAdapter->search($this->communicationConfig->getChannel($storeId), 'Search.ff'); - $searchResult = $this->communicationConfig->getVersion() === Version::NG ? $response : $response['searchResult']; + $searchResult = $searchAdapter->search($this->communicationConfig->getChannel($storeId), 'Search.ff'); $result->setData(['message' => __('Search result does not contain field roles')]); if (isset($searchResult['fieldRoles'])) { diff --git a/src/Controller/Adminhtml/TestConnection/TestConnection.php b/src/Controller/Adminhtml/TestConnection/TestConnection.php index 36a38d1b..8e9fb57b 100644 --- a/src/Controller/Adminhtml/TestConnection/TestConnection.php +++ b/src/Controller/Adminhtml/TestConnection/TestConnection.php @@ -10,6 +10,7 @@ use Omikron\FactFinder\Communication\Client\ClientBuilder; use Omikron\FactFinder\Communication\Credentials; use Omikron\FactFinder\Communication\Resource\AdapterFactory; +use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Logger\FactFinderLogger; use Omikron\Factfinder\Model\Api\CredentialsFactory; use Omikron\Factfinder\Model\Config\AuthConfig; @@ -50,8 +51,8 @@ public function execute() $adapterFactory = new AdapterFactory( $clientBuilder, - $request->getParam('version'), - $request->getParam('ff_api_version') + Version::NG, + 'v5' ); $searchAdapter = $adapterFactory->getSearchAdapter(); $searchAdapter->search($request->getParam('channel'), '*'); diff --git a/src/Model/Api/CredentialsFactory.php b/src/Model/Api/CredentialsFactory.php index e38ffed1..04eb1cb7 100644 --- a/src/Model/Api/CredentialsFactory.php +++ b/src/Model/Api/CredentialsFactory.php @@ -25,8 +25,8 @@ public function create(array $authData = null) [ 'username' => $this->authConfig->getUsername(), 'password' => $this->authConfig->getPassword(), - 'prefix' => $this->authConfig->getAuthenticationPrefix(), - 'postfix' => $this->authConfig->getAuthenticationPostfix() + 'prefix' => '', + 'postfix' => '', ]); } } diff --git a/src/Model/Api/PushImport.php b/src/Model/Api/PushImport.php index 53c94d62..60280245 100644 --- a/src/Model/Api/PushImport.php +++ b/src/Model/Api/PushImport.php @@ -7,7 +7,6 @@ use Omikron\FactFinder\Communication\Client\ClientBuilder; use Omikron\FactFinder\Communication\Client\ClientException; use Omikron\FactFinder\Communication\Resource\AdapterFactory; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Config\CommunicationConfig; use Omikron\Factfinder\Model\Config\ExportConfig; use Psr\Log\LoggerInterface; @@ -54,7 +53,7 @@ public function execute(int $storeId): bool return false; } - if ($this->communicationConfig->getVersion() === Version::NG && $importAdapter->running($channel)) { + if ($importAdapter->running($channel)) { throw new ClientException("Can't start a new import process. Another one is still going"); } @@ -75,9 +74,7 @@ public function getPushImportResult(): string private function prepareListFromPushImportResponses(array $responses): string { - return strtolower($this->communicationConfig->getVersion()) === 'ng' - ? $this->ngResponse($responses) - : $this->standardResponse($responses); + return $this->ngResponse($responses); } private function ngResponse(array $responses): string @@ -101,22 +98,4 @@ private function ngResponse(array $responses): string return sprintf($list, $listContent); } - - private function standardResponse(array $responses): string - { - $list = ''; - $listContent = ''; - - if (!empty($responses['status'])) { - $statusList = sprintf( - '', - implode('', array_map(fn (string $message): string => sprintf('
  • %s
  • ', $message), $responses['status'])) - ); - - $statusMessages = sprintf('
  • Status messages
  • %s
  • ', $statusList); - $listContent .= $statusMessages; - } - - return sprintf($list, $listContent); - } } diff --git a/src/Model/Config/AuthConfig.php b/src/Model/Config/AuthConfig.php index 2dceb542..c60190cd 100644 --- a/src/Model/Config/AuthConfig.php +++ b/src/Model/Config/AuthConfig.php @@ -11,8 +11,6 @@ class AuthConfig { private const PATH_USERNAME = 'factfinder/general/username'; private const PATH_PASSWORD = 'factfinder/general/password'; - private const PATH_AUTH_PREFIX = 'factfinder/general/prefix'; - private const PATH_AUTH_POSTFIX = 'factfinder/general/postfix'; private ScopeConfigInterface $scopeConfig; @@ -30,14 +28,4 @@ public function getPassword(): string { return (string) $this->scopeConfig->getValue(self::PATH_PASSWORD, Scope::SCOPE_STORE); } - - public function getAuthenticationPrefix(): string - { - return (string) $this->scopeConfig->getValue(self::PATH_AUTH_PREFIX, Scope::SCOPE_STORE); - } - - public function getAuthenticationPostfix(): string - { - return (string) $this->scopeConfig->getValue(self::PATH_AUTH_POSTFIX, Scope::SCOPE_STORE); - } } diff --git a/src/Model/Config/CommunicationConfig.php b/src/Model/Config/CommunicationConfig.php index 6275334b..994a5e60 100644 --- a/src/Model/Config/CommunicationConfig.php +++ b/src/Model/Config/CommunicationConfig.php @@ -8,15 +8,12 @@ use Magento\Framework\UrlInterface; use Magento\Store\Model\ScopeInterface; use Omikron\Factfinder\Api\Config\ParametersSourceInterface; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Controller\Router; class CommunicationConfig implements ParametersSourceInterface { private const PATH_CHANNEL = 'factfinder/general/channel'; private const PATH_ADDRESS = 'factfinder/general/address'; - private const PATH_VERSION = 'factfinder/general/version'; - private const PATH_API_VERSION = 'factfinder/general/ff_api_version'; private const PATH_IS_ENABLED = 'factfinder/general/is_enabled'; private const PATH_USE_PROXY = 'factfinder/general/ff_enrichment'; private const PATH_DATA_TRANSFER_IMPORT = 'factfinder/data_transfer/ff_push_import_enabled'; @@ -55,7 +52,7 @@ public function isPushImportEnabled(int $scopeId = null): bool public function getVersion(): string { - return (string) $this->scopeConfig->getValue(self::PATH_VERSION, ScopeInterface::SCOPE_STORES); + return 'ng'; } public function getApiKey(): string @@ -79,7 +76,7 @@ public function getParameters(): array public function getApiVersion(): string { - return (string) $this->scopeConfig->getValue(self::PATH_API_VERSION, ScopeInterface::SCOPE_STORES) ?? 'v4'; + return 'v5'; } private function getServerUrl(): string diff --git a/src/Model/Config/ExportConfig.php b/src/Model/Config/ExportConfig.php index 581ea6c2..7a9f2356 100644 --- a/src/Model/Config/ExportConfig.php +++ b/src/Model/Config/ExportConfig.php @@ -7,7 +7,6 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Serialize\SerializerInterface; use Magento\Store\Model\ScopeInterface; -use Omikron\FactFinder\Communication\Version; class ExportConfig { @@ -44,20 +43,21 @@ public function getPushImportDataTypes(int $scopeId = null): array { $configPath = 'factfinder/data_transfer/ff_push_import_type'; $dataTypes = (string) $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORES, $scopeId); - $isNg = $this->communicationConfig->getVersion() === Version::NG; - return explode(',', $isNg ? $dataTypes : str_replace('search', 'data', $dataTypes)); + return explode(',', $dataTypes); } private function getAttributeCodes(?int $storeId, callable $condition): array { $rows = array_filter($this->getConfigValue($storeId), $condition); + return array_values(array_unique(array_column($rows, 'code'))); } private function getConfigValue(?int $storeId): array { $value = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORES, $storeId); + return array_map( fn (array $row): array => ['multi' => !!$row['multi']] + $row, (array) $this->serializer->unserialize($value ?: '[]') diff --git a/src/Model/Ssr/PriceFormatter.php b/src/Model/Ssr/PriceFormatter.php index f4a328eb..4836bfed 100644 --- a/src/Model/Ssr/PriceFormatter.php +++ b/src/Model/Ssr/PriceFormatter.php @@ -5,7 +5,6 @@ namespace Omikron\Factfinder\Model\Ssr; use Magento\Framework\Pricing\PriceCurrencyInterface; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Config\CommunicationConfig; use Omikron\Factfinder\Model\FieldRoles; @@ -21,11 +20,8 @@ public function __construct( public function format(array $searchResult): array { $priceField = $this->fieldRoles->getFieldRole('price'); - $isNG = $this->communicationConfig->getVersion() === Version::NG; - $records = $isNG ? $searchResult['hits'] : $searchResult['searchResult']['records']; - $recordField = $isNG ? 'masterValues' : 'record'; - return ['records' => array_map($this->price($priceField, $recordField), $records)] + $searchResult; + return ['records' => array_map($this->price($priceField, 'masterValues'), $searchResult['hits'])] + $searchResult; } protected function price(string $priceField, string $recordField): callable diff --git a/src/Model/Ssr/SearchAdapter.php b/src/Model/Ssr/SearchAdapter.php index 41fcc185..276c488a 100644 --- a/src/Model/Ssr/SearchAdapter.php +++ b/src/Model/Ssr/SearchAdapter.php @@ -6,7 +6,6 @@ use Omikron\FactFinder\Communication\Client\ClientBuilder; use Omikron\FactFinder\Communication\Client\ClientException; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Api\CredentialsFactory; use Omikron\Factfinder\Model\Config\CommunicationConfig; use Psr\Http\Message\ResponseInterface; @@ -50,8 +49,6 @@ private function createEndpoint(string $paramString, bool $navigationRequest) $apiVersion = $this->communicationConfig->getApiVersion(); $endpoint = $navigationRequest ? 'navigation' : 'search'; - return $this->communicationConfig->getVersion() == Version::NG - ? "rest/{$apiVersion}/{$endpoint}/{$channel}?{$paramString}" - : "Search.ff?channel={$channel}&{$paramString}&format=json"; + return "rest/{$apiVersion}/{$endpoint}/{$channel}?{$paramString}"; } } diff --git a/src/Plugin/MapFieldRoles.php b/src/Plugin/MapFieldRoles.php index aa8f0457..d2c182eb 100644 --- a/src/Plugin/MapFieldRoles.php +++ b/src/Plugin/MapFieldRoles.php @@ -4,7 +4,6 @@ namespace Omikron\Factfinder\Plugin; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Config\CommunicationConfig; use Omikron\Factfinder\Model\FieldRoles; @@ -24,9 +23,7 @@ public function __construct(private readonly CommunicationConfig $communicationC */ public function aroundSaveFieldRoles(FieldRoles $subject, callable $proceed, array $fieldRoles, int $storeId) { - $isNg = $this->communicationConfig->getVersion() === Version::NG; - - return $proceed($isNg ? $this->map($fieldRoles) : $fieldRoles, $storeId); + return $proceed($this->map($fieldRoles), $storeId); } protected function map(array $fieldRoles): array diff --git a/src/Test/Unit/Model/Config/ExportConfigTest.php b/src/Test/Unit/Model/Config/ExportConfigTest.php index 7bd24bf5..6032dfe2 100644 --- a/src/Test/Unit/Model/Config/ExportConfigTest.php +++ b/src/Test/Unit/Model/Config/ExportConfigTest.php @@ -44,12 +44,8 @@ public function test_single_fields_are_calculated_correctly() $this->assertCount(2, $result); } - public function test_correct_push_data_types_are_returned_for_different_ff_versions() + public function test_correct_push_data_types_are_returned() { - $result = $this->testee->getPushImportDataTypes(1); - $this->assertContains('data', $result); - $this->assertNotContains('search', $result); - $result = $this->testee->getPushImportDataTypes(1); $this->assertContains('search', $result); $this->assertNotContains('data', $result); @@ -63,7 +59,7 @@ protected function setUp(): void ['factfinder/export/attributes', Scope::SCOPE_STORES, 42,'{"_1":{"code":"color","multi":"0","numerical":"0"},"_2":{"code":"climate","multi":"1","numerical":"0"},"_3":{"code":"gender","multi":"0","numerical":"0"},"_4":{"code":"size","multi":"1","numerical":"1"}}'] ]); $communicationConfig = $this->createMock(CommunicationConfig::class); - $communicationConfig->method('getVersion')->willReturnOnConsecutiveCalls('7.3', 'ng'); + $communicationConfig->method('getVersion')->willReturn('ng'); $this->testee = new ExportConfig($scopeConfig, new Json(), $communicationConfig); } } diff --git a/src/Test/Unit/Plugin/MapFieldRolesTest.php b/src/Test/Unit/Plugin/MapFieldRolesTest.php index f4350825..69af8e59 100644 --- a/src/Test/Unit/Plugin/MapFieldRolesTest.php +++ b/src/Test/Unit/Plugin/MapFieldRolesTest.php @@ -38,14 +38,6 @@ public function test_it_will_map_field_roles_in_ng() $this->plugin->aroundSaveFieldRoles($this->createMock(FieldRoles::class), $callbackMock, $this->fieldRoles, 1); } - public function test_it_will_not_map_field_roles_in_pre_ng() - { - $this->configMock->method('getVersion')->willReturn('7.3'); - //in fact, this field role does exist in 7.3 but mocked field roles are of NG format - $callbackMock = fn (array $fieldRoles, int $storeId) => $this->assertArrayNotHasKey('masterArticleNumber', $fieldRoles); - $this->plugin->aroundSaveFieldRoles($this->createMock(FieldRoles::class), $callbackMock, $this->fieldRoles, 1); - } - protected function setUp(): void { $this->configMock = $this->createMock(CommunicationConfig::class); diff --git a/src/Test/Unit/ViewModel/CommunicationTest.php b/src/Test/Unit/ViewModel/CommunicationTest.php index 52a5f17f..ff0c78d9 100644 --- a/src/Test/Unit/ViewModel/CommunicationTest.php +++ b/src/Test/Unit/ViewModel/CommunicationTest.php @@ -63,7 +63,7 @@ protected function setUp(): void $this->parametersProviderMock->method('getParameters')->willReturn([ 'url' => 'http://some-url', - 'version' => '7.3', + 'version' => 'ng', 'user-id' => null, 'channel' => 'some-channel', 'use-cache' => 'true', diff --git a/src/ViewModel/CategoryPath.php b/src/ViewModel/CategoryPath.php index 9e20e414..e6188d36 100644 --- a/src/ViewModel/CategoryPath.php +++ b/src/ViewModel/CategoryPath.php @@ -7,7 +7,6 @@ use Magento\Catalog\Model\Category; use Magento\Framework\Registry; use Magento\Framework\View\Element\Block\ArgumentInterface; -use Omikron\FactFinder\Communication\Version; use Omikron\Factfinder\Model\Config\CommunicationConfig; class CategoryPath implements ArgumentInterface @@ -20,12 +19,6 @@ public function __construct( ) { } - public function __toString() - { - return $this->communicationConfig->getVersion() === Version::NG ? $this->getCategoryPath( - ) : ''; - } - public function getCategoryPath(): array { $values = []; diff --git a/src/ViewModel/Communication.php b/src/ViewModel/Communication.php index ad6119df..f8d96a79 100644 --- a/src/ViewModel/Communication.php +++ b/src/ViewModel/Communication.php @@ -30,7 +30,7 @@ public function getParameters(array $blockParams = []): array $params = $this->parametersProvider->getParameters(); - return ['version' => $params['version'] ?? 'ng'] + return ['version' => 'ng'] + array_filter($this->mergeParameters($blockParams, $params) + $blockParams + $params, 'boolval'); } diff --git a/src/etc/adminhtml/system/general.xml b/src/etc/adminhtml/system/general.xml index 502f3787..7697c1d6 100644 --- a/src/etc/adminhtml/system/general.xml +++ b/src/etc/adminhtml/system/general.xml @@ -19,21 +19,21 @@ required-entry - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + required-entry @@ -46,18 +46,6 @@ Magento\Config\Model\Config\Backend\Encrypted - - - - ng - - - - - - ng - - Omikron\Factfinder\Block\Adminhtml\System\Config\Button\TestConnection diff --git a/src/etc/config.xml b/src/etc/config.xml index 5f9ed9ca..74b22453 100644 --- a/src/etc/config.xml +++ b/src/etc/config.xml @@ -12,10 +12,6 @@ 0 {"brand":"Brand","campaignProductNumber":"ProductNumber","deeplink":"Deeplink","description":"Description","displayProductNumber":"ProductNumber","ean":"EAN","imageUrl":"ImageURL","masterArticleNumber":"Master","price":"Price","productName":"Name","trackingProductNumber":"ProductNumber"} - - 7.3 - v4 - 1 1