/** * Add a delete entry to the audit log * * @param Events\CategoryEvent $event */ public function onCategoryDelete(Events\CategoryEvent $event) { $category = $event->getCategory(); $log = array("bundle" => "category", "object" => "category", "objectId" => $category->deletedId, "action" => "delete", "details" => array('name' => $category->getTitle()), "ipAddress" => $this->factory->getIpAddressFromRequest()); $this->factory->getModel('core.auditLog')->writeToLog($log); }
/** * {@inheritdoc} * * @param $action * @param $event * @param $entity * @param $isNew * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException */ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null) { if (!$entity instanceof Category) { throw new MethodNotAllowedHttpException(array('Category')); } switch ($action) { case "pre_save": $name = CategoryEvents::CATEGORY_PRE_SAVE; break; case "post_save": $name = CategoryEvents::CATEGORY_POST_SAVE; break; case "pre_delete": $name = CategoryEvents::CATEGORY_PRE_DELETE; break; case "post_delete": $name = CategoryEvents::CATEGORY_POST_DELETE; break; default: return null; } if ($this->dispatcher->hasListeners($name)) { if (empty($event)) { $event = new CategoryEvent($entity, $isNew); $event->setEntityManager($this->em); } $this->dispatcher->dispatch($name, $event); return $event; } else { return null; } }
/** * Add a delete entry to the audit log. * * @param Events\CategoryEvent $event */ public function onCategoryDelete(Events\CategoryEvent $event) { $category = $event->getCategory(); $log = ['bundle' => 'category', 'object' => 'category', 'objectId' => $category->deletedId, 'action' => 'delete', 'details' => ['name' => $category->getTitle()], 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest()]; $this->auditLogModel->writeToLog($log); }