public function delete(FolderDeleteEvent $event) { if (null !== ($folder = FolderQuery::create()->findPk($event->getFolderId()))) { $folder->setDispatcher($event->getDispatcher())->delete(); $event->setFolder($folder); } }
public function delete(FolderDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher) { if (null !== ($folder = FolderQuery::create()->findPk($event->getFolderId()))) { $con = Propel::getWriteConnection(FolderTableMap::DATABASE_NAME); $con->beginTransaction(); try { $fileList = ['images' => [], 'documentList' => []]; // Get folder's files to delete after folder deletion $fileList['images']['list'] = FolderImageQuery::create()->findByFolderId($event->getFolderId()); $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE; $fileList['documentList']['list'] = FolderDocumentQuery::create()->findByFolderId($event->getFolderId()); $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE; // Delete folder $folder->setDispatcher($dispatcher)->delete($con); $event->setFolder($folder); // Dispatch delete folder'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; } } }
/** * test folder removal * @covers Thelia\Action\Folder::delete */ public function testDeleteFolder() { $folder = $this->getRandomFolder(); $event = new FolderDeleteEvent($folder->getId()); $event->setDispatcher($this->dispatcher); $folderAction = new Folder(); $folderAction->delete($event); $deletedFolder = $event->getFolder(); $this->assertInstanceOf('Thelia\\Model\\Folder', $deletedFolder); $this->assertTrue($deletedFolder->isDeleted()); }
/** * Put in this method post object delete processing if required. * * @param \Thelia\Core\Event\Folder\FolderDeleteEvent $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->getFolder()->getParent()]); }