/**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var Category $category */
     $category = $observer->getEvent()->getCategory();
     if ($category->dataHasChangedFor('parent_id')) {
         $saveRewritesHistory = $this->scopeConfig->isSetFlag(UrlKeyRenderer::XML_PATH_SEO_SAVE_HISTORY, ScopeInterface::SCOPE_STORE, $category->getStoreId());
         $category->setData('save_rewrites_history', $saveRewritesHistory);
         $urlRewrites = array_merge($this->categoryUrlRewriteGenerator->generate($category), $this->urlRewriteHandler->generateProductUrlRewrites($category));
         $this->urlRewriteHandler->deleteCategoryRewritesForChildren($category);
         $this->urlPersist->replace($urlRewrites);
     }
 }
 /**
  * Generate urls for UrlRewrite and save it in storage
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /** @var Category $category */
     $category = $observer->getEvent()->getCategory();
     if ($category->getParentId() == Category::TREE_ROOT_ID) {
         return;
     }
     if ($category->dataHasChangedFor('url_key') || $category->getIsChangedProductList()) {
         $urlRewrites = array_merge($this->categoryUrlRewriteGenerator->generate($category), $this->urlRewriteHandler->generateProductUrlRewrites($category));
         $this->urlPersist->replace($urlRewrites);
     }
 }