/** * Check that a slug can be updated for a page and update if so * * @param Page $page * @param Slug $slug */ public function updateSlug(Page $page, Slug $slug) { if ($slug->getFull() === $page->slug->getFull()) { return; } $newSlug = $slug->getLastSegment(); $slugSegments = $page->slug->getSegments(); array_pop($slugSegments); $slugSegments[] = $newSlug; $slug = '/' . implode('/', $slugSegments); $this->_checkRoute($slug); $this->_checkSlugExists($page, $slug); // If the slug has changed then update the slug $this->_pageEdit->removeHistoricalSlug($slug); try { $this->_pageEdit->updateSlug($page, $newSlug); } catch (Exception\InvalidSlugException $e) { throw new Exception\SlugUpdateException($e->getMessage(), 'ms.cms.feedback.force-slug.failure.generic', ['%message%' => $e->getMessage()]); } }
public function testGetLastSegment() { $fullSlug = '/secret/place/in/the/website'; $slug = new Slug($fullSlug); $this->assertSame($slug->getLastSegment(), 'website'); }