Skip to content

Commit c22f7d2

Browse files
authored
FFWEB-2709: Refresh export cache functionality (#149)
Add button which refresh export cache.
1 parent 50f44ff commit c22f7d2

File tree

17 files changed

+202
-9
lines changed

17 files changed

+202
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Changelog
22
## Unreleased
3+
### Add
4+
- Add refresh export cache button
35
### Fix
46
- Fix problem with autowire EntityRepository and SalesChannelRepository for Shopware 6.4
7+
58
## [v4.2.4] - 2023.04.26
69
### Fix
710
- Fix problem with ff-template in search result page
811
- Fix some inaccuracies in read.me file
912
- Remove deprecations for EntityRepository and SalesChannelRepository
1013
- Fix type for custom_fields and filter_attributes in FeedPreprocessorEntryDefinition
14+
1115
## [v4.2.3] - 2023.04.13
1216
### Fix
1317
- SSR

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ Export can be done for:
335335
`Create Export` Send a message to a bus which then might be consumed automatically by an admin worker (if enabled)
336336
or by CLI worker. More information about messaging you can find in official Shopware [documentation](https://developer.shopware.com/docs/guides/hosting/infrastructure/message-queue)
337337

338+
![Admin Panel Refresh export cache](docs/assets/admin-panel-refresh-cache-export.png "Admin Panel Refresh export cache")
339+
If you use the export cache feature ([read more](#export-settings)) you could also refresh your export cache by clicking on `Refresh cache Export`
340+
button. This feature will be useful if:
341+
- your export cache is old or incomplete
342+
- you did some database changes programmatically
343+
- you want to decrease export time (export with cache is faster)
338344

339345
## Web Components Integration
340346

19.3 KB
Loading

src/Api/UiFeedExportController.php

+30-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
use Omikron\FactFinder\Shopware6\Command\DataExportCommand;
88
use Omikron\FactFinder\Shopware6\Message\FeedExport;
9+
use Omikron\FactFinder\Shopware6\Message\RefreshExportCache;
910
use Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler;
11+
use Omikron\FactFinder\Shopware6\MessageQueue\RefreshExportCacheHandler;
1012
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
1113
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1214
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -20,16 +22,21 @@ class UiFeedExportController extends AbstractController
2022
{
2123
private FeedExportHandler $feedExportHandler;
2224
private DataExportCommand $dataExportCommand;
25+
private RefreshExportCacheHandler $refreshCacheHandler;
2326

2427
/**
2528
* UiFeedExportController constructor.
2629
*
2730
* @param FeedExportHandler $feedExportHandler
2831
*/
29-
public function __construct(FeedExportHandler $feedExportHandler, DataExportCommand $dataExportCommand)
30-
{
31-
$this->feedExportHandler = $feedExportHandler;
32-
$this->dataExportCommand = $dataExportCommand;
32+
public function __construct(
33+
FeedExportHandler $feedExportHandler,
34+
DataExportCommand $dataExportCommand,
35+
RefreshExportCacheHandler $refreshCacheHandler
36+
) {
37+
$this->feedExportHandler = $feedExportHandler;
38+
$this->dataExportCommand = $dataExportCommand;
39+
$this->refreshCacheHandler = $refreshCacheHandler;
3340
}
3441

3542
/**
@@ -61,4 +68,23 @@ public function getTypeEntityMap(): JsonResponse
6168
{
6269
return new JsonResponse($this->dataExportCommand->getTypeEntityMap());
6370
}
71+
72+
/**
73+
* @Route("/api/_action/fact-finder/refresh-export-cache", name="api.action.fact_finder.refresh-export-cache", methods={"GET"}, defaults={"XmlHttpRequest"=true})
74+
*
75+
* @param Request $request
76+
*
77+
* @return JsonResponse
78+
*
79+
* @throws \Exception
80+
*/
81+
public function refreshExportCacheAction(Request $request): JsonResponse
82+
{
83+
$this->refreshCacheHandler->handle(new RefreshExportCache(
84+
$request->query->get('salesChannelValue'),
85+
$request->query->get('salesChannelLanguageValue')
86+
));
87+
88+
return new JsonResponse();
89+
}
6490
}

src/Message/RefreshExportCache.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Omikron\FactFinder\Shopware6\Message;
6+
7+
final class RefreshExportCache
8+
{
9+
private ?string $salesChannelId;
10+
private ?string $salesChannelLanguageId;
11+
12+
public function __construct(string $salesChannelId = null, string $salesChannelLanguageId = null)
13+
{
14+
$this->salesChannelId = $salesChannelId;
15+
$this->salesChannelLanguageId = $salesChannelLanguageId;
16+
}
17+
18+
public function getSalesChannelId(): ?string
19+
{
20+
return $this->salesChannelId;
21+
}
22+
23+
public function getSalesChannelLanguageId(): ?string
24+
{
25+
return $this->salesChannelLanguageId;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Omikron\FactFinder\Shopware6\MessageQueue;
6+
7+
use Omikron\FactFinder\Shopware6\Command\RunPreprocessorCommand;
8+
use Omikron\FactFinder\Shopware6\Message\RefreshExportCache;
9+
use Shopware\Core\Framework\MessageQueue\Handler\AbstractMessageHandler;
10+
use Symfony\Bundle\FrameworkBundle\Console\Application;
11+
use Symfony\Component\Console\Input\ArrayInput;
12+
use Symfony\Component\Console\Output\NullOutput;
13+
use Symfony\Component\HttpKernel\KernelInterface;
14+
15+
class RefreshExportCacheHandler extends AbstractMessageHandler
16+
{
17+
private Application $application;
18+
19+
public function __construct(KernelInterface $kernel)
20+
{
21+
$this->application = new Application($kernel);
22+
$this->application->setAutoExit(false);
23+
}
24+
25+
/**
26+
* @param RefreshExportCache $message
27+
*
28+
* @throws \Exception
29+
*/
30+
public function handle($message): void
31+
{
32+
$input = new ArrayInput([
33+
'command' => 'factfinder:data:pre-process',
34+
RunPreprocessorCommand::SALES_CHANNEL_ARGUMENT => $message->getSalesChannelId(),
35+
RunPreprocessorCommand::SALES_CHANNEL_LANGUAGE_ARGUMENT => $message->getSalesChannelLanguageId(),
36+
]);
37+
$input->setInteractive(false);
38+
$output = new NullOutput();
39+
$this->application->run($input, $output);
40+
}
41+
42+
public static function getHandledMessages(): iterable
43+
{
44+
return [RefreshExportCache::class];
45+
}
46+
}

src/Resources/app/administration/src/module/sw-cms/elements/shared/shared.scss

+4
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
text-align: center;
1515
justify-content: center;
1616
}
17+
18+
.margint10 {
19+
margin-top: 10px;
20+
}

src/Resources/app/administration/src/module/sw-cms/snippet/de-DE.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"factfinderWebComponentsRecordList": {
1515
"label": "FACT-Finder® Web Components Record List"
16-
},
16+
}
1717
}
1818
},
1919
"elements": {

src/Resources/app/administration/src/module/sw-cms/snippet/en-GB.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"factfinderWebComponentsRecordList": {
1515
"label": "FACT-Finder® Web Components Record List"
16-
},
16+
}
1717
}
1818
},
1919
"elements": {

src/Resources/app/administration/src/module/ui-feed-export/component/ui-feed-export-form/index.js

+46
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ const { Component, Mixin } = Shopware;
55
Component.register('ui-feed-export-form', {
66
template,
77

8+
inject: ['systemConfigApiService'],
9+
810
data() {
911
return {
1012
salesChannelValue: null,
1113
salesChannelLanguageValue: null,
1214
exportTypeValue: null,
1315
typeSelectOptions: [],
16+
isCacheDisable: false,
17+
isLoadingCache: false,
1418
}
1519
},
1620

1721
mixins: [
1822
Mixin.getByName('notification')
1923
],
2024
mounted () {
25+
this.getPluginConfig()
2126
this.getExportTypeValues()
2227
},
2328
filters: {
@@ -28,6 +33,10 @@ Component.register('ui-feed-export-form', {
2833
}
2934
},
3035
methods: {
36+
async getPluginConfig() {
37+
const config = await this.systemConfigApiService.getValues('OmikronFactFinder.config');
38+
this.isCacheDisable = config['OmikronFactFinder.config.enableExportCache'];
39+
},
3140
getExportTypeValues() {
3241
const httpClient = Shopware.Service('syncService').httpClient;
3342
const url = '_action/fact-finder/get-export-type-options';
@@ -56,6 +65,16 @@ Component.register('ui-feed-export-form', {
5665
message: this.$tc('ui-feed-export.component.export_form.alert_error.text')
5766
})
5867
},
68+
successRefreshCacheWindow() {
69+
this.createNotificationSuccess({
70+
message: this.$tc('ui-feed-export.component.export_form.refresh_cache_success.text')
71+
})
72+
},
73+
errorRefreshCacheWindow() {
74+
this.createNotificationError({
75+
message: this.$tc('ui-feed-export.component.export_form.refresh_cache_error.text')
76+
})
77+
},
5978
getFeedExportFile(url) {
6079
const httpClient = Shopware.Service('syncService').httpClient;
6180
const basicHeaders = {
@@ -80,6 +99,33 @@ Component.register('ui-feed-export-form', {
8099
this.errorFeedGenerationWindow();
81100
}
82101
});
102+
},
103+
refreshExportCache(url) {
104+
this.isLoadingCache = true;
105+
const httpClient = Shopware.Service('syncService').httpClient;
106+
const basicHeaders = {
107+
Authorization: `Bearer ${Shopware.Context.api.authToken.access}`,
108+
'Content-Type': 'application/json'
109+
};
110+
const params = {
111+
salesChannelValue: this.salesChannelValue,
112+
salesChannelLanguageValue: this.salesChannelLanguageValue
113+
};
114+
115+
httpClient
116+
.get(url, {
117+
headers: basicHeaders,
118+
params: params
119+
})
120+
.then((response) => {
121+
if (response.status === 200) {
122+
this.successRefreshCacheWindow();
123+
} else {
124+
this.errorRefreshCacheWindow();
125+
}
126+
127+
this.isLoadingCache = false;
128+
});
83129
}
84130
}
85131
});

src/Resources/app/administration/src/module/ui-feed-export/component/ui-feed-export-form/ui-feed-export-form.html.twig

+12
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,17 @@
3232

3333
{{ $tc('ui-feed-export.component.export_form.button.title') }}
3434
</sw-button>
35+
36+
<sw-button @click="refreshExportCache('_action/fact-finder/refresh-export-cache')"
37+
v-if="isCacheDisable"
38+
:isLoading="isLoadingCache"
39+
:disabled="isLoadingCache"
40+
variant="success"
41+
block="true"
42+
size="large"
43+
class="margint10">
44+
45+
{{ $tc('ui-feed-export.component.export_form.cache_button.title') }}
46+
</sw-button>
3547
</sw-card>
3648
</sw-card-view>

src/Resources/app/administration/src/module/ui-feed-export/snippet/de-DE.json

+9
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@
1212
"button": {
1313
"title": "Create Export"
1414
},
15+
"cache_button": {
16+
"title": "Refresh cache Export"
17+
},
1518
"alert_success": {
1619
"text": "Integration process has been started"
1720
},
1821
"alert_error": {
1922
"text": "An error occurred during integration process"
23+
},
24+
"refresh_cache_success": {
25+
"text": "Export cache has been refreshed"
26+
},
27+
"refresh_cache_error": {
28+
"text": "An error occurred during refresh export cache"
2029
}
2130
}
2231
}

src/Resources/app/administration/src/module/ui-feed-export/snippet/en-GB.json

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"button": {
1313
"title": "Create Export"
1414
},
15+
"cache_button": {
16+
"title": "Refresh cache Export"
17+
},
1518
"alert_success": {
1619
"text": "Integration process has been started"
1720
},
@@ -20,6 +23,12 @@
2023
},
2124
"export_type": {
2225
"label": "Select export type"
26+
},
27+
"refresh_cache_success": {
28+
"text": "Export cache has been refreshed"
29+
},
30+
"refresh_cache_error": {
31+
"text": "An error occurred during refresh export cache"
2332
}
2433
}
2534
}

src/Resources/config/services.xml

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
<service id="Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler">
141141
<tag name="messenger.message_handler" />
142142
</service>
143+
<service id="Omikron\FactFinder\Shopware6\MessageQueue\RefreshExportCacheHandler">
144+
<tag name="messenger.message_handler" />
145+
</service>
143146
<service id="Omikron\FactFinder\Shopware6\Export\ExportBrands">
144147
<argument type="service" id="product_manufacturer.repository" />
145148
</service>

src/Resources/public/administration/css/omikron-fact-finder.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/public/administration/js/omikron-fact-finder.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/public/administration/js/omikron-fact-finder.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)