Skip to content

Commit

Permalink
FFWEB-2996: Improvements from marketplace version
Browse files Browse the repository at this point in the history
- Add validation for plugin configuration form
- Add FactFinder logger
- Add German translations
  • Loading branch information
Rayn93 authored Mar 11, 2024
1 parent 4d12391 commit adad60d
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: build

on: [pull_request]
on: [push]

jobs:
build:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## Unreleased
### Add
- Add validation for plugin configuration form
- Add FactFinder logger
- Add German translations
- Add reporting for Shopware marketplace
- Add PHPStan
### Change
Expand Down
14 changes: 13 additions & 1 deletion src/Api/TestConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Omikron\FactFinder\Communication\Credentials;
use Omikron\FactFinder\Shopware6\Config\Communication as CommunicationConfig;
use Omikron\FactFinder\Shopware6\Upload\UploadService;
use Psr\Log\LoggerInterface;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -22,7 +23,8 @@ class TestConnectionController extends AbstractController
public function __construct(
private readonly ClientBuilder $clientBuilder,
private readonly CommunicationConfig $config,
private readonly UploadService $uploadService
private readonly UploadService $uploadService,
private readonly LoggerInterface $factfinderLogger
) {
}

Expand All @@ -38,11 +40,19 @@ public function testApiConnection(): JsonResponse
->build();

try {
$client = $this->clientBuilder
->withCredentials(new Credentials(...$this->config->getCredentials()))
->withServerUrl($this->config->getServerUrl())
->withVersion($this->config->getVersion())
->build();

$endpoint = $this->createTestEndpoint();
$client->request('GET', $endpoint);

return new JsonResponse(['message' => 'Connection successfully established'], 200);
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());

return new JsonResponse(['message' => 'Connection could not be established'], 400);
}
}
Expand All @@ -57,6 +67,8 @@ public function testFTPConnection(): JsonResponse

return new JsonResponse(['message' => 'Connection successfully established'], 200);
} catch (FilesystemException $e) {
$this->factfinderLogger->error($e->getMessage());

return new JsonResponse(['message' => "Connection could not be established. Error: {$e->getMessage()}"], 400);
}
}
Expand Down
42 changes: 26 additions & 16 deletions src/Api/UiFeedExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Omikron\FactFinder\Shopware6\Message\RefreshExportCache;
use Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler;
use Omikron\FactFinder\Shopware6\MessageQueue\RefreshExportCacheHandler;
use Psr\Log\LoggerInterface;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -23,7 +24,8 @@ class UiFeedExportController extends AbstractController
public function __construct(
private FeedExportHandler $feedExportHandler,
private DataExportCommand $dataExportCommand,
private RefreshExportCacheHandler $refreshCacheHandler
private RefreshExportCacheHandler $refreshCacheHandler,
private LoggerInterface $factfinderLogger
) {
}

Expand All @@ -33,18 +35,22 @@ public function __construct(
* @param Request $request
*
* @return JsonResponse
*
* @throws \Exception
*/
public function generateExportFeedAction(Request $request): JsonResponse
{
$this->feedExportHandler->__invoke(new FeedExport(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue'),
$request->query->get('exportTypeValue')
));
try {
$this->feedExportHandler->__invoke(new FeedExport(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue'),
$request->query->get('exportTypeValue')
));

return new JsonResponse();
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());

return new JsonResponse();
return new JsonResponse(['message' => 'Problem with export. Check logs for more informations'], 400);
}
}

/**
Expand All @@ -63,16 +69,20 @@ public function getTypeEntityMap(): JsonResponse
* @param Request $request
*
* @return JsonResponse
*
* @throws \Exception
*/
public function refreshExportCacheAction(Request $request): JsonResponse
{
$this->refreshCacheHandler->__invoke(new RefreshExportCache(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue')
));
try {
$this->refreshCacheHandler->__invoke(new RefreshExportCache(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue')
));

return new JsonResponse();
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());

return new JsonResponse();
return new JsonResponse(['message' => 'Problem with cache export. Check logs for more informations'], 400);
}
}
}
28 changes: 19 additions & 9 deletions src/Api/UpdateFieldRolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Omikron\FactFinder\Shopware6\Api;

