From 228ef8cbe9a27439f43fb460fcc2c0cfbbb7da69 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 9 Jul 2025 09:30:34 +0200 Subject: [PATCH] refactor + update DB --- migrations/Version20250709072959.php | 37 ++++++++++++++++++++ src/Entity/Subscriptions.php | 36 ------------------- src/Entity/User.php | 35 ------------------ src/EventSubscriber/ScopeResolveListener.php | 6 ++-- 4 files changed, 39 insertions(+), 75 deletions(-) create mode 100644 migrations/Version20250709072959.php delete mode 100644 src/Entity/Subscriptions.php diff --git a/migrations/Version20250709072959.php b/migrations/Version20250709072959.php new file mode 100644 index 0000000..f252895 --- /dev/null +++ b/migrations/Version20250709072959.php @@ -0,0 +1,37 @@ +addSql('DROP SEQUENCE subscriptions_id_seq CASCADE'); + $this->addSql('ALTER TABLE subscriptions DROP CONSTRAINT fk_4778a0167b3b43d'); + $this->addSql('DROP TABLE subscriptions'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('CREATE SEQUENCE subscriptions_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE subscriptions (id SERIAL NOT NULL, users_id INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX idx_4778a0167b3b43d ON subscriptions (users_id)'); + $this->addSql('ALTER TABLE subscriptions ADD CONSTRAINT fk_4778a0167b3b43d FOREIGN KEY (users_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } +} diff --git a/src/Entity/Subscriptions.php b/src/Entity/Subscriptions.php deleted file mode 100644 index 7a85ce0..0000000 --- a/src/Entity/Subscriptions.php +++ /dev/null @@ -1,36 +0,0 @@ -id; - } - - public function getUsers(): ?User - { - return $this->users; - } - - public function setUsers(?User $users): static - { - $this->users = $users; - - return $this; - } -} diff --git a/src/Entity/User.php b/src/Entity/User.php index 42d9b8b..ff06fae 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -55,15 +55,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(options: ['default' => false])] private ?bool $isDeleted = null; - /** - * @var Collection - */ - #[ORM\OneToMany(targetEntity: Subscriptions::class, mappedBy: 'users')] - private Collection $subscriptions; public function __construct() { - $this->subscriptions = new ArrayCollection(); } public function getId(): ?int @@ -233,33 +227,4 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return (string) $this->getId(); } - /** - * @return Collection - */ - public function getSubscriptions(): Collection - { - return $this->subscriptions; - } - - public function addSubscription(Subscriptions $subscription): static - { - if (!$this->subscriptions->contains($subscription)) { - $this->subscriptions->add($subscription); - $subscription->setUsers($this); - } - - return $this; - } - - public function removeSubscription(Subscriptions $subscription): static - { - if ($this->subscriptions->removeElement($subscription)) { - // set the owning side to null (unless already changed) - if ($subscription->getUsers() === $this) { - $subscription->setUsers(null); - } - } - - return $this; - } } diff --git a/src/EventSubscriber/ScopeResolveListener.php b/src/EventSubscriber/ScopeResolveListener.php index c90a170..9b09234 100644 --- a/src/EventSubscriber/ScopeResolveListener.php +++ b/src/EventSubscriber/ScopeResolveListener.php @@ -2,7 +2,6 @@ namespace App\EventSubscriber; -use App\Service\ClientService; use Doctrine\ORM\EntityManagerInterface; use League\Bundle\OAuth2ServerBundle\Event\ScopeResolveEvent; use League\Bundle\OAuth2ServerBundle\Repository\ScopeRepository; @@ -16,15 +15,14 @@ final class ScopeResolveListener implements EventSubscriberInterface { private ClientRepositoryInterface $clientRepository; private LoggerInterface $logger; - private ClientService $clientService; + private EntityManagerInterface $entityManager; - public function __construct(ClientRepositoryInterface $clientRepository, LoggerInterface $logger, ClientService $clientService, EntityManagerInterface $entityManager) + public function __construct(ClientRepositoryInterface $clientRepository, LoggerInterface $logger, EntityManagerInterface $entityManager) { $this->logger = $logger; // Inject the client repository $this->clientRepository = $clientRepository; - $this->clientService = $clientService; $this->entityManager = $entityManager; }