public function deleteFileAction($fileId, $parentType, $objectType, $eventName)
    {
        $message = null;

        $this->checkAuth($this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT), array(), AccessManager::UPDATE);
        $this->checkXmlHttpRequest();

        $fileManager = $this->getFileManager();
        $modelInstance = $fileManager->getModelInstance($objectType, $parentType);

        $model = $modelInstance->getQueryInstance()->findPk($fileId);

        if ($model == null) {
            return $this->pageNotFound();
        }

        // Feed event
        $fileDeleteEvent = new FileDeleteEvent($model);

        // Dispatch Event to the Action
        try {
            $this->dispatch($eventName, $fileDeleteEvent);

            $this->adminLogAppend(
                $this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT),
                AccessManager::UPDATE,
                $this->getTranslator()->trans(
                    'Deleting %obj% for %id% with parent id %parentId%',
                    array(
                        '%obj%' => $objectType,
                        '%id%' => $fileDeleteEvent->getFileToDelete()->getId(),
                        '%parentId%' => $fileDeleteEvent->getFileToDelete()->getParentId(),
                    )
                ),
                $fileDeleteEvent->getFileToDelete()->getId()
            );
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans(
                'Fail to delete  %obj% for %id% with parent id %parentId% (Exception : %e%)',
                array(
                    '%obj%' => $objectType,
                    '%id%' => $fileDeleteEvent->getFileToDelete()->getId(),
                    '%parentId%' => $fileDeleteEvent->getFileToDelete()->getParentId(),
                    '%e%' => $e->getMessage()
                )
            );

            $this->adminLogAppend(
                $this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT),
                AccessManager::UPDATE,
                $message,
                $fileDeleteEvent->getFileToDelete()->getId()
            );
        }

        if (null === $message) {
            $message = $this->getTranslator()->trans(
                '%obj%s deleted successfully',
                ['%obj%' => ucfirst($objectType)],
                'image'
            );
        }

        return new Response($message);
    }
public function deleteFileAction($fileId, $parentType, $objectType, $eventName)
    {
        $message = null;

        $this->checkAuth($this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT), array(), AccessManager::UPDATE);
        $this->checkXmlHttpRequest();

        $fileManager = $this->getFileManager();
        $modelInstance = $fileManager->getModelInstance($objectType, $parentType);

        $model = $modelInstance->getQueryInstance()->findPk($fileId);

        if ($model == null) {
            return $this->pageNotFound();
        }

        // Feed event
        $fileDeleteEvent = new FileDeleteEvent($model);

        // Dispatch Event to the Action
        try {
            $this->dispatch($eventName, $fileDeleteEvent);

            $this->adminLogAppend(
                $this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT),
                AccessManager::UPDATE,
                $this->getTranslator()->trans(
                    'Deleting %obj% for %id% with parent id %parentId%',
                    array(
                        '%obj%' => $objectType,
                        '%id%' => $fileDeleteEvent->getFileToDelete()->getId(),
                        '%parentId%' => $fileDeleteEvent->getFileToDelete()->getParentId(),
                    )
                ),
                $fileDeleteEvent->getFileToDelete()->getId()
            );
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans(
                'Fail to delete  %obj% for %id% with parent id %parentId% (Exception : %e%)',
                array(
                    '%obj%' => $objectType,
                    '%id%' => $fileDeleteEvent->getFileToDelete()->getId(),
                    '%parentId%' => $fileDeleteEvent->getFileToDelete()->getParentId(),
                    '%e%' => $e->getMessage()
                )
            );

            $this->adminLogAppend(
                $this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT),
                AccessManager::UPDATE,
                $message,
                $fileDeleteEvent->getFileToDelete()->getId()
            );
        }

        if (null === $message) {
            $message = $this->getTranslator()->trans(
                '%obj%s deleted successfully',
                ['%obj%' => ucfirst($objectType)],
                'image'
            );
        }

        return new Response($message);
    }
public function deleteFileAction ( $ fileId , $ parentType , $ objectType , $ eventName ) { $ message = null ; $ this -> checkAuth ( $ this -> getAdminResources ( ) -> getResource ( $ parentType , static :: MODULE_RIGHT ) , array ( ) , AccessManager :: UPDATE ) ; $ this -> checkXmlHttpRequest ( ) ; $ fileManager = $ this -> getFileManager ( ) ; $ modelInstance = $ fileManager -> getModelInstance ( $ objectType , $ parentType ) ; $ model = $ modelInstance -> getQueryInstance ( ) -> findPk ( $ fileId ) ; if ( $ model == null ) { return $ this -> pageNotFound ( ) ; } // Feed event $ fileDeleteEvent = new FileDeleteEvent ( $ model ) ; // Dispatch Event to the Action try { $ this -> dispatch ( $ eventName , $ fileDeleteEvent ) ; $ this -> adminLogAppend ( $ this -> getAdminResources ( ) -> getResource ( $ parentType , static :: MODULE_RIGHT ) , AccessManager :: UPDATE , $ this -> getTranslator ( ) -> trans ( 'Deleting %obj% for %id% with parent id %parentId%' , array ( '%obj%' => $ objectType , '%id%' => $ fileDeleteEvent -> getFileToDelete ( ) -> getId ( ) , '%parentId%' => $ fileDeleteEvent -> getFileToDelete ( ) -> getParentId ( ) , ) ) , $ fileDeleteEvent -> getFileToDelete ( ) -> getId ( ) ) ; } catch ( \ Exception $ e ) { $ message = $ this -> getTranslator ( ) -> trans ( 'Fail to delete  %obj% for %id% with parent id %parentId% (Exception : %e%)' , array ( '%obj%' => $ objectType , '%id%' => $ fileDeleteEvent -> getFileToDelete ( ) -> getId ( ) , '%parentId%' => $ fileDeleteEvent -> getFileToDelete ( ) -> getParentId ( ) , '%e%' => $ e -> getMessage ( ) ) ) ; $ this -> adminLogAppend ( $ this -> getAdminResources ( ) -> getResource ( $ parentType , static :: MODULE_RIGHT ) , AccessManager :: UPDATE , $ message , $ fileDeleteEvent -> getFileToDelete ( ) -> getId ( ) ) ; } if ( null === $ message ) { $ message = $ this -> getTranslator ( ) -> trans ( '%obj%s deleted successfully' , [ '%obj%' => ucfirst ( $ objectType ) ] , 'image' ) ; } return new Response ( $ message ) ; }
Manage how a file has to be deleted

@param int    $fileId     Parent id owning file being deleted
@param string $parentType Parent Type owning file being deleted
@param string $objectType the type of the file, image or document
@param string $eventName  the event type.

@return Response
Manage how a file has to be deleted