From 0de6738817547fcf430bd5e205316f880209b467 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Sun, 21 Feb 2021 22:55:39 +0100 Subject: [PATCH] 4 --- migrations/Version20210221204057.php | 14 ++++++++------ src/Controller/SiteController.php | 4 ++++ src/Entity/Site.php | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/migrations/Version20210221204057.php b/migrations/Version20210221204057.php index 2761f9c..9b02ef0 100644 --- a/migrations/Version20210221204057.php +++ b/migrations/Version20210221204057.php @@ -12,20 +12,22 @@ */ final class Version20210221204057 extends AbstractMigration { - public function getDescription() : string + public function getDescription(): string { - return ''; + return ""; } - public function up(Schema $schema) : void + public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE TABLE site (host VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL, messages_monday VARCHAR(255) NOT NULL, messages_tuesday VARCHAR(255) NOT NULL, messages_wednesday VARCHAR(255) NOT NULL, messages_thursday VARCHAR(255) NOT NULL, messages_friday VARCHAR(255) NOT NULL, messages_saturday VARCHAR(255) NOT NULL, messages_sunday VARCHAR(255) NOT NULL, PRIMARY KEY(host))'); + $this->addSql( + "CREATE TABLE site (host VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL, messages_monday VARCHAR(255) NOT NULL, messages_tuesday VARCHAR(255) NOT NULL, messages_wednesday VARCHAR(255) NOT NULL, messages_thursday VARCHAR(255) NOT NULL, messages_friday VARCHAR(255) NOT NULL, messages_saturday VARCHAR(255) NOT NULL, messages_sunday VARCHAR(255) NOT NULL, PRIMARY KEY(host))" + ); } - public function down(Schema $schema) : void + public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->addSql('DROP TABLE site'); + $this->addSql("DROP TABLE site"); } } diff --git a/src/Controller/SiteController.php b/src/Controller/SiteController.php index cc1d84d..e836b9c 100644 --- a/src/Controller/SiteController.php +++ b/src/Controller/SiteController.php @@ -8,6 +8,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Annotation\Route; /** @@ -24,6 +25,9 @@ public function index( ): Response { $host = $request->get("host", $request->getHost()); $site = $siteRepository->findOneByHost($host); + if (null === $site) { + throw new NotFoundHttpException(); + } $now = $this->getNow($request); $message = "…"; if (null !== $site && $site->getMessages()) { diff --git a/src/Entity/Site.php b/src/Entity/Site.php index dbf2d13..a46ffa0 100644 --- a/src/Entity/Site.php +++ b/src/Entity/Site.php @@ -30,6 +30,7 @@ class Site /** * @ORM\Column(type="string", length=255) + * @Assert\NotBlank() */ private $title;