Beispiel #1
0
 /**
  * @param FolderCreateEvent $event
  */
 public function create(FolderCreateEvent $event)
 {
     $folder = new FolderModel();
     $folder->setDispatcher($event->getDispatcher());
     $folder->setParent($event->getParent())->setVisible($event->getVisible())->setLocale($event->getLocale())->setTitle($event->getTitle())->save();
     $event->setFolder($folder);
 }
Beispiel #2
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();
 }
Beispiel #3
0
 /**
  * Declares an association between this object and a ChildFolder object.
  *
  * @param                  ChildFolder $v
  * @return                 \Thelia\Model\FolderVersion The current object (for fluent API support)
  * @throws PropelException
  */
 public function setFolder(ChildFolder $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aFolder = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildFolder object, it will not be re-added.
     if ($v !== null) {
         $v->addFolderVersion($this);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * generates a folder and its contents to be used in Position tests
  *
  * @return Folder the parent folder
  */
 protected function getFolderForPositionTest()
 {
     if (null === self::$folderForPositionTest) {
         $folder = new Folder();
         $folder->setParent(0);
         $folder->setVisible(1);
         $folder->setPosition(1);
         $this->setI18n($folder);
         $folder->save();
         for ($i = 0; $i < 4; $i++) {
             $content = new \Thelia\Model\Content();
             $content->addFolder($folder);
             $content->setVisible(1);
             $content->setPosition($i + 1);
             $this->setI18n($content);
             $contentFolders = $content->getContentFolders();
             $collection = new Collection();
             $collection->prepend($contentFolders[0]->setDefaultFolder(1));
             $content->setContentFolders($collection);
             $content->save();
         }
         self::$folderForPositionTest = $folder;
     }
     return self::$folderForPositionTest;
 }
Beispiel #5
0
 /**
  * Exclude object from result
  *
  * @param   ChildFolder $folder Object to remove from the list of results
  *
  * @return ChildFolderQuery The current query, for fluid interface
  */
 public function prune($folder = null)
 {
     if ($folder) {
         $this->addUsingAlias(FolderTableMap::ID, $folder->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #6
0
 /**
  * generates a folder and its sub folders to be used in Position tests
  *
  * @return int the parent folder id
  */
 protected function getFolderIdForPositionTest()
 {
     if (null === self::$folderIdForPositionTest) {
         $folder = new FolderModel();
         $folder->setParent(0);
         $folder->setVisible(1);
         $folder->setPosition(1);
         $this->setI18n($folder);
         $folder->save();
         for ($i = 0; $i < 4; $i++) {
             $subFolder = new FolderModel();
             $subFolder->setParent($folder->getId());
             $subFolder->setVisible(1);
             $subFolder->setPosition($i + 1);
             $this->setI18n($subFolder);
             $subFolder->save();
         }
         self::$folderIdForPositionTest = $folder->getId();
     }
     return self::$folderIdForPositionTest;
 }
Beispiel #7
0
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from contenu order by dossier asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     $image_import = new ContentImageImport($this->dispatcher, $this->t1db);
     $document_import = new ContentDocumentImport($this->dispatcher, $this->t1db);
     while ($hdl && ($contenu = $this->t1db->fetch_object($hdl))) {
         $count++;
         // Put contents on the root folder in a special folder
         if ($contenu->dossier == 0) {
             try {
                 $dossier = $this->fld_corresp->getT2($contenu->dossier);
             } catch (\Exception $ex) {
                 // Create the '0' folder
                 $root = new Folder();
                 $root->setParent(0)->setLocale('fr_FR')->setTitle("Dossier racine Thelia 1")->setLocale('en_US')->setTitle("Thelia 1 root folder")->setDescription("")->setChapo("")->setPostscriptum("")->setVisible(true)->save();
                 Tlog::getInstance()->warning("Created pseudo-root folder to store contents at root level");
                 $this->fld_corresp->addEntry(0, $root->getId());
             }
         }
         $dossier = $this->fld_corresp->getT2($contenu->dossier);
         if ($dossier > 0) {
             try {
                 $this->content_corresp->getT2($contenu->id);
                 Tlog::getInstance()->warning("Content ID={$contenu->id} already imported.");
                 continue;
             } catch (ImportException $ex) {
                 // Okay, the content was not imported.
             }
             try {
                 $event = new ContentCreateEvent();
                 $idx = 0;
                 $descs = $this->t1db->query_list("select * from contenudesc where contenu = ? order by lang asc", array($contenu->id));
                 foreach ($descs as $objdesc) {
                     $lang = $this->getT2Lang($objdesc->lang);
                     // A title is required to create the rewritten URL
                     if (empty($objdesc->titre)) {
                         $objdesc->titre = sprintf("Untitled-%d-%s", $objdesc->id, $lang->getCode());
                     }
                     if ($idx == 0) {
                         $event->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setDefaultFolder($dossier)->setVisible($contenu->ligne == 1 ? true : false);
                         $this->dispatcher->dispatch(TheliaEvents::CONTENT_CREATE, $event);
                         $content_id = $event->getContent()->getId();
                         // Update position
                         $update_position_event = new UpdatePositionEvent($content_id, UpdatePositionEvent::POSITION_ABSOLUTE, $contenu->classement);
                         $this->dispatcher->dispatch(TheliaEvents::CONTENT_UPDATE_POSITION, $update_position_event);
                         Tlog::getInstance()->info("Created content {$content_id} from {$objdesc->titre} ({$contenu->id})");
                         $this->content_corresp->addEntry($contenu->id, $content_id);
                         // Import images and documents
                         // ---------------------------
                         $image_import->importMedia($contenu->id, $content_id);
                         $document_import->importMedia($contenu->id, $content_id);
                     }
                     // Update the newly created content
                     $update_event = new ContentUpdateEvent($content_id);
                     $update_event->setTitle($objdesc->titre)->setDefaultFolder($this->fld_corresp->getT2($contenu->dossier))->setLocale($lang->getLocale())->setVisible($contenu->ligne == 1 ? true : false)->setChapo($objdesc->chapo)->setDescription($objdesc->description)->setPostscriptum($objdesc->postscriptum);
                     $this->dispatcher->dispatch(TheliaEvents::CONTENT_UPDATE, $update_event);
                     // Update the rewritten URL, if one was defined
                     $this->updateRewrittenUrl($event->getContent(), $lang->getLocale(), $objdesc->lang, "contenu", "%id_contenu={$contenu->id}&id_dossier={$contenu->dossier}%");
                     $idx++;
                 }
             } catch (\Exception $ex) {
                 Tlog::getInstance()->addError("Failed to import content ID={$contenu->id}: ", $ex->getMessage());
                 $errors++;
             }
         } else {
             Tlog::getInstance()->addError("Cannot import content ID={$contenu->id}, which is at root level (e.g., dossier parent = 0).");
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }
 /**
  * Returns the object ID from the object
  *
  * @param Folder $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Beispiel #9
0
 /**
  * generates a folder and its contents to be used in Position tests
  *
  * @return Folder the parent folder
  */
 protected function getFolderForPositionTest()
 {
     if (null === self::$folderForPositionTest) {
         $folder = new Folder();
         $folder->setParent(0);
         $folder->setVisible(1);
         $folder->setPosition(1);
         $this->setI18n($folder);
         $folder->save();
         for ($i = 0; $i < 4; $i++) {
             $content = new ContentModel();
             $content->setVisible(1);
             $content->addFolder($folder);
             $this->setI18n($content);
             $content->save();
         }
         self::$folderForPositionTest = $folder;
     }
     return self::$folderForPositionTest;
 }
Beispiel #10
0
 /**
  * Filter the query by a related \Thelia\Model\Folder object
  *
  * @param \Thelia\Model\Folder|ObjectCollection $folder The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildFolderDocumentQuery The current query, for fluid interface
  */
 public function filterByFolder($folder, $comparison = null)
 {
     if ($folder instanceof \Thelia\Model\Folder) {
         return $this->addUsingAlias(FolderDocumentTableMap::FOLDER_ID, $folder->getId(), $comparison);
     } elseif ($folder instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(FolderDocumentTableMap::FOLDER_ID, $folder->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByFolder() only accepts arguments of type \\Thelia\\Model\\Folder or Collection');
     }
 }