Skip to content

Commit

Permalink
feat(Realms): Made RealmNode.php realm_id column not nullable for ind…
Browse files Browse the repository at this point in the history
…ex performance
  • Loading branch information
ambroisemaupate committed Mar 5, 2024
1 parent b8a2c78 commit 153d53c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
31 changes: 31 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20240305124809.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240305124809 extends AbstractMigration
{
public function getDescription(): string
{
return 'Set realm_id as not nullable in realms_nodes table';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE realms_nodes CHANGE realm_id realm_id INT NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE realms_nodes CHANGE realm_id realm_id INT DEFAULT NULL');
}
}
12 changes: 6 additions & 6 deletions lib/RoadizCoreBundle/src/Entity/RealmNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class RealmNode extends AbstractEntity
name: 'realm_id',
referencedColumnName: 'id',
unique: false,
nullable: true,
nullable: false,
onDelete: 'CASCADE'
)]
#[SymfonySerializer\Ignore]
#[Serializer\Exclude]
private ?Realm $realm = null;
private Realm $realm;

#[ORM\Column(name: 'inheritance_type', type: 'string', length: 10, nullable: false)]
#[SymfonySerializer\Ignore]
Expand All @@ -74,18 +74,18 @@ public function setNode(Node $node): RealmNode
}

/**
* @return Realm|null
* @return Realm
*/
public function getRealm(): ?Realm
public function getRealm(): Realm
{
return $this->realm;
}

/**
* @param Realm|null $realm
* @param Realm $realm
* @return RealmNode
*/
public function setRealm(?Realm $realm): RealmNode
public function setRealm(Realm $realm): RealmNode
{
$this->realm = $realm;
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function onNodeJoinedRealm(AbstractRealmNodeEvent $event): void
*/
$this->bus->dispatch(new Envelope(new ApplyRealmNodeInheritanceMessage(
$event->getRealmNode()->getNode()->getId(),
$event->getRealmNode()->getRealm()?->getId()
$event->getRealmNode()->getRealm()->getId()
)));
}

Expand All @@ -70,7 +70,7 @@ public function onNodeLeftRealm(AbstractRealmNodeEvent $event): void
*/
$this->bus->dispatch(new Envelope(new CleanRealmNodeInheritanceMessage(
$event->getRealmNode()->getNode()->getId(),
$event->getRealmNode()->getRealm()?->getId()
$event->getRealmNode()->getRealm()->getId()
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public function defaultAction(Request $request, Node $id): Response
'node.%node%.joined.%realm%',
[
'%node%' => $nodeSource->getTitle(),
'%realm%' => $realmNode->getRealm() ?
$realmNode->getRealm()->getName() :
$this->translator->trans('node.no_realm')
'%realm%' => $realmNode->getRealm()->getName()
]
);
$this->publishConfirmMessage($request, $msg);
Expand Down

0 comments on commit 153d53c

Please sign in to comment.