/**
  * Deletes the page's contents, for all the languages of the site
  *
  * @param  BeforeDeletePageCommitEvent $event
  * @return boolean
  * @throws \Exception
  *
  * @api
  */
 public function onBeforeDeletePageCommit(BeforeDeletePageCommitEvent $event)
 {
     if ($event->isAborted()) {
         return;
     }
     $pageManager = $event->getContentManager();
     $pageRepository = $pageManager->getPageRepository();
     try {
         $languages = $this->languageRepository->activeLanguages();
         if (count($languages) > 0) {
             $idPage = $pageManager->get()->getId();
             $pageRepository->startTransaction();
             foreach ($languages as $alLanguage) {
                 $this->blockRepository->deleteBlocks($alLanguage->getId(), $idPage);
             }
             $pageRepository->commit();
             return true;
         }
     } catch (\Exception $e) {
         $event->abort();
         if (isset($pageRepository) && $pageRepository !== null) {
             $pageRepository->rollBack();
         }
         throw $e;
     }
 }
Пример #2
0
 /**
  * Deletes the page's seo attributes, for all the languages of the site
  *
  * @param  BeforeDeletePageCommitEvent $event
  * @return boolean
  * @throws \Exception
  *
  * api
  */
 public function onBeforeDeletePageCommit(BeforeDeletePageCommitEvent $event)
 {
     if ($event->isAborted()) {
         return;
     }
     $pageManager = $event->getContentManager();
     $pageRepository = $pageManager->getPageRepository();
     try {
         $languages = $this->languageRepository->activeLanguages();
         if (count($languages) > 0) {
             $result = null;
             $pageRepository->startTransaction();
             $idPage = $pageManager->get()->getId();
             foreach ($languages as $alLanguage) {
                 $result = $this->seoManager->deleteSeoAttributesFromLanguage($alLanguage->getId(), $idPage);
                 if (false === $result) {
                     break;
                 }
             }
             if (false !== $result) {
                 $pageRepository->commit();
             } else {
                 $pageRepository->rollBack();
                 $event->abort();
             }
         }
     } catch (\Exception $e) {
         $event->abort();
         if (isset($pageRepository) && $pageRepository !== null) {
             $pageRepository->rollBack();
         }
         throw $e;
     }
 }