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;
}
}