Example #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);
     }
 }
Example #2
0
 public function delete(ContentDeleteEvent $event)
 {
     if (null !== ($content = ContentQuery::create()->findPk($event->getContentId()))) {
         $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             $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($event->getDispatcher())->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);
                     $event->getDispatcher()->dispatch($fileTypeList['type'], $fileDeleteEvent);
                 }
             }
             $con->commit();
         } catch (\Exception $e) {
             $con->rollback();
             throw $e;
         }
     }
 }