mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-22 17:18:37 +00:00
Fixing tests
This commit is contained in:
parent
7f55941856
commit
48656e0eaa
7 changed files with 63 additions and 23 deletions
|
@ -49,22 +49,23 @@ class DownloadImagesSubscriber implements EventSubscriber
|
|||
return;
|
||||
}
|
||||
|
||||
$em = $args->getEntityManager();
|
||||
$config = new $this->configClass();
|
||||
$config->setEntityManager($args->getEntityManager());
|
||||
|
||||
// field content has been updated
|
||||
if ($args->hasChangedField('content')) {
|
||||
$html = $this->downloadImages($em, $entity);
|
||||
$html = $this->downloadImages($config, $entity);
|
||||
|
||||
if (null !== $html) {
|
||||
if (false !== $html) {
|
||||
$args->setNewValue('content', $html);
|
||||
}
|
||||
}
|
||||
|
||||
// field preview picture has been updated
|
||||
if ($args->hasChangedField('previewPicture')) {
|
||||
$previewPicture = $this->downloadPreviewImage($em, $entity);
|
||||
$previewPicture = $this->downloadPreviewImage($config, $entity);
|
||||
|
||||
if (null !== $previewPicture) {
|
||||
if (false !== $previewPicture) {
|
||||
$entity->setPreviewPicture($previewPicture);
|
||||
}
|
||||
}
|
||||
|
@ -88,17 +89,25 @@ class DownloadImagesSubscriber implements EventSubscriber
|
|||
|
||||
// update all images inside the html
|
||||
$html = $this->downloadImages($config, $entity);
|
||||
if (null !== $html) {
|
||||
if (false !== $html) {
|
||||
$entity->setContent($html);
|
||||
}
|
||||
|
||||
// update preview picture
|
||||
$previewPicture = $this->downloadPreviewImage($config, $entity);
|
||||
if (null !== $previewPicture) {
|
||||
if (false !== $previewPicture) {
|
||||
$entity->setPreviewPicture($previewPicture);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download all images from the html.
|
||||
*
|
||||
* @param Config $config
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @return string|false False in case of async
|
||||
*/
|
||||
public function downloadImages(Config $config, Entry $entry)
|
||||
{
|
||||
// if ($config->get('download_images_with_rabbitmq')) {
|
||||
|
@ -113,6 +122,14 @@ class DownloadImagesSubscriber implements EventSubscriber
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the preview picture.
|
||||
*
|
||||
* @param Config $config
|
||||
* @param Entry $entry
|
||||
*
|
||||
* @return string|false False in case of async
|
||||
*/
|
||||
public function downloadPreviewImage(Config $config, Entry $entry)
|
||||
{
|
||||
// if ($config->get('download_images_with_rabbitmq')) {
|
||||
|
|
|
@ -65,6 +65,7 @@ class ContentProxy
|
|||
|
||||
$entry->setUrl($content['url'] ?: $url);
|
||||
$entry->setTitle($title);
|
||||
$entry->setContent($html);
|
||||
|
||||
$entry->setLanguage($content['language']);
|
||||
$entry->setMimetype($content['content_type']);
|
||||
|
@ -75,8 +76,6 @@ class ContentProxy
|
|||
$entry->setDomainName($domainName);
|
||||
}
|
||||
|
||||
$entry->setContent($html);
|
||||
|
||||
if (isset($content['open_graph']['og_image'])) {
|
||||
$entry->setPreviewPicture($content['open_graph']['og_image']);
|
||||
}
|
||||
|
|
|
@ -91,20 +91,23 @@ class DownloadImages
|
|||
// build image path
|
||||
$absolutePath = $this->getAbsoluteLink($url, $imagePath);
|
||||
if (false === $absolutePath) {
|
||||
$this->logger->log('debug', 'Can not determine the absolute path for that image, skipping.');
|
||||
$this->logger->log('error', 'Can not determine the absolute path for that image, skipping.');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = $this->client->get(
|
||||
$absolutePath,
|
||||
['exceptions' => false]
|
||||
);
|
||||
try {
|
||||
$res = $this->client->get($absolutePath);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->log('error', 'Can not retrieve image, skipping.', ['exception' => $e]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$ext = $this->mimeGuesser->guess($res->getHeader('content-type'));
|
||||
$this->logger->log('debug', 'Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]);
|
||||
if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'])) {
|
||||
$this->logger->log('debug', 'Processed image with not allowed extension. Skipping '.$imagePath);
|
||||
if (!in_array($ext, ['jpeg', 'jpg', 'gif', 'png'], true)) {
|
||||
$this->logger->log('error', 'Processed image with not allowed extension. Skipping '.$imagePath);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -117,7 +120,7 @@ class DownloadImages
|
|||
$im = false;
|
||||
}
|
||||
|
||||
if ($im === false) {
|
||||
if (false === $im) {
|
||||
$this->logger->log('error', 'Error while regenerating image', ['path' => $localPath]);
|
||||
|
||||
return false;
|
||||
|
@ -193,6 +196,8 @@ class DownloadImages
|
|||
return $absolute->get_uri();
|
||||
}
|
||||
|
||||
$this->logger->log('error', 'Can not make an absolute link', ['base' => $base, 'url' => $url]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue