refactor + update DB
This commit is contained in:
parent
c81142e4a5
commit
228ef8cbe9
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20250709072959 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SubscriptionsRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: SubscriptionsRepository::class)]
|
||||
class Subscriptions
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'subscriptions')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $users = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUsers(): ?User
|
||||
{
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
public function setUsers(?User $users): static
|
||||
{
|
||||
$this->users = $users;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -55,15 +55,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
#[ORM\Column(options: ['default' => false])]
|
||||
private ?bool $isDeleted = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Subscriptions>
|
||||
*/
|
||||
#[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<int, Subscriptions>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue