'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');
}
foreach ($hashedUrls as $hashedUrl) {
$res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId());
- // $results[$url] = $this->returnExistInformation($res, $returnId);
$results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
}
->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 {
* 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();
}
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'));
}
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=');