eZ\Publish\Core\Repository\SectionService::updateSection PHP Method

updateSection() public method

Updates the given section in the content repository.
public updateSection ( eZ\Publish\API\Repository\Values\Content\Section $section, eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct $sectionUpdateStruct ) : eZ\Publish\API\Repository\Values\Content\Section
$section eZ\Publish\API\Repository\Values\Content\Section
$sectionUpdateStruct eZ\Publish\API\Repository\Values\Content\SectionUpdateStruct
return eZ\Publish\API\Repository\Values\Content\Section
    public function updateSection(Section $section, SectionUpdateStruct $sectionUpdateStruct)
    {
        if ($sectionUpdateStruct->name !== null && !is_string($sectionUpdateStruct->name)) {
            throw new InvalidArgumentValue('name', $section->name, 'Section');
        }
        if ($sectionUpdateStruct->identifier !== null && !is_string($sectionUpdateStruct->identifier)) {
            throw new InvalidArgumentValue('identifier', $section->identifier, 'Section');
        }
        if ($this->repository->canUser('section', 'edit', $section) !== true) {
            throw new UnauthorizedException('section', 'edit');
        }
        if ($sectionUpdateStruct->identifier !== null) {
            try {
                $existingSection = $this->loadSectionByIdentifier($sectionUpdateStruct->identifier);
                // Allowing identifier update only for the same section
                if ($existingSection->id != $section->id) {
                    throw new InvalidArgumentException('sectionUpdateStruct', 'section with specified identifier already exists');
                }
            } catch (APINotFoundException $e) {
                // Do nothing
            }
        }
        $loadedSection = $this->loadSection($section->id);
        $this->repository->beginTransaction();
        try {
            $spiSection = $this->sectionHandler->update($loadedSection->id, $sectionUpdateStruct->name ?: $loadedSection->name, $sectionUpdateStruct->identifier ?: $loadedSection->identifier);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
        return $this->buildDomainSectionObject($spiSection);
    }