Skip to content

Commit

Permalink
Switch to correct blog ID before fetching thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
foopang authored and kayue committed Dec 11, 2017
1 parent 8d23f9e commit 6a9cda8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Wordpress/Helper/AttachmentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ protected function getManager()

public function findThumbnail(Post $post)
{
$originBlogId = $this->getManager()->getBlogId();
if ($this->getManager()->getBlogId() !== $post->getBlogId()) {
$this->managerRegistry->setCurrentBlogId($post->getBlogId());
}

$id = $this->getManager()->getRepository('KayueWordpressBundle:PostMeta')->findOneBy([
'post' => $post,
'key' => '_thumbnail_id',
Expand All @@ -33,19 +38,34 @@ public function findThumbnail(Post $post)
return null;
}

return $this->getManager()->getRepository('KayueWordpressBundle:Post')->findOneBy([
$thumbnail = $this->getManager()->getRepository('KayueWordpressBundle:Post')->findOneBy([
'id' => $id->getValue(),
'type' => 'attachment',
]);

if ($originBlogId !== $this->getManager()->getBlogId()) {
$this->managerRegistry->setCurrentBlogId($originBlogId);
}

return $thumbnail;
}

public function getAttachmentUrl(Post $post, $size = 'post-thumbnail')
{
$originBlogId = $this->getManager()->getBlogId();
if ($this->getManager()->getBlogId() !== $post->getBlogId()) {
$this->managerRegistry->setCurrentBlogId($post->getBlogId());
}

$metadata = $this->getManager()->getRepository('KayueWordpressBundle:PostMeta')->findOneBy([
'post' => $post,
'key' => '_wp_attachment_metadata',
]);

if ($originBlogId !== $this->getManager()->getBlogId()) {
$this->managerRegistry->setCurrentBlogId($originBlogId);
}

if (!$metadata) {
return null;
}
Expand Down

0 comments on commit 6a9cda8

Please sign in to comment.