@param Request $request
@param int     $folderId

@Route("/delete/{folderId}", requirements={"folderId" = "\d+"}, name="KunstmaanMediaBundle_folder_delete")

@return RedirectResponse
437925
public function deleteAction(Request $request, $folderId)
    {
        /** @var EntityManager $em */
        $em = $this->getDoctrine()->getManager();

        /* @var Folder $folder */
        $folder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($folderId);
        $folderName = $folder->getName();
        $parentFolder = $folder->getParent();

        if (is_null($parentFolder)) {
            $this->addFlash(
                FlashTypes::ERROR,
                $this->get('translator')->trans('media.folder.delete.failure.text', array(
                    '%folder%' => $folderName,
                ))
            );
        } else {
            $em->getRepository('KunstmaanMediaBundle:Folder')->delete($folder);
            $this->addFlash(
                FlashTypes::SUCCESS,
                $this->get('translator')->trans('media.folder.delete.success.text', array(
                    '%folder%' => $folderName,
                ))
            );
            $folderId = $parentFolder->getId();
        }
        if (strpos($request->server->get('HTTP_REFERER', ''), 'chooser')) {
            $redirect = 'KunstmaanMediaBundle_chooser_show_folder';
        } else {
            $redirect = 'KunstmaanMediaBundle_folder_show';
        }

        $type = $this->get('request_stack')->getCurrentRequest()->get('type');

        return new RedirectResponse(
            $this->generateUrl($redirect,
                array(
                    'folderId' => $folderId,
                    'type' => $type,
                )
            )
        );
    }
1288201
public function chooserIndexAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $session = $request->getSession();
        $folderId = false;

        $type = $request->get('type', 'all');
        $cKEditorFuncNum = $request->get('CKEditorFuncNum');
        $linkChooser = $request->get('linkChooser');

        // Go to the last visited folder
        if ($session->get('last-media-folder')) {
            try {
                $em->getRepository('KunstmaanMediaBundle:Folder')->getFolder($session->get('last-media-folder'));
                $folderId = $session->get('last-media-folder');
            } catch (EntityNotFoundException $e) {
                $folderId = false;
            }
        }

        if (!$folderId) {
            // Redirect to the first top folder
            /* @var Folder $firstFolder */
            $firstFolder = $em->getRepository('KunstmaanMediaBundle:Folder')->getFirstTopFolder();
            $folderId = $firstFolder->getId();
        }

        $params = array(
            'folderId' => $folderId,
            'type' => $type,
            'CKEditorFuncNum' => $cKEditorFuncNum,
            'linkChooser' => $linkChooser,
        );

        return $this->redirect($this->generateUrl('KunstmaanMediaBundle_chooser_show_folder', $params));
    }
1316398
public function cdeleteAction(Request $request)
    {
        $repository = $this->getRedirectRouteRepository();
        $manager = $this->getRedirectRouteManager();

        $ids = array_filter(explode(',', $request->query->get('ids', '')));
        foreach ($ids as $id) {
            $redirectRoute = $repository->find($id);
            if (!$redirectRoute) {
                continue;
            }

            $manager->delete($redirectRoute);
        }

        $this->get('doctrine.orm.entity_manager')->flush();

        return $this->handleView($this->view());
    }
1216354
public function delete(Request $request)
    {
        $json = [];

        if ($request->get('directory')) {
            $this->storage->deleteDirectory($request->get('directory'));
            Image::deleteDirectory($this->path . $request->get('directory'));
            $json['success'] = trans('admin::image.success.delete');
        } elseif ($request->get('file')) {
            $this->storage->delete($request->get('file'));
            Image::delete($this->path . $request->get('file'));
            $json['success'] = trans('admin::image.success.delete');
        } else {
            $json['error'] = trans('admin::image.error.delete');
        }

        return response()
            ->json($json);
    }
1134913
public function delete_file_folder(Request $request)
    {
        $folderLocation = $request->folder_location;
        $fileFolder = $request->file_folder;
        $type = $request->type;
        $success = true;
        $error = '';

        if (is_array($folderLocation)) {
            $folderLocation = rtrim(implode('/', $folderLocation), '/');
        }

        $location = "{$this->directory}/{$folderLocation}";
        $fileFolder = "{$location}/{$fileFolder}";

        if ($type == 'folder') {
            if (!Storage::disk($this->filesystem)->deleteDirectory($fileFolder)) {
                $error = __('admin.media.error_deleting_folder');
                $success = false;
            }
        } elseif (!Storage::disk($this->filesystem)->delete($fileFolder)) {
            $error = __('admin.media.error_deleting_file');
            $success = false;
        }

        return compact('success', 'error');
    }
