Some cleanup

Also, do not run the hashed_url migration into a Doctrine migration
This commit is contained in:
Jeremy Benoist 2019-04-01 14:34:20 +02:00
parent 8a64566298
commit c579ce2306
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
5 changed files with 23 additions and 15 deletions

View file

@ -24,11 +24,6 @@ class Version20190401105353 extends WallabagMigration
'notnull' => false,
]);
// sqlite doesn't have the MD5 function by default
if ('sqlite' !== $this->connection->getDatabasePlatform()->getName()) {
$this->addSql('UPDATE ' . $this->getTable('entry') . ' SET hashed_url = MD5(url)');
}
$entryTable->addIndex(['user_id', 'hashed_url'], 'hashed_url_user_id');
}

View file

@ -52,7 +52,6 @@ class EntryRestController extends WallabagRestController
foreach ($hashedUrls as $hashedUrl) {
$res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId());
// $results[$url] = $this->returnExistInformation($res, $returnId);
$results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
}

View file

@ -20,18 +20,14 @@ class GenerateUrlHashesCommand extends ContainerAwareCommand
->setName('wallabag:generate-hashed-urls')
->setDescription('Generates hashed urls for each entry')
->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved')
->addArgument(
'username',
InputArgument::OPTIONAL,
'User to process entries'
);
->addArgument('username', InputArgument::OPTIONAL, 'User to process entries');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
$username = $input->getArgument('username');
$username = (string) $input->getArgument('username');
if ($username) {
try {

View file

@ -350,15 +350,15 @@ class EntryRepository extends EntityRepository
* Find an entry by its hashed url and its owner.
* If it exists, return the entry otherwise return false.
*
* @param $hashedUrl
* @param $userId
* @param string $hashedUrl Url hashed using sha1
* @param int $userId
*
* @return Entry|bool
*/
public function findByHashedUrlAndUserId($hashedUrl, $userId)
{
$res = $this->createQueryBuilder('e')
->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', urldecode($hashedUrl))
->where('e.hashedUrl = :hashed_url')->setParameter('hashed_url', $hashedUrl)
->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
->getQuery()
->getResult();

View file

@ -1076,6 +1076,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
}
public function testGetEntriesExistsWhichDoesNotExists()
{
$this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertFalse($content['exists']);
}
public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl()
{
$this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
@ -1087,6 +1098,13 @@ class EntryRestControllerTest extends WallabagApiTestCase
}
public function testGetEntriesExistsWithNoUrl()
{
$this->client->request('GET', '/api/entries/exists?url=');
$this->assertSame(403, $this->client->getResponse()->getStatusCode());
}
public function testGetEntriesExistsWithNoHashedUrl()
{
$this->client->request('GET', '/api/entries/exists?hashed_url=');