Exemplo n.º 1
0
 /**
  * Create and save the id of the pop-in images folder if necessary.
  *
  * @throws \Exception
  * @throws PropelException
  */
 protected function createPopInImageFolder()
 {
     $imageFolderIdConfig = ConfigQuery::create()->findOneByName(static::CONF_KEY_IMAGE_FOLDER_ID);
     if (null !== $imageFolderIdConfig && null !== FolderQuery::create()->findPk($imageFolderIdConfig->getValue())) {
         // we already have and know our images folder
         return;
     }
     Propel::getConnection()->beginTransaction();
     try {
         // create the folder
         $folder = new Folder();
         $folder->setVisible(true);
         /** @var Lang $lang */
         foreach (LangQuery::create()->find() as $lang) {
             $localizedTitle = Translator::getInstance()->trans("Pop-in images", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
             if ($localizedTitle == "") {
                 continue;
             }
             $folder->setLocale($lang->getLocale())->setTitle($localizedTitle);
         }
         $folder->save();
         // save the folder id in configuration
         if ($folder->getId() !== null) {
             $config = new Config();
             $config->setName(static::CONF_KEY_IMAGE_FOLDER_ID)->setValue($folder->getId())->setHidden(false);
             /** @var Lang $lang */
             foreach (LangQuery::create()->find() as $lang) {
                 $localizedTitle = Translator::getInstance()->trans("Pop-in images folder id", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
                 if ($localizedTitle == "") {
                     continue;
                 }
                 $config->setLocale($lang->getLocale())->setTitle($localizedTitle);
             }
             $config->save();
         }
     } catch (\Exception $e) {
         Propel::getConnection()->rollBack();
         throw $e;
     }
     Propel::getConnection()->commit();
 }