1144085
public function deleteAction(Request $request, $ticketId)
    {
        $userManager = $this->getUserManager();
        $user        = $userManager->getCurrentUser();

        if (!\is_object($user) || !$userManager->hasRole($user, TicketRole::ADMIN)) {
            throw new \Symfony\Component\HttpKernel\Exception\HttpException(403);
        }

        $form = $this->createDeleteForm($ticketId);

        if ($request->isMethod('DELETE')) {
            $form->submit($request->request->get($form->getName()));

            if ($form->isValid()) {
                $ticketManager = $this->get('hackzilla_ticket.ticket_manager');
                $ticket        = $ticketManager->getTicketById($ticketId);

                if (!$ticket) {
                    throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], 'HackzillaTicketBundle'));
                }

                $ticketManager->deleteTicket($ticket);
                $this->dispatchTicketEvent(TicketEvents::TICKET_DELETE, $ticket);
            }
        }

        return $this->redirect($this->generateUrl('hackzilla_ticket'));
    }
1257125
public function cleanDataAction(ServerRequestInterface $request, FilesystemInterface $filesystem): ResponseInterface
    {
        $to_delete = (array) $request->get('to_delete');
        $to_delete = array_filter($to_delete);

        foreach ($to_delete as $path) {
            $metadata = $filesystem->getMetadata($path);

            if ($metadata === false) {
                // Already deleted?
                continue;
            }

            if ($metadata['type'] === 'dir') {
                try {
                    $filesystem->deleteDir($path);

                    FlashMessages::addMessage(I18N::translate('The folder %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The folder %s could not be deleted.', e($path)), 'danger');
                }
            }

            if ($metadata['type'] === 'file') {
                try {
                    $filesystem->delete($path);

                    FlashMessages::addMessage(I18N::translate('The file %s has been deleted.', e($path)), 'success');
                } catch (Exception $ex) {
                    FlashMessages::addMessage(I18N::translate('The file %s could not be deleted.', e($path)), 'danger');
                }
            }
        }

        return redirect(route('admin-clean-data'));
    }
544322
public function mediaTypeListAction($folderId)
    {
        /** @var FolderInterface $folder */
        $folder = $this->get('open_orchestra_media.repository.media_folder')->find($folderId);
        $this->denyAccessUnlessGranted(ContributionActionInterface::READ, $folder);

        $mediaCollection = $this->get('open_orchestra_media.repository.media')->findByFolderId($folderId);

        return $this->get('open_orchestra_api.transformer_manager')
            ->transform('media_type_collection', $mediaCollection, $folderId);
    }
571822
public function uploadAction($folderId, Request $request)
    {
        $uploadedFile = $request->files->get('file');
        $title = $request->get('title');

        $saveMediaManager = $this->get('open_orchestra_media_admin.manager.save_media');

        if ($uploadedFile && $uploadedFile = $saveMediaManager->getFileFromChunks($uploadedFile)) {
            $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
            $media = $saveMediaManager->initializeMediaFromUploadedFile($uploadedFile, $folderId, $siteId, $title);
            $violations = $this->get('validator')->validate($media, null, array('upload'));
            if (count($violations) !== 0) {
                return new Response(
                    implode('.', $this->getViolationsMessage($violations)),
                    403
                );
            }

            $saveMediaManager->saveMedia($media);

            return $this->get('open_orchestra_api.transformer_manager')->transform('media', $media);

        }

        return new Response('', 202);
    }
514595
public function deleteAction(Request $request)
    {
        $treeIds = $request->get('id');
        if (!is_array($treeIds)) {
            $treeIds = [$treeIds];
        }

        $treeManager = $this->get('phlexible_tree.tree_manager');

        foreach ($treeIds as $treeId) {
            $tree = $treeManager->getByNodeId($treeId);
            $node = $tree->get($treeId);

            $tree->delete($node, $this->getUser()->getId());
        }

        return new ResultResponse(true, 'Item(s) deleted');
    }
458382
protected function deleteDirectory(Request $request)
    {
        try {
            $dir = $request->input('s');
            Storage::deleteDirectory($dir);

            return $this->notifySuccess($dir . ' successfully deleted!');
        } catch (\ErrorException $e) {
            return $this->notifyError($e->getMessage());
        }
    }
