/**
  * 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;
     }
 }
Example #2
0
 public static function getLanguages(LanguageRepositoryInterface $languageRepository, $withNoneOption = true)
 {
     $result = array();
     if ($withNoneOption) {
         $result["none"] = " ";
     }
     $languages = $languageRepository->activeLanguages();
     foreach ($languages as $language) {
         $result[$language->getId()] = $language->getLanguageName();
     }
     return $result;
 }
Example #3
0
 /**
  * Adds the page's seo attributes when a new page is added, for each language of
  * the site
  *
  * @param  BeforeAddPageCommitEvent $event
  * @return boolean
  * @throws InvalidArgumentException
  * @throws \Exception
  *
  * @api
  */
 public function onBeforeAddPageCommit(BeforeAddPageCommitEvent $event)
 {
     if ($event->isAborted()) {
         return;
     }
     $pageManager = $event->getContentManager();
     $pageRepository = $pageManager->getPageRepository();
     $values = $event->getValues();
     if (!is_array($values)) {
         throw new InvalidArgumentException('exception_invalid_value_array_required');
     }
     try {
         $languages = $this->languageRepository->activeLanguages();
         if (count($languages)) {
             $result = true;
             $idPage = $pageManager->get()->getId();
             $this->seoManager->getSeoRepository()->setConnection($pageRepository->getConnection());
             $pageRepository->startTransaction();
             foreach ($languages as $alLanguage) {
                 $seoManagerValues = array_merge($values, array('PageId' => $idPage, 'LanguageId' => $alLanguage->getId(), 'CreatedAt' => date("Y-m-d H:i:s")));
                 if (!$alLanguage->getMainLanguage() && array_key_exists('Permalink', $seoManagerValues)) {
                     $seoManagerValues['Permalink'] = $alLanguage->getLanguageName() . '-' . $seoManagerValues['Permalink'];
                 }
                 $this->seoManager->set(null);
                 $result = $this->seoManager->save($seoManagerValues);
                 if (false === $result) {
                     break;
                 }
             }
             if (false !== $result) {
                 $pageRepository->commit();
                 return;
             }
             $pageRepository->rollBack();
             $event->abort();
         }
     } catch (\Exception $e) {
         $event->abort();
         if (isset($pageRepository) && $pageRepository !== null) {
             $pageRepository->rollBack();
         }
         throw $e;
     }
 }
Example #4
0
 /**
  * Saves the current theme structure into a file
  *
  * @param  ThemeInterface $theme
  * @param  string           $themeStructureFile
  * @throws \Exception
  */
 protected function saveThemeStructure(ThemeInterface $theme, $themeStructureFile)
 {
     $templates = array();
     foreach ($this->languagesRepository->activeLanguages() as $language) {
         foreach ($this->pagesRepository->activePages() as $page) {
             $key = $language->getId() . '-' . $page->getId();
             $templates[$key] = $page->getTemplateName();
         }
     }
     $themeName = $theme->getThemeName();
     $currentTheme = array("Theme" => $themeName, "Templates" => $templates);
     file_put_contents($themeStructureFile, json_encode($currentTheme));
 }
 /**
  * Degrades the main language to normal language
  *
  * @throws \Exception
  * @return boolean
  *
  * @api
  */
 protected function resetMain()
 {
     try {
         $language = $this->languageRepository->mainLanguage();
         if (null !== $language) {
             $result = $this->languageRepository->setRepositoryObject($language)->save(array('MainLanguage' => 0));
             return $result;
         }
         return true;
     } catch (\Exception $e) {
         if (isset($this->languageRepository) && $this->languageRepository !== null) {
             $this->languageRepository->rollBack();
         }
         throw $e;
     }
 }
 /**
  * Fills up the PageTree collection
  */
 public function fill()
 {
     $languages = $this->languageRepository->activeLanguages();
     $this->initPages($languages);
     $this->initBasePages($languages);
 }
Example #7
0
 /**
  * Removes the active languages
  *
  * @param  \RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Repository\Repository\LanguageRepositoryInterface $languageRepository
  * @return boolean
  */
 protected function removeActiveLanguages(LanguageRepositoryInterface $languageRepository)
 {
     try {
         $languages = $languageRepository->activeLanguages();
         foreach ($languages as $language) {
             $language->delete();
         }
         return true;
     } catch (\Exception $ex) {
         $this->errorMessage = "An error occoured during the removing of existing languages. The reported error is: " . $ex->getMessage();
         return false;
     }
 }