Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSP-90 Add a mechanism to avoid growing tables #59

Merged
merged 4 commits into from
Jul 31, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/Model/Config/NostoConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class NostoConfigService

public const ENABLE_PRODUCT_LABELLING_SYNC = 'enableLabelling';

public const ENABLE_STORE_ABANDONED_CART_DATA = 'storeAbandonedCartData';

public const DAILY_PRODUCT_SYNC_ENABLED = 'dailySynchronization';

public const DAILY_PRODUCT_SYNC_TIME = 'dailySynchronizationTime';
Expand Down
21 changes: 19 additions & 2 deletions src/Model/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ public function isEnabledProductLabellingSync($channelId = null, $languageId = n
);
}

public function isEnabledStoreAbandonedCartData($channelId = null, $languageId = null): bool
{
return $this->configService->getBool(
NostoConfigService::ENABLE_STORE_ABANDONED_CART_DATA,
$channelId,
$languageId
);
}

public function isDailyProductSyncEnabled($channelId = null, $languageId = null): bool
{
return $this->configService->getBool(NostoConfigService::DAILY_PRODUCT_SYNC_ENABLED, $channelId, $languageId);
Expand All @@ -232,12 +241,20 @@ public function getOldJobCleanupPeriod($channelId = null, $languageId = null): ?

public function isOldNostoDataCleanupEnabled($channelId = null, $languageId = null): bool
{
return $this->configService->getBool(NostoConfigService::OLD_NOSTO_DATA_CLEANUP_ENABLED, $channelId, $languageId);
return $this->configService->getBool(
NostoConfigService::OLD_NOSTO_DATA_CLEANUP_ENABLED,
$channelId,
$languageId
);
}

public function getOldNostoDataCleanupPeriod($channelId = null, $languageId = null): ?int
{
return $this->configService->getInt(NostoConfigService::OLD_NOSTO_DATA_CLEANUP_PERIOD, $channelId, $languageId);
return $this->configService->getInt(
NostoConfigService::OLD_NOSTO_DATA_CLEANUP_PERIOD,
$channelId,
$languageId
);
}

public function toArray($channelId = null, $languageId = null): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ Component.register('nosto-integration-features-flags', {
return options;
},
createOldNostoDataCleanupPeriodOptions() {
const monthPeriods = [3];
const dayPeriods = [7, 30, 60, 90];
const options = [];
const translationAfter = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.after');
const translationMonths = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.months');
const translationDays = this.$tc('nosto.configuration.featuresFlags.oldNostoDataPeriod.days');

monthPeriods.forEach((period) => {
dayPeriods.forEach((period) => {
options.push(
{
label: `${translationAfter} ${period} ${translationMonths}`,
label: `${translationAfter} ${period} ${translationDays}`,
value: period,
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@
</sw-inherit-wrapper>
{% endblock %}

{% block nosto_integration_feature_store_abandoned_cart_data %}
<sw-inherit-wrapper
v-model="actualConfigData['storeAbandonedCartData']"
:inheritedValue="configKey === null ? null : allConfigs['null']['storeAbandonedCartData']"
>
<template #content="props">
<sw-switch-field
:map-inheritance="props"
:label="$tc('nosto.configuration.featuresFlags.storeAbandonedCartData')"
:help-text="$tc('nosto.configuration.featuresFlags.storeAbandonedCartDataHelpText')"
:disabled="props.isInherited"
:value="props.currentValue"
@change="props.updateCurrentValue"
/>
</template>
</sw-inherit-wrapper>
{% endblock %}

{% block nosto_integration_daily_synchronization_flag %}
<sw-inherit-wrapper
v-if="configKey === null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
"enableProductPublishedDateTagging": "Kennzeichnung des Veröffentlichungsdatums von Produkten",
"enableReloadRecommendations": "Empfehlungen neu laden, nachdem ein empfohlenes Produkt hinzugefügt wurde",
"enableLabelling": "Synchronisierung der Produktkennzeichnung aktivieren",
"storeAbandonedCartData": "Datenspeicherung für abgebrochene Warenkörbe",
"enableDailySynchronization": "Tägliche Produktsynchronisierung aktivieren",
"enableDailySynchronizationHelp": "Wenn das Feld aktiviert ist, werden die Produkte jeden Tag zur angegebenen Zeit synchronisiert",
"timeDailySynchronization": "Zeit für die tägliche Produktsynchronisierung",
"timeDailySynchronizationHelp": "Die Option gibt an, zu welcher Uhrzeit die t\u00e4gliche Produktsynchronisierung synchronisiert werden soll",
"enableProductPublishedDateTaggingHelpText": "Wenn das Kontrollkästchen aktiviert ist, wird auch das Veröffentlichungsdatum des Produkts markiert.",
"enableReloadRecommendationsHelpText": "Wenn das Kontrollkästchen aktiviert ist, werden die Empfehlungen nach dem Hinzufügen eines empfohlenen Produkts neu geladen",
"enableLabellingHelpText": "Wenn das Kontrollkästchen aktiviert ist, werden die Produktetiketten an Nosto gesendet.",
"storeAbandonedCartDataHelpText": "Diese Konfigurationsoption steuert, ob Daten für abgebrochene Warenkörbe in der entsprechenden Datenbank Tabelle gespeichert werden sollen. Wenn diese Option aktiviert ist, ruft das System die Daten ab und erstellt neue Zeilen in der Tabelle für jeden abgebrochenen Warenkorb. Wenn sie deaktiviert ist, werden keine neuen Zeilen hinzugefügt, was möglicherweise Leistungsprobleme verhindert.",
"categoryNamingHelpText": "Produktkategorienamen enthalten die Kategorie-ID oder nicht",
"categoryNaming": "Produktkategorienamen",
"categoryBlocklist": "Kategorie Ausschluss",
Expand All @@ -124,7 +126,7 @@
},
"oldNostoDataPeriod": {
"after": "Nach",
"months": "monate"
"days": "Tagen"
}
},
"search-navigation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@
"enableProductPublishedDateTagging": "Enable Product Published Date Tagging",
"enableReloadRecommendations": "Reload Recommendations After Adding a recommended product",
"enableLabelling": "Enable Product Labelling Sync",
"storeAbandonedCartData": "Store data for abandoned carts",
"enableDailySynchronization": "Enable Daily Product Synchronization",
"enableDailySynchronizationHelp": "If the field is enabled products will be synchronized at the mentioned time each day",
"timeDailySynchronization": "Time for Daily Product Synchronization",
"timeDailySynchronizationHelp": "The option specifies at which time to sync daily product synchronization",
"enableProductPublishedDateTaggingHelpText": "If the checkbox is checked, product publishing date will be tagged as well.",
"enableReloadRecommendationsHelpText": "If the checkbox is checked, the recommendations will be reloaded after adding a recommended product",
"enableLabellingHelpText": "If the checkbox is checked, product labels will be sent to Nosto",
"storeAbandonedCartDataHelpText": "This configuration option controls whether data for abandoned carts should be stored in the relevant table. When this option is enabled, the system will fetch and create new rows in the table for each abandoned cart. If disabled, no new rows will be added, potentially preventing performance issues.",
"categoryNamingHelpText": "Product category names will contain the category ID or not",
"categoryNaming": "Product Category Names",
"categoryBlocklist": "Category Exclusion",
Expand All @@ -124,7 +126,7 @@
},
"oldNostoDataPeriod": {
"after": "After",
"months": "months"
"days": "days"
}
},
"search-navigation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function run(): void
{
try {
$isNostoDataCleanupEnabled = $this->configProvider->isOldNostoDataCleanupEnabled();
$monthPeriod = $this->configProvider->getOldNostoDataCleanupPeriod();
$dayPeriod = $this->configProvider->getOldNostoDataCleanupPeriod();

if ($isNostoDataCleanupEnabled && $monthPeriod) {
$numberOfMonthsBeforeToday = new DateTime(' - ' . $monthPeriod . ' month');
if ($isNostoDataCleanupEnabled && $dayPeriod) {
$numberOfDaysBeforeToday = new DateTime(' - ' . $dayPeriod . ' day');

$this->connection->executeStatement(
'DELETE FROM nosto_integration_checkout_mapping WHERE created_at <= :timestamp',
['timestamp' => $numberOfMonthsBeforeToday->format(Defaults::STORAGE_DATE_FORMAT)]
['timestamp' => $numberOfDaysBeforeToday->format(Defaults::STORAGE_DATE_FORMAT)]
);
}
} catch (Throwable $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nosto\NostoIntegration\Entity\CheckoutMapping\CheckoutMappingDefinition;
use Nosto\NostoIntegration\Entity\CheckoutMapping\CheckoutMappingEntity;
use Nosto\NostoIntegration\Model\ConfigProvider;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
Expand All @@ -22,16 +23,21 @@ class RestoreUrlService
public function __construct(
private readonly EntityRepository $mappingRepository,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly ConfigProvider $configProvider,
private readonly RequestStack $requestStack,
) {
}

public function getCurrentRestoreUrl(SalesChannelContext $context): string
public function getCurrentRestoreUrl(SalesChannelContext $context): ?string
{
$current = $this->fetchFromDb($context->getToken(), $context->getContext());
return $this->generate(
$current ? $current->getId() : $this->createNew($context->getToken(), $context->getContext()),
);
if ($this->configProvider->isEnabledStoreAbandonedCartData()) {
$current = $this->fetchFromDb($context->getToken(), $context->getContext());
return $this->generate(
$current ? $current->getId() : $this->createNew($context->getToken(), $context->getContext()),
);
}

return null;
}

protected function fetchFromDb(string $token, Context $context): ?CheckoutMappingEntity
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/CustomerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getNostoCustomer(CustomerEntity $customer, Context $context): Cu
return $this->builder->build($customer, $context);
}

public function getRestoreCartLink(SalesChannelContext $context): string
public function getRestoreCartLink(SalesChannelContext $context): ?string
{
return $this->restoreUrlService->getCurrentRestoreUrl($context);
}
Expand Down
Loading