/** * Delete a category entry * * @param \Thelia\Core\Event\Category\CategoryDeleteEvent $event */ public function delete(CategoryDeleteEvent $event) { if (null !== ($category = CategoryQuery::create()->findPk($event->getCategoryId()))) { $category->setDispatcher($event->getDispatcher())->delete(); $event->setCategory($category); } }
/** * Delete a category entry * * @param \Thelia\Core\Event\Category\CategoryDeleteEvent $event */ public function delete(CategoryDeleteEvent $event) { if (null !== ($category = CategoryQuery::create()->findPk($event->getCategoryId()))) { $con = Propel::getWriteConnection(CategoryTableMap::DATABASE_NAME); $con->beginTransaction(); try { // Get category's files to delete after category deletion $fileList['images']['list'] = CategoryImageQuery::create()->findByCategoryId($event->getCategoryId()); $fileList['images']['type'] = TheliaEvents::IMAGE_DELETE; $fileList['documentList']['list'] = CategoryDocumentQuery::create()->findByCategoryId($event->getCategoryId()); $fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE; // Delete category $category->setDispatcher($event->getDispatcher())->delete($con); $event->setCategory($category); // Dispatch delete category'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; } } }
/** * @depends testUpdate */ public function testDelete(CategoryModel $category) { $event = new CategoryDeleteEvent($category->getId()); $event->setDispatcher($this->getDispatcher()); $action = new Category(); $action->delete($event); $deletedCategory = $event->getCategory(); $this->assertInstanceOf('Thelia\\Model\\Category', $deletedCategory); $this->assertTrue($deletedCategory->isDeleted()); }
/** * @param CategoryDeleteEvent $deleteEvent * @return null|\Symfony\Component\HttpFoundation\Response */ protected function performAdditionalDeleteAction($deleteEvent) { // Redirect to parent category list $category_id = $deleteEvent->getCategory()->getParent(); return $this->redirectToListTemplateWithId($category_id); }
/** * @param mixed $entityId * @return \Symfony\Component\EventDispatcher\Event */ protected function getDeleteEvent($entityId) { $event = new CategoryDeleteEvent($entityId); $event->setCategory(CategoryQuery::create()->findPk($entityId)); return $event; }