Do not overwrite existing favicons

This commit is contained in:
Frederic Guillot 2017-01-02 20:34:41 -05:00
parent 97bab4aaad
commit d6d9368ab3
2 changed files with 10 additions and 1 deletions

View File

@ -31,6 +31,15 @@ function store_favicon($mime_type, $blob)
} }
$hash = sha1($blob); $hash = sha1($blob);
$favicon_id = Database::getInstance('db')
->table(TABLE)
->eq('hash', $hash)
->findOneColumn('id');
if ($favicon_id) {
return $favicon_id;
}
if (file_put_contents(get_favicon_filename($hash, $mime_type), $blob) === false) { if (file_put_contents(get_favicon_filename($hash, $mime_type), $blob) === false) {
return false; return false;
} }

View File

@ -90,7 +90,7 @@ class FaviconModelTest extends BaseTest
$this->assertCreateFeed($this->buildFeed()); $this->assertCreateFeed($this->buildFeed());
self::$functions self::$functions
->expects($this->any()) ->expects($this->once())
->method('file_put_contents') ->method('file_put_contents')
->with( ->with(
$this->stringEndsWith('data/favicons/57978a20204f7af6967571041c79d907a8a8072c.png'), $this->stringEndsWith('data/favicons/57978a20204f7af6967571041c79d907a8a8072c.png'),