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());
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;

View file

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

View file

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