Change the way to define algorithm for hashing url
This commit is contained in:
parent
4a5516376b
commit
0132ccd2a2
@ -66,9 +66,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
|
|||||||
|
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$entry->setHashedUrl(
|
$entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl()));
|
||||||
UrlHasher::hashUrl($entry->getUrl())
|
|
||||||
);
|
|
||||||
$em->persist($entry);
|
$em->persist($entry);
|
||||||
|
|
||||||
if (0 === ($i % 20)) {
|
if (0 === ($i % 20)) {
|
||||||
@ -87,7 +85,7 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
|
|||||||
*
|
*
|
||||||
* @param string $username
|
* @param string $username
|
||||||
*
|
*
|
||||||
* @return \Wallabag\UserBundle\Entity\User
|
* @return User
|
||||||
*/
|
*/
|
||||||
private function getUser($username)
|
private function getUser($username)
|
||||||
{
|
{
|
||||||
|
@ -7,16 +7,17 @@ namespace Wallabag\CoreBundle\Helper;
|
|||||||
*/
|
*/
|
||||||
class UrlHasher
|
class UrlHasher
|
||||||
{
|
{
|
||||||
/** @var string */
|
|
||||||
const ALGORITHM = 'sha1';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* Hash the given url using the given algorithm.
|
||||||
|
* Hashed url are faster to be retrieved in the database than the real url.
|
||||||
*
|
*
|
||||||
* @return string hashed $url
|
* @param string $url
|
||||||
|
* @param string $algorithm
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function hashUrl(string $url)
|
public static function hashUrl(string $url, $algorithm = 'sha1')
|
||||||
{
|
{
|
||||||
return hash(static::ALGORITHM, $url);
|
return hash($algorithm, urldecode($url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,8 @@ class EntryRepository extends EntityRepository
|
|||||||
{
|
{
|
||||||
return $this->findByHashedUrlAndUserId(
|
return $this->findByHashedUrlAndUserId(
|
||||||
UrlHasher::hashUrl($url),
|
UrlHasher::hashUrl($url),
|
||||||
$userId);
|
$userId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user