Exemplo n.º 1
0
 public function update(FolderUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($folder = FolderQuery::create()->findPk($event->getFolderId()))) {
         $folder->setDispatcher($dispatcher);
         $folder->setParent($event->getParent())->setVisible($event->getVisible())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save();
         $event->setFolder($folder);
     }
 }
Exemplo n.º 2
0
 /**
  * @param  \Thelia\Core\Event\Folder\FolderUpdateEvent $updateEvent
  * @return Response|void
  */
 protected function performAdditionalUpdateAction($updateEvent)
 {
     if ($this->getRequest()->get('save_mode') != 'stay') {
         return $this->generateRedirectFromRoute('admin.folders.default', ['parent' => $updateEvent->getFolder()->getParent()]);
     } else {
         return null;
     }
 }
Exemplo n.º 3
0
 /**
  * test update creation
  * @covers Thelia\Action\Folder::update
  */
 public function testUpdateFolder()
 {
     $folder = $this->getRandomFolder();
     $visible = !$folder->getVisible();
     $event = new FolderUpdateEvent($folder->getId());
     $event->setDispatcher($this->dispatcher);
     $event->setLocale('en_US')->setTitle('test update folder')->setVisible($visible)->setChapo('test folder update chapo')->setDescription('update folder description')->setPostscriptum('update folder postscriptum')->setParent(0);
     $folderAction = new Folder();
     $folderAction->update($event);
     $updatedFolder = $event->getFolder();
     $this->assertInstanceOf('Thelia\\Model\\Folder', $updatedFolder);
     $this->assertEquals('test update folder', $updatedFolder->getTitle());
     $this->assertEquals('test folder update chapo', $updatedFolder->getChapo());
     $this->assertEquals('update folder description', $updatedFolder->getDescription());
     $this->assertEquals('update folder postscriptum', $updatedFolder->getPostscriptum());
     $this->assertEquals(0, $updatedFolder->getParent());
     $this->assertEquals($visible, $updatedFolder->getVisible());
 }
Exemplo n.º 4
0
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from dossier order by parent asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     $image_import = new FolderImageImport($this->dispatcher, $this->t1db);
     $document_import = new FolderDocumentImport($this->dispatcher, $this->t1db);
     while ($hdl && ($dossier = $this->t1db->fetch_object($hdl))) {
         Tlog::getInstance()->info("Processing T1 folder ID {$dossier->id}, parent: {$dossier->parent}.");
         $count++;
         try {
             $this->fld_corresp->getT2($dossier->id);
             Tlog::getInstance()->warning("Folder ID={$dossier->id} already imported.");
             continue;
         } catch (ImportException $ex) {
             // Okay, the dossier was not imported.
         }
         try {
             $event = new FolderCreateEvent();
             $idx = 0;
             $descs = $this->t1db->query_list("select * from dossierdesc where dossier = ? order by lang asc", array($dossier->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());
                 }
                 $parent = $dossier->parent > 0 ? $dossier->parent + 1000000 : 0;
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($objdesc->titre)->setParent($parent)->setVisible($dossier->ligne == 1 ? true : false);
                     $this->dispatcher->dispatch(TheliaEvents::FOLDER_CREATE, $event);
                     $folder_id = $event->getFolder()->getId();
                     Tlog::getInstance()->info("Created folder {$folder_id} from {$objdesc->titre} ({$dossier->id})");
                     // Update position
                     $update_position_event = new UpdatePositionEvent($folder_id, UpdatePositionEvent::POSITION_ABSOLUTE, $dossier->classement);
                     $this->dispatcher->dispatch(TheliaEvents::FOLDER_UPDATE_POSITION, $update_position_event);
                     $this->fld_corresp->addEntry($dossier->id, $folder_id);
                     // Import images and documents
                     // ---------------------------
                     $image_import->importMedia($dossier->id, $folder_id);
                     $document_import->importMedia($dossier->id, $folder_id);
                 }
                 // Update the newly created folder
                 $update_event = new FolderUpdateEvent($folder_id);
                 $update_event->setTitle($objdesc->titre)->setParent($parent)->setLocale($lang->getLocale())->setVisible($dossier->ligne == 1 ? true : false)->setChapo($objdesc->chapo)->setDescription($objdesc->description)->setPostscriptum($objdesc->postscriptum);
                 $this->dispatcher->dispatch(TheliaEvents::FOLDER_UPDATE, $update_event);
                 // Update the rewritten URL, if one was defined
                 $this->updateRewrittenUrl($event->getFolder(), $lang->getLocale(), $objdesc->lang, "dossier", "%id_dossier={$dossier->id}");
                 $idx++;
             }
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError("Failed to import folder ID={$dossier->id}: ", $ex->getMessage());
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }