Fixed thumbnails for deleted Youtube videos

This commit is contained in:
Marcin Kurczewski 2014-07-25 18:55:27 +02:00
parent e2f6440e18
commit c7f077d89a
3 changed files with 37 additions and 20 deletions

View file

@ -28,7 +28,16 @@ foreach ($posts as $post)
unlink($post->getThumbnailPath()); unlink($post->getThumbnailPath());
if (!file_exists($post->getThumbnailPath())) if (!file_exists($post->getThumbnailPath()))
$post->generateThumbnail(); {
try
{
$post->generateThumbnail();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
} }
echo 'Don\'t forget to check access rights.' . PHP_EOL; echo 'Don\'t forget to check access rights.' . PHP_EOL;

View file

@ -13,21 +13,37 @@ class GetPostThumbnailJob extends AbstractJob
$post = $this->postRetriever->retrieve(); $post = $this->postRetriever->retrieve();
$path = $post->getThumbnailPath(); $path = $post->getThumbnailPath();
if (!file_exists($path) or !is_readable($path)) if (!$this->isValidThumbnailPath($path))
{ {
$post->generateThumbnail(); try
$path = $post->getThumbnailPath();
if (!file_exists($path) or !is_readable($path))
{ {
$path = Core::getConfig()->main->mediaPath . DS . 'img' . DS . 'thumb.jpg'; $post->generateThumbnail();
$path = TextHelper::absolutePath($path); $path = $post->getThumbnailPath();
} }
catch (Exception $e)
{
$path = null;
}
if (!$this->isValidThumbnailPath($path))
$path = $this->getDefaultThumbnailPath();
} }
return new ApiFileOutput($path, 'thumbnail.jpg'); return new ApiFileOutput($path, 'thumbnail.jpg');
} }
private function isValidThumbnailPath($path)
{
return file_exists($path) and is_readable($path);
}
private function getDefaultThumbnailPath()
{
$path = Core::getConfig()->main->mediaPath . DS . 'img' . DS . 'thumb.jpg';
$path = TextHelper::absolutePath($path);
return $path;
}
public function getRequiredArguments() public function getRequiredArguments()
{ {
return $this->postRetriever->getRequiredArguments(); return $this->postRetriever->getRequiredArguments();

View file

@ -5,18 +5,10 @@ class SmartThumbnailGenerator implements IThumbnailGenerator
{ {
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg'; $tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.jpg';
try TransferHelper::download(
{ $url,
TransferHelper::download( $tmpPath,
$url, null);
$tmpPath,
null);
}
catch (SimpleException $e)
{
echo $e->getMessage();
return false;
}
$ret = self::generateFromFile($tmpPath, $dstPath, $width, $height); $ret = self::generateFromFile($tmpPath, $dstPath, $width, $height);