use Omikron\FactFinder\Shopware6\Config\FieldRolesInterface;
use Psr\Log\LoggerInterface;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
Expand All @@ -21,28 +22,37 @@ class UpdateFieldRolesController extends AbstractController
{
private FieldRolesInterface $fieldRoles;
private EntityRepository $channelRepository;
private LoggerInterface $factfinderLogger;

public function __construct(FieldRolesInterface $fieldRolesService, EntityRepository $channelRepository)
{
public function __construct(
FieldRolesInterface $fieldRolesService,
EntityRepository $channelRepository,
LoggerInterface $factfinderLogger
) {
$this->fieldRoles = $fieldRolesService;
$this->channelRepository = $channelRepository;
$this->factfinderLogger = $factfinderLogger;
}

/**
* @Route("/api/_action/field-roles/update", name="api.action.fact_finder.field_roles.update", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*
* @return JsonResponse
*
* @throws \Exception
*/
public function execute(): JsonResponse
{
foreach ($this->fetchSalesChannels() as $salesChannel) {
$fieldRoles = $this->fieldRoles->getRoles($salesChannel->getId());
$this->fieldRoles->update($fieldRoles, $salesChannel->getId());
}
try {
foreach ($this->fetchSalesChannels() as $salesChannel) {
$fieldRoles = $this->fieldRoles->getRoles($salesChannel->getId());
$this->fieldRoles->update($fieldRoles, $salesChannel->getId());
}

return new JsonResponse();
return new JsonResponse();
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());

return new JsonResponse(['message' => 'Problem with update fields roles. Check logs for more informations'], 400);
}
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/Communication/ClientBuilderConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@
use Omikron\FactFinder\Communication\Client\ClientBuilder;
use Omikron\FactFinder\Communication\Credentials;
use Omikron\FactFinder\Shopware6\Config\Communication as CommunicationConfig;
use Psr\Log\LoggerInterface;

class ClientBuilderConfigurator
{
private CommunicationConfig $config;
private LoggerInterface $factfinderLogger;

public function __construct(CommunicationConfig $config)
public function __construct(CommunicationConfig $config, LoggerInterface $factfinderLogger)
{
$this->config = $config;
$this->config = $config;
$this->factfinderLogger = $factfinderLogger;
}

public function configure(ClientBuilder $clientBuilder): void
{
$clientBuilder->withCredentials(new Credentials(...$this->config->getCredentials()));

if ($this->config->getServerUrl() !== '') {
$clientBuilder->withServerUrl($this->config->getServerUrl());
try {
if ($this->config->getServerUrl() !== '') {
$clientBuilder->withServerUrl($this->config->getServerUrl());
}
} catch (\InvalidArgumentException $e) {
$this->factfinderLogger->error($e->getMessage());
}
}
}
23 changes: 20 additions & 3 deletions src/OmikronFactFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
use Shopware\Core\System\CustomField\Aggregate\CustomFieldSet\CustomFieldSetEntity;
use Shopware\Core\System\CustomField\CustomFieldEntity;
use Shopware\Core\System\CustomField\CustomFieldTypes;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -37,7 +43,7 @@ class OmikronFactFinder extends Plugin
'config' => [
'label' => [
'en-GB' => 'Include in FACT-Finder® CMS Export',
'de-DE' => 'Include in FACT-Finder® CMS Export',
'de-DE' => 'In FACT-Finder® CMS-Export einbinden',
],
'componentName' => 'sw-field',
'customFieldType' => CustomFieldTypes::SWITCH,
Expand All @@ -50,7 +56,7 @@ class OmikronFactFinder extends Plugin
'config' => [
'label' => [
'en-GB' => 'Disable `ff-communication/search-immediate`',
'de-DE' => 'Disable `ff-communication/search-immediate`',
'de-DE' => 'Deaktivieren `ff-communication/search-immediate`',
],
'componentName' => 'sw-field',
'customFieldType' => CustomFieldTypes::SWITCH,
Expand All @@ -66,6 +72,17 @@ public function build(ContainerBuilder $container): void
$container->registerForAutoconfiguration(ExportInterface::class)->addTag('factfinder.export.exporter');
$container->registerForAutoconfiguration(ExportEntityInterface::class)->addTag('factfinder.export.entity');
$container->registerForAutoconfiguration(FactoryInterface::class)->addTag('factfinder.export.entity_factory');

$locator = new FileLocator('Resources/config');
$resolver = new LoaderResolver([
new YamlFileLoader($container, $locator),
new GlobFileLoader($container, $locator),
new DirectoryLoader($container, $locator),
]);

$configLoader = new DelegatingLoader($resolver);
$confDir = \rtrim($this->getPath(), '/') . '/Resources/config';
$configLoader->load($confDir . '/{packages}/*.yaml', 'glob');
}

public function install(InstallContext $installContext): void
Expand Down Expand Up @@ -176,7 +193,7 @@ private function fixCMSExportIncludeFieldType(Context $context): void
'customFieldType' => CustomFieldTypes::SWITCH,
'label' => [
'en-GB' => 'Include in FACT-Finder® CMS Export',
'de-DE' => 'Include in FACT-Finder® CMS Export',
'de-DE' => 'In FACT-Finder® CMS-Export einbinden',
],
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"configuration": {
"updateFieldRoles": {
"update": "Update Field Roles"
"update": "Feldrollen aktualisieren",
"successMessage": "Feldrollen erfolgreich aktualisiert. Bitte prüfen Sie, ob die Werte korrekt sind"
},
"testConnection": {
"success": "Connection successfully established.",
"fail": "Connection could not be established.",
"helpText": "Please save you current configuration before test connection"
"success": "Verbindung erfolgreich hergestellt.",
"fail": "Die Verbindung konnte nicht hergestellt werden.",
"helpText": "Bitte speichern Sie Ihre aktuelle Konfiguration, bevor Sie die Verbindung testen"
},
"testApiConnection": {
"testConnection": "Test Connection"
"testConnection": "Testverbindung"
},
"testFtpConnection": {
"testConnection": "Test FTP/SFTP Connection"
"testConnection": "FTP/SFTP Testverbindung "
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
"blocks": {
"commerce": {
"factfinderWebComponentsListing": {
"label": "Typical collection of Web Components that implements search result page "
"label": "Typische Sammlung von Webkomponenten, die eine Suchergebnisseite implementiert"
},
"factfinderWebComponentsCampaigns": {
"label": "FACT-Finder® Web Components Campaigns"
"label": "FACT-Finder® Web Components Kampagnen"
},
"factfinderWebComponentsFilters": {
"label": "FACT-Finder® Web Components Filters"
"label": "FACT-Finder® Web Components Filter"
},
"factfinderWebComponentsRecordList": {
"label": "FACT-Finder® Web Components Record List"
"label": "FACT-Finder® Web Components Rekordliste"
}
}
},
"elements": {
"recordList": {
"label": "FACT-Finder® Web Components ff-record-list element",
"config": {
"callbackArg": "Name of argument which will be available inside the callback scope",
"callback": "callback to the subscribed topic. It is recommended to have only one callback per topic, per page.",
"domUpdated": "listener to dom-update event of that element.",
"id": "Value will be passed as `id` attribute to element. If not specified, the default CMS element id will be used"
"callbackArg": "Name des Arguments, das im Callback-Bereich verfügbar sein wird",
"callback": "Rückruf zum abonnierten Thema. Es wird empfohlen, nur einen Rückruf pro Thema und Seite durchzuführen.",
"domUpdated": "Listener für das dom-update-Ereignis dieses Elements",
"id": "Der Wert wird als „id“-Attribut an das Element übergeben. Wenn nicht angegeben, wird die Standard-CMS-Element-ID verwendet"
}
},
"asn": {
"asn": {
"label": "FACT-Finder® Web Components ff-asn element",
"config": {
"callbackArg": "Name of argument which will be available inside the callback scope",
"callback": "callback to the subscribed topic. It is recommended to have only one callback per topic, per page.",
"domUpdated": "listener to dom-update event of that element.",
"id": "Value will be passed as `id` attribute to element. If not specified, the default CMS element id will be used",
"topic": "Leaving this field empty causes element subscribe to its default topic (asn)",
"vertical": "Setting to true will add additional CSS class `btn-block` to the `ff-asn-group` and `<div slot=\"groupCaption\"` and ffw-asn-vertical, ffw-asn-group-vertical and ffw-asn-group-element-vertical to corresponding elements"
"callbackArg": "Name des Arguments, das im Callback-Bereich verfügbar sein wird",
"callback": "Rückruf zum abonnierten Thema. Es wird empfohlen, nur einen Rückruf pro Thema und Seite durchzuführen.",
"domUpdated": "Listener für das dom-update-Ereignis dieses Elements.",
"id": "Der Wert wird als „id“-Attribut an das Element übergeben. Wenn nicht angegeben, wird die Standard-CMS-Element-ID verwendet",
"topic": "Wenn Sie dieses Feld leer lassen, abonniert das Element sein Standardthema (ASN).",
"vertical": "Durch die Einstellung „true“ wird die zusätzliche CSS-Klasse „btn-block“ zu „ff-asn-group“ und „<div slots=\"groupCaption\"“ sowie zu ffw-asn-vertical, ffw-asn-group-vertical und ffw-asn hinzugefügt -group-element-vertikal zu entsprechenden Elementen"
}
},
"sortbox": {
Expand All @@ -45,9 +45,9 @@
"label": "FACT-Finder® Web Components ff-paging element"
},
"campaigns": {
"label": "FACT-Finder® Web Components campaigns elements collection",
"label": "FACT-Finder® Web Components Sammlung von Kampagnenelementen",
"config": {
"leaveFreeIfNotSpecified": "Leave this value free if you want page to accept all campaigns matching the criteria"
"leaveFreeIfNotSpecified": "Lassen Sie diesen Wert frei, wenn die Seite alle Kampagnen akzeptieren soll, die den Kriterien entsprechen"
}
}
}
Expand Down
Loading

0 comments on commit adad60d

Please sign in to comment.