Skip to content

Commit

Permalink
Fix MySQL error for column 'path' without length used in an index (#33)
Browse files Browse the repository at this point in the history
* Use a md5 of the path to avoid MySQL error about indexed column length

* Use sha1 instead of md5

* Add schema update precision in the changelog
  • Loading branch information
pyrech authored Mar 26, 2018
1 parent 0548479 commit 788aa46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Not yet released

* Dropped compatibility with Symfony < 3.0
* Added compatibility with Symfony 4.0
* Drop compatibility with Symfony < 3.0
* Add compatibility with Symfony 4.0
* [BC BREAK][Doctrine] Changed SeoOverride SQL index to use a hash of the path
(you should update your database schema due to SQL column and index changes)

## 0.5.1 (2017-12-28)

Expand Down
11 changes: 11 additions & 0 deletions src/Bridge/Doctrine/Entity/SeoOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class SeoOverride
*/
private $path;

/**
* @var string
*/
private $hashedPath;

/**
* @var string|null
*/
Expand All @@ -46,6 +51,12 @@ public function getPath()
public function setPath(string $path)
{
$this->path = $path;
$this->hashedPath = sha1($path);
}

public function getHashedPath()
{
return $this->hashedPath;
}

public function getDomainAlias()
Expand Down
7 changes: 4 additions & 3 deletions src/Bridge/Doctrine/Repository/SeoOverrideRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class SeoOverrideRepository extends EntityRepository
public function findOneForPathAndDomain(string $path, string $domainAlias = null)
{
return $this->createQueryBuilder('s')
->andWhere('s.path = :path')
->setParameter('path', $path)
->andWhere('s.hashedPath = :hashedPath')
->setParameter('hashedPath', sha1($path))
->andWhere('s.domainAlias = :domainAlias')
->setParameter('domainAlias', $domainAlias)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
->getOneOrNullResult()
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Joli\SeoOverride\Bridge\Doctrine\Entity\SeoOverride:
table: joli_seo_override
indexes:
request_index:
columns: [ path, domain_alias ]
columns: [ hashed_path, domain_alias ]
id:
id:
type: integer
Expand All @@ -14,6 +14,10 @@ Joli\SeoOverride\Bridge\Doctrine\Entity\SeoOverride:
path:
column: path
type: text
hashedPath:
column: hashed_path
type: string
length: 40
domainAlias:
column: domain_alias
type: string
Expand Down

0 comments on commit 788aa46

Please sign in to comment.