mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-22 17:11:07 +00:00
Some cleanup
Also, do not run the hashed_url migration into a Doctrine migration
This commit is contained in:
parent
8a64566298
commit
c579ce2306
5 changed files with 23 additions and 15 deletions
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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=');
|
||||
|
||||
|
|
Loading…
Reference in a new issue