Example #1
0
 /**
  * Soft or hard delete a section.
  *
  * @param Wiki         $wiki
  * @param Section      $section
  * @param ParamFetcher $paramFetcher
  *
  * @return mixed[]
  *
  * @Route(
  *     requirements={ "wiki" = "\d+", "section" = "\d+" }
  * )
  * @QueryParam(
  *     name="withChildren",
  *     requirements="(true|false)",
  *     nullable=true,
  *     description="Should the section be soft deleted with its children ?"
  * )
  */
 public function deleteWikiSectionAction(Wiki $wiki, Section $section, ParamFetcher $paramFetcher)
 {
     if (!$section->getDeleted()) {
         // Soft delete
         $repo = $this->get('icap.wiki.section_repository');
         $withChildren = $paramFetcher->get('withChildren') === 'true';
         if ($withChildren) {
             $repo->deleteSubtree($section);
         } else {
             $repo->deleteFromTree($section);
         }
         $this->dispatchSectionDeleteEvent($wiki, $section);
         $this->dispatchSectionDeleteEvent($wiki, $section);
     } else {
         $this->checkAccess('EDIT', $wiki);
         // Hard delete
         $em = $this->getDoctrine()->getManager();
         $em->remove($section);
         $em->flush();
         $this->dispatchSectionRemoveEvent($wiki, $section);
     }
     $isAdmin = $this->isUserGranted('EDIT', $wiki);
     return ['sections' => $repo->buildSectionTree($wiki, $isAdmin, $this->getLoggedUser()), 'deletedSections' => $repo->findDeletedSections($wiki)];
 }