public function toggleVisibilityFileAction($documentId, $parentType, $objectType, $eventName) { $message = null; //$position = $this->getRequest()->request->get('position'); $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE); $this->checkXmlHttpRequest(); $fileManager = $this->getFileManager(); $modelInstance = $fileManager->getModelInstance($objectType, $parentType); $model = $modelInstance->getQueryInstance()->findPk($documentId); if ($model === null) { return $this->pageNotFound(); } // Feed event $event = new FileToggleVisibilityEvent($modelInstance->getQueryInstance(), $documentId); // Dispatch Event to the Action try { $this->dispatch($eventName, $event); } catch (\Exception $e) { $message = $this->getTranslator()->trans('Fail to update %type% visibility: %err%', ['%type%' => $objectType, '%err%' => $e->getMessage()]); } if (null === $message) { $message = $this->getTranslator()->trans('%type% visibility updated', ['%type%' => ucfirst($objectType)]); } return new Response($message); }
public function deleteImageAction($entityId, $imageId) { $request = $this->getRequest(); $entity = $request->attributes->get('entity'); $this->checkAuth(AdminResources::retrieve($entity), [], AccessManager::UPDATE); $this->checkEntityExists($entity, $entityId); $entityModel = $this->checkImage($entity, $imageId); if (null === $entityModel) { throw new HttpException(404, sprintf('{"error": "image with id %d not found"}', $imageId)); } try { $fileDeleteEvent = new FileDeleteEvent($entityModel); $this->dispatch(TheliaEvents::IMAGE_DELETE, $fileDeleteEvent); return Response::create('', 204); } catch (\Exception $e) { return JsonResponse::create(['error' => $e->getMessage()], 500); } }