1327567
public function batchDeleteAction(Request $request)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        $this->getParentEntityDefinition($request);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $form = $this->getAdminFormFactory()->createBatchDeleteForm($this->entityClass)->handleRequest($request);
        $entities = $form->get('entities')->getData();

        if ($entities instanceof Collection) {
            $entities = $entities->toArray();
        }
        if (empty($entities)) {
            throw new ControllerException(
                sprintf('Unable to handle batch delete form for entity class "%s": entity array is empty.', $this->entityClass)
            );
        }
        if ($this->getFormHandler()->handleBatchDeleteForm($form, $entities)) {
            $eventDispatcher = $this->getEventDispatcher();
            $user            = $this->getUser();

            foreach ($entities as $entity) {
                $eventDispatcher->dispatch(CrudEvents::DELETED, new DeletedEvent($user, $entity));
            }

            return $this->redirect($this->getAdminRouter()->generate(reset($entities), $this->entityClass, AdminRouter::TYPE_INDEX));
        }

        $url = $request->headers->get(
            'referer',
            $this->getAdminRouter()->generate(reset($entities), $this->entityClass, AdminRouter::TYPE_INDEX)
        );

        return $this->redirect($url);
    }
34520
public function directoryAction(Request $request)
    {
        $id = $request->query->get('id');

        $parent = null;
        if (intval($id)) {
            $em = $this->getDoctrine()->getManager();

            $parent = $em->getReference('ClasticMediaBundle:Directory', $id);
        }

        $directories = $this->getDoctrine()->getRepository('ClasticMediaBundle:Directory')
            ->findBy(array(
                'parent' => $parent,
            ));

        $data = array_map(function (Directory $directory) use ($parent) {
            return array(
                'id' => $directory->getId(),
                'text' => $directory->getName(),
                'children' => true,
                'state' => array(
                    'disabled' => false,
                    'opened' => !$parent,
                    'selected' => !$parent,
                ),
            );
        }, $directories);

        return new JsonResponse($data);
    }
342976
public function moveAction(Request $request)
    {
        $volumeId = $request->get('site_id');
        $targetId = $request->get('target_id');
        $sourceId = $request->get('source_id');

        $volume = $this->getVolume($volumeId);
        $folder = $volume->findFolder($sourceId);
        $targetFolder = $volume->findFolder($targetId);

        $volume->moveFolder($folder, $targetFolder, $this->getUser()->getId());

        return new ResultResponse(true);
    }
1065238
public function deleteAction($id, Request $request)
    {
        $data = $this->resolveData($id);
        $title = $this->resolveDataTitle($data);

        $breadcrumbs = $this->buildBreadcrumbs($this->getType());
        $breadcrumbs->addItem(sprintf('Delete "%s"', $this->resolveDataTitle($data)));

        $form = $this->createForm(DeleteFormType::class, array(
            'id' => $data->getId(),
            'title' => $title,
        ));

        $form->handleRequest($request);

        if ($form->isValid()) {
            if ($form->get('tabs')->get('actions')->get('delete')->isClicked()) {
                $manager = $this->getDoctrine()->getManager();
                $manager->remove($data);
                $manager->flush();

                $request->getSession()
                    ->getFlashBag()
                    ->add('success', sprintf('You deleted "%s"!', $title));
            }

            if ($request->query->has('_return')) {
                $redirectUrl = $this->generateUrl($request->query->get('_return'));
            } else {
                $redirectUrl = $this->getListUrl();
            }

            return $this->redirect($redirectUrl);
        }

        $module = $this->getModule($this->getType());

        return $this->render('ClasticNodeBundle:Backoffice/Node:form.html.twig', array(
            'page_title' => sprintf('Delete "%s"?', $title),
            'form' => $form->createView(),
            'module' => $module,
            'submodules' => $this->getSubmodules($module),
        ));
    }
1113110
public function renameAction(Request $request)
    {
        $volumeId = $request->get('site_id');
        $folderId = $request->get('folder_id');
        $folderName = $request->get('folder_name');

        $volume = $this->getVolume($volumeId);
        $folder = $volume->findFolder($folderId);

        $volume->renameFolder($folder, $folderName, $this->getUser()->getId());

        return new ResultResponse(true, 'Folder renamed.', [
            'folder_name' => $folderName,
        ]);
    }
278658
public function deleteFolders($container, $folders, $root = '', $force = false)
    {
        $root = FileUtilities::fixFolderPath($root);
        foreach ($folders as $key => $folder) {
            try {
                // path is full path, name is relative to root, take either
                $path = array_get($folder, 'path');
                $name = array_get($folder, 'name');
                if (!empty($path)) {
                    $path = static::removeContainerFromPath($container, $path);
                } elseif (!empty($name)) {
                    $path = $root . $folder['name'];
                } else {
                    throw new BadRequestException('No path or name found for folder in delete request.');
                }
                if (!empty($path)) {
                    $this->deleteFolder($container, $path, $force);
                } else {
                    throw new BadRequestException('No path or name found for folder in delete request.');
                }
            } catch (\Exception $ex) {
                // error whole batch here?
                $folders[$key]['error'] = ['message' => $ex->getMessage(), 'code' => $ex->getCode()];
            }
        }

        return $folders;
    }