Пример #1
0
 public function testCreateContent()
 {
     $folder = $this->getRandomFolder();
     $event = new ContentCreateEvent();
     $event->setVisible(1)->setLocale('en_US')->setTitle('test create content')->setDefaultFolder($folder->getId());
     $contentAction = new Content();
     $contentAction->create($event, null, $this->getMockEventDispatcher());
     $createdContent = $event->getContent();
     $this->assertInstanceOf('Thelia\\Model\\Content', $createdContent);
     $this->assertEquals(1, $createdContent->getVisible());
     $this->assertEquals('test create content', $createdContent->getTitle());
     $this->assertEquals($folder->getId(), $createdContent->getDefaultFolderId());
 }
Пример #2
0
 public function create(ContentCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $content = (new ContentModel())->setDispatcher($dispatcher)->setVisible($event->getVisible())->setLocale($event->getLocale())->setTitle($event->getTitle())->create($event->getDefaultFolder());
     $event->setContent($content);
 }
Пример #3
0
 /**
  * Creates the creation event with the provided form data
  *
  * @param  array                                         $formData
  * @return \Thelia\Core\Event\Content\ContentCreateEvent
  */
 protected function getCreationEvent($formData)
 {
     $contentCreateEvent = new ContentCreateEvent();
     $contentCreateEvent->setLocale($formData['locale'])->setDefaultFolder($formData['default_folder'])->setTitle($formData['title'])->setVisible($formData['visible']);
     return $contentCreateEvent;
 }
Пример #4
0
 public function create(ContentCreateEvent $event)
 {
     $content = new ContentModel();
     $content->setVisible($event->getVisible())->setLocale($event->getLocale())->setTitle($event->getTitle())->create($event->getDefaultFolder());
     $event->setContent($content);
 }
Пример #5
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);
 }