Exemplo n.º 1
0
 public function delete(ContentDeleteEvent $event)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getContentId()))) {
         $defaultFolderId = $content->getDefaultFolderId();
         $content->setDispatcher($event->getDispatcher())->delete();
         $event->setDefaultFolderId($defaultFolderId);
         $event->setContent($content);
     }
 }
Exemplo n.º 2
0
 public function testDeleteContent()
 {
     $content = $this->getRandomContent();
     $event = new ContentDeleteEvent($content->getId());
     $event->setDispatcher($this->dispatcher);
     $contentAction = new Content($this->getContainer());
     $contentAction->delete($event);
     $deletedContent = $event->getContent();
     $this->assertInstanceOf('Thelia\\Model\\Content', $deletedContent);
     $this->assertTrue($deletedContent->isDeleted());
 }
Exemplo n.º 3
0
 public function delete(ContentDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getContentId()))) {
         $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $fileList = ['images' => [], 'documentList' => []];
             $defaultFolderId = $content->getDefaultFolderId();
             // Get content's files to delete after content deletion
             $fileList['images']['list'] = ContentImageQuery::create()->findByContentId($event->getContentId());
             $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;
             $fileList['documentList']['list'] = ContentDocumentQuery::create()->findByContentId($event->getContentId());
             $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;
             // Delete content
             $content->setDispatcher($dispatcher)->delete($con);
             $event->setDefaultFolderId($defaultFolderId);
             $event->setContent($content);
             // Dispatch delete content's files event
             foreach ($fileList as $fileTypeList) {
                 foreach ($fileTypeList['list'] as $fileToDelete) {
                     $fileDeleteEvent = new FileDeleteEvent($fileToDelete);
                     $dispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
                 }
             }
             $con->commit();
         } catch (\Exception $e) {
             $con->rollback();
             throw $e;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Put in this method post object delete processing if required.
  *
  * @param  \Thelia\Core\Event\Content\ContentDeleteEvent $deleteEvent the delete event
  * @return Response                                      a response, or null to continue normal processing
  */
 protected function performAdditionalDeleteAction($deleteEvent)
 {
     return $this->generateRedirectFromRoute('admin.folders.default', ['parent' => $deleteEvent->getDefaultFolderId()]);
 }