Skip to content

Commit 5e58a7a

Browse files
author
Zane
committed
Add image hash (unique)
1 parent b74fa4f commit 5e58a7a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

‎migrations/Version00000000000000.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function up(Schema $schema): void
4343
$this->addSql('CREATE UNIQUE INDEX UNIQ_23A0E662B36786B ON article (title)');
4444

4545
// IMAGES
46-
$this->addSql('CREATE TABLE image (id INT UNSIGNED AUTO_INCREMENT NOT NULL, title VARCHAR(512) NOT NULL, format VARCHAR(5) NOT NULL, watermark_position SMALLINT UNSIGNED NOT NULL DEFAULT 4, reusable TINYINT(1) NOT NULL DEFAULT 0, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
46+
$this->addSql('CREATE TABLE image (id INT UNSIGNED AUTO_INCREMENT NOT NULL, title VARCHAR(512) NOT NULL, format VARCHAR(5) NOT NULL, watermark_position SMALLINT UNSIGNED NOT NULL DEFAULT 4, reusable TINYINT(1) NOT NULL DEFAULT 0, hash CHAR(32) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
47+
$this->addSql('CREATE UNIQUE INDEX UNIQ_C53D045FD1B862B8 ON image (hash)');
4748

4849
// TAGS
4950
$this->addSql('CREATE TABLE tag (id INT UNSIGNED AUTO_INCREMENT NOT NULL, title VARCHAR(512) NOT NULL, replacement_id INT UNSIGNED DEFAULT NULL, ranking SMALLINT UNSIGNED NOT NULL DEFAULT 1, views INT UNSIGNED NOT NULL DEFAULT 0, abstract VARCHAR(2000) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');

‎src/Entity/Cms/Image.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Image extends BaseCmsEntity
4040
#[ORM\Column(type: 'boolean', options: ['default' => false])]
4141
protected bool $reusable = false;
4242

43+
#[ORM\Column(length: 32, unique: true, options: ["fixed" => true])]
44+
protected ?string $hash = null;
45+
4346
#[ORM\OneToMany(mappedBy: 'image', targetEntity: ImageAuthor::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
4447
#[ORM\OrderBy(['ranking' => 'ASC'])]
4548
protected Collection $authors;
@@ -109,6 +112,14 @@ public function setReusable(bool $reusable) : static
109112
return $this;
110113
}
111114

115+
public function getHash(): ?string { return $this->hash; }
116+
117+
public function setHash(string $hash) : static
118+
{
119+
$this->hash = $hash;
120+
return $this;
121+
}
122+
112123
/**
113124
* @return Collection<int, ImageAuthor>
114125
*/

‎src/Service/Cms/Image.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function getOriginalFilePath() : string
145145
{
146146
$imageFolderMod = $this->getFolderMod();
147147
$fileName = $this->getOriginalFileName();
148+
148149
return
149150
$this->projectDir->createVarDirFromFilePath(
150151
static::UPLOADED_IMAGES_FOLDER_NAME . "/originals/$imageFolderMod/$fileName"

0 commit comments

Comments
 (0)