From 2a9bacea8c348fe157292d9832cc1e269412892e Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Thu, 24 Jul 2025 00:02:38 -0500 Subject: [PATCH] fix: removes preference options db table --- migrations/Version20250724042107.php | 41 +++++++++++++++++++ src/Twig/Components/Filter.php | 27 ++++++++---- src/User/Dto/PreferenceOptions.php | 14 +++++++ src/User/Dto/PreferenceOptionsFactory.php | 23 +++++++++++ .../Controller/Web/PreferencesController.php | 2 +- templates/components/Filter.html.twig | 16 ++++---- 6 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 migrations/Version20250724042107.php create mode 100644 src/User/Dto/PreferenceOptions.php create mode 100644 src/User/Dto/PreferenceOptionsFactory.php diff --git a/migrations/Version20250724042107.php b/migrations/Version20250724042107.php new file mode 100644 index 0000000..dee487f --- /dev/null +++ b/migrations/Version20250724042107.php @@ -0,0 +1,41 @@ +addSql(<<<'SQL' + ALTER TABLE preference_option DROP FOREIGN KEY FK_607C52FD81022C0 + SQL); + $this->addSql(<<<'SQL' + DROP TABLE preference_option + SQL); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql(<<<'SQL' + CREATE TABLE preference_option (id INT AUTO_INCREMENT NOT NULL, preference_id VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, name VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, value VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, enabled TINYINT(1) NOT NULL, INDEX IDX_607C52FD81022C0 (preference_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = '' + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE preference_option ADD CONSTRAINT FK_607C52FD81022C0 FOREIGN KEY (preference_id) REFERENCES preference (id) + SQL); + } +} diff --git a/src/Twig/Components/Filter.php b/src/Twig/Components/Filter.php index 8db95d3..8a50910 100644 --- a/src/Twig/Components/Filter.php +++ b/src/Twig/Components/Filter.php @@ -3,14 +3,20 @@ namespace App\Twig\Components; use Aimeos\Map; +use App\User\Database\CodecList; use App\User\Database\QualityList; +use App\User\Database\ResolutionList; +use App\User\Dto\PreferenceOptions; +use App\User\Dto\PreferenceOptionsFactory; +use App\User\Dto\UserPreferencesFactory; use App\User\Framework\Repository\PreferencesRepository; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\SecurityBundle\Security; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\DefaultActionTrait; #[AsLiveComponent] -final class Filter +final class Filter extends AbstractController { use DefaultActionTrait; @@ -21,15 +27,20 @@ final class Filter public array $reverseMappedQualities = []; public function __construct( - private readonly PreferencesRepository $preferencesRepository, private readonly Security $security, ) { - $this->preferences = Map::from($this->preferencesRepository->findEnabled()) - ->rekey(fn($element) => $element->getId()) - ->map(fn($element) => $element->getPreferenceOptions()->toArray()) - ->toArray(); - $this->userPreferences = Map::from($this->security->getUser()->getUserPreferenceValues()) - ->toArray(); + $this->preferences = (array) PreferenceOptionsFactory::createSelectOptions(); + $this->userPreferences = (array) UserPreferencesFactory::createFromUser($security->getUser()); $this->reverseMappedQualities = QualityList::getAsReverseMap(); } + + public function getResolutionOptions() + { + return ResolutionList::asSelectOptions(); + } + + public function getCodecOptions() + { + return CodecList::asSelectOptions(); + } } diff --git a/src/User/Dto/PreferenceOptions.php b/src/User/Dto/PreferenceOptions.php new file mode 100644 index 0000000..46cc31d --- /dev/null +++ b/src/User/Dto/PreferenceOptions.php @@ -0,0 +1,14 @@ +getUser()->getDownloadPreferences(); $formData = (array) UserPreferencesFactory::createFromUser($this->getUser()); $form = $this->createForm(UserMediaPreferencesForm::class, $formData); - + $saveUserDownloadPreferencesHandler->handle($input->toCommand()); $this->broadcaster->alert( diff --git a/templates/components/Filter.html.twig b/templates/components/Filter.html.twig index 137083c..6671671 100644 --- a/templates/components/Filter.html.twig +++ b/templates/components/Filter.html.twig @@ -15,10 +15,10 @@ value="{{ app.user.userPreferenceValues["resolution"] }}" > - {% for option in this.preferences['resolution'] %} - + {% for name, value in this.resolutionOptions %} + {% endfor %} @@ -26,10 +26,10 @@ Codec