Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a unique slug to the meetup-event entity #74

Merged
merged 1 commit into from
Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"presta/sitemap-bundle": "^1.7",
"sensio/framework-extra-bundle": "^5.3",
"snc/redis-bundle": "^2.1",
"stof/doctrine-extensions-bundle": "^1.5",
"symfony/cache": "4.4.*",
"symfony/config": "4.4.*",
"symfony/console": "4.4.*",
Expand Down
220 changes: 218 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true],
Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true, 'test' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
];
5 changes: 5 additions & 0 deletions config/packages/stof_doctrine_extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
sluggable: true
19 changes: 19 additions & 0 deletions src/Entity/MeetupEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gdemo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

Expand Down Expand Up @@ -122,6 +123,12 @@ class MeetupEvent
*/
private $updatedAt;

/**
* @ORM\Column(type="string", length=255, unique=true)
* @Gdemo\Slug(fields={"title"})
*/
private $slug;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -388,4 +395,16 @@ public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}

public function getSlug(): ?string
{
return $this->slug;
}

public function setSlug(string $slug): self
{
$this->slug = $slug;

return $this;
}
}
35 changes: 35 additions & 0 deletions src/Migrations/Version20201127130925.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Version20201127130925 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add the slug field without restrictions to have a safe migration';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE meetup_event ADD slug VARCHAR(255) NOT NULL, CHANGE created_at created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE meetup_event DROP slug, CHANGE created_at created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL');
}
}
Loading