66use Shopware \Core \Content \Category \SalesChannel \CategoryRoute ;
77use Shopware \Core \Content \Cms \CmsPageEvents ;
88use Shopware \Core \Content \Seo \Event \SeoEvents ;
9+ use Shopware \Core \Content \Seo \SeoUrlTemplate \SeoUrlTemplateCollection ;
910use Shopware \Core \Content \Seo \SeoUrlUpdater ;
1011use Shopware \Core \Framework \Adapter \Cache \CacheInvalidator ;
1112use Shopware \Core \Framework \Context ;
1920use Shopware \Core \System \SystemConfig \SystemConfigService ;
2021use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
2122use Werkl \OpenBlogware \Content \Blog \BlogEntryCollection ;
23+ use Werkl \OpenBlogware \Content \Blog \BlogEntryDefinition ;
2224use Werkl \OpenBlogware \Content \Blog \BlogSeoUrlRoute ;
2325use Werkl \OpenBlogware \Content \BlogCategory \BlogCategoryCollection ;
2426use 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