/** * Deletes $section from content repository. * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified section is not found * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete a section * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If section can not be deleted * because it is still assigned to some contents, * or because it is still being used in policy limitations. * * @param \eZ\Publish\API\Repository\Values\Content\Section $section */ public function deleteSection(Section $section) { $loadedSection = $this->loadSection($section->id); if ($this->repository->canUser('section', 'edit', $loadedSection) !== true) { throw new UnauthorizedException('section', 'edit', array('sectionId' => $loadedSection->id)); } if ($this->sectionHandler->assignmentsCount($loadedSection->id) > 0) { throw new BadStateException('section', 'section is still assigned to content'); } if ($this->sectionHandler->policiesCount($loadedSection->id) > 0) { throw new BadStateException('section', 'section is still being used in policy limitations'); } $this->repository->beginTransaction(); try { $this->sectionHandler->delete($loadedSection->id); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } }
/** * Counts the contents which $section is assigned to * * @param \eZ\Publish\API\Repository\Values\Content\Section $section * * @return int */ public function countAssignedContents(Section $section) { return $this->sectionHandler->assignmentsCount($section->id); }