Skip to content

Commit 6661e96

Browse files
committed
fix: load all blog entry ids when updating seo urls
1 parent 6ac0e2b commit 6661e96

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
<argument type="service" id="Shopware\Core\Content\Seo\SeoUrlUpdater"/>
194194
<argument type="service" id="category.repository"/>
195195
<argument type="service" id="werkl_blog_entry.repository"/>
196+
<argument type="service" id="seo_url_template.repository"/>
196197
<argument type="service" id="Shopware\Core\Framework\Adapter\Cache\CacheInvalidator"/>
197198
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
198199

src/Subscriber/BlogCacheInvalidSubscriber.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Shopware\Core\Content\Category\SalesChannel\CategoryRoute;
77
use Shopware\Core\Content\Cms\CmsPageEvents;
88
use Shopware\Core\Content\Seo\Event\SeoEvents;
9+
use Shopware\Core\Content\Seo\SeoUrlTemplate\SeoUrlTemplateCollection;
910
use Shopware\Core\Content\Seo\SeoUrlUpdater;
1011
use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
1112
use Shopware\Core\Framework\Context;
@@ -19,6 +20,7 @@
1920
use Shopware\Core\System\SystemConfig\SystemConfigService;
2021
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2122
use Werkl\OpenBlogware\Content\Blog\BlogEntryCollection;
23+
use Werkl\OpenBlogware\Content\Blog\BlogEntryDefinition;
2224
use Werkl\OpenBlogware\Content\Blog\BlogSeoUrlRoute;
2325
use Werkl\OpenBlogware\Content\BlogCategory\BlogCategoryCollection;
2426
use Werkl\OpenBlogware\Controller\BlogController;
@@ -34,11 +36,13 @@ class BlogCacheInvalidSubscriber implements EventSubscriberInterface
3436
/**
3537
* @param EntityRepository<BlogCategoryCollection> $categoryRepository
3638
* @param EntityRepository<BlogEntryCollection> $blogRepository
39+
* @param EntityRepository<SeoUrlTemplateCollection> $seoUrlTemplateRepository
3740
*/
3841
public function __construct(
3942
private readonly SeoUrlUpdater $seoUrlUpdater,
4043
private readonly EntityRepository $categoryRepository,
4144
private readonly EntityRepository $blogRepository,
45+
private readonly EntityRepository $seoUrlTemplateRepository,
4246
private readonly CacheInvalidator $cacheInvalidator,
4347
private readonly SystemConfigService $systemConfigService
4448
) {
@@ -126,9 +130,21 @@ public function onDeleteInvalidateCache(EntityDeletedEvent $event): void
126130
/**
127131
* When update SEO template in the settings, we will update all SEO URLs for the blog articles
128132
*/
129-
public function updateSeoUrlForAllArticles(): void
133+
public function updateSeoUrlForAllArticles(EntityWrittenEvent $event): void
130134
{
131-
$this->seoUrlUpdater->update(BlogSeoUrlRoute::ROUTE_NAME, []);
135+
$context = $event->getContext();
136+
137+
$criteria = (new Criteria($event->getIds()))
138+
->addFilter(new EqualsFilter('entityName', BlogEntryDefinition::ENTITY_NAME));
139+
140+
if ($this->seoUrlTemplateRepository->searchIds($criteria, $context)->getTotal() < 1) {
141+
return;
142+
}
143+
144+
/** @var list<string> $ids */
145+
$ids = $this->blogRepository->searchIds(new Criteria(), $context)->getIds();
146+
147+
$this->seoUrlUpdater->update(BlogSeoUrlRoute::ROUTE_NAME, $ids);
132148
}
133149

134150
/**

0 commit comments

Comments
 (0)