diff --git a/module/Installer/src/Config/Plugin/ApplicationConfigCustomizer.php b/module/Installer/src/Config/Plugin/ApplicationConfigCustomizer.php index 7843833a..2e56d1e2 100644 --- a/module/Installer/src/Config/Plugin/ApplicationConfigCustomizer.php +++ b/module/Installer/src/Config/Plugin/ApplicationConfigCustomizer.php @@ -15,9 +15,13 @@ class ApplicationConfigCustomizer implements ConfigCustomizerInterface public const SECRET = 'SECRET'; public const DISABLE_TRACK_PARAM = 'DISABLE_TRACK_PARAM'; + public const CHECK_VISITS_THRESHOLD = 'CHECK_VISITS_THRESHOLD'; + public const VISITS_THRESHOLD = 'VISITS_THRESHOLD'; private const EXPECTED_KEYS = [ self::SECRET, self::DISABLE_TRACK_PARAM, + self::CHECK_VISITS_THRESHOLD, + self::VISITS_THRESHOLD, ]; public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void @@ -31,6 +35,11 @@ class ApplicationConfigCustomizer implements ConfigCustomizerInterface $io->title('APPLICATION'); foreach ($keysToAskFor as $key) { + // Skip visits threshold when the user decided not to check visits on deletions + if ($key === self::VISITS_THRESHOLD && ! $app[self::CHECK_VISITS_THRESHOLD]) { + continue; + } + $app[$key] = $this->ask($io, $key); } $appConfig->setApp($app); @@ -49,6 +58,16 @@ class ApplicationConfigCustomizer implements ConfigCustomizerInterface 'Provide a parameter name that you will be able to use to disable tracking on specific request to ' . 'short URLs (leave empty and this feature won\'t be enabled)' ); + case self::CHECK_VISITS_THRESHOLD: + return $io->confirm( + 'Do you want to enable a safety check which will not allow short URLs to be deleted when they ' + . 'have more than a specific amount of visits?' + ); + case self::VISITS_THRESHOLD: + return $io->ask( + 'What is the amount of visits from which the system will not allow short URLs to be deleted?', + 15 + ); } return ''; diff --git a/module/Installer/src/Model/CustomizableAppConfig.php b/module/Installer/src/Model/CustomizableAppConfig.php index 253cba21..2e298f42 100644 --- a/module/Installer/src/Model/CustomizableAppConfig.php +++ b/module/Installer/src/Model/CustomizableAppConfig.php @@ -121,6 +121,8 @@ final class CustomizableAppConfig implements ArraySerializableInterface $this->setApp($this->mapExistingPathsToKeys([ ApplicationConfigCustomizer::SECRET => ['app_options', 'secret_key'], ApplicationConfigCustomizer::DISABLE_TRACK_PARAM => ['app_options', 'disable_track_param'], + ApplicationConfigCustomizer::CHECK_VISITS_THRESHOLD => ['delete_short_urls', 'check_visits_threshold'], + ApplicationConfigCustomizer::VISITS_THRESHOLD => ['delete_short_urls', 'visits_threshold'], ], $array)); $this->setDatabase($this->mapExistingPathsToKeys([ @@ -165,6 +167,10 @@ final class CustomizableAppConfig implements ArraySerializableInterface 'secret_key' => $this->app[ApplicationConfigCustomizer::SECRET] ?? '', 'disable_track_param' => $this->app[ApplicationConfigCustomizer::DISABLE_TRACK_PARAM] ?? null, ], + 'delete_short_urls' => [ + 'check_visits_threshold' => $this->app[ApplicationConfigCustomizer::CHECK_VISITS_THRESHOLD] ?? true, + 'visits_threshold' => $this->app[ApplicationConfigCustomizer::VISITS_THRESHOLD] ?? 15, + ], 'entity_manager' => [ 'connection' => [ 'driver' => $dbDriver,