예제 #1
0
 /**
  * Check that a no page exists with this slug in its history
  *
  * @param Page $page
  * @param $slug
  * @throws \InvalidArgumentException        Throws exception if $slug is not a string
  * @throws Exception\SlugUpdateException    Throws exception if page exists with slug matching that given
  *                                          in $slug in its slug history
  */
 private function _checkSlugHistory(Page $page, $slug)
 {
     if (!is_string($slug)) {
         throw new \InvalidArgumentException('Slug must be a string, ' . gettype($slug) . ' given');
     }
     // Check for the slug historically and show deleted ones too
     $historicalSlug = $this->_pageLoader->getBySlug($slug, true);
     // If there is a page returned and it's not this page then offer
     // a link to remove the slug from history and use it anyway
     if ($historicalSlug && $historicalSlug->id != $page->id) {
         $slugParts = explode('/', $slug);
         $newSlug = array_pop($slugParts);
         throw new Exception\SlugUpdateException('Slug `' . $slug . '` has been used previously and is redirecting to page ' . $historicalSlug->id, 'ms.cms.feedback.force-slug.failure.redirected', ['%slug%' => $slug, '%redirectedUrl%' => $this->_urlGenerator->generate('ms.cp.cms.edit.attributes', ['pageID' => $historicalSlug->id]), '%redirectedTitle%' => $historicalSlug->title, '%forceUrl%' => $this->_urlGenerator->generate('ms.cp.cms.edit.attributes.slug.force', ['pageID' => $page->id, 'slug' => $newSlug])]);
     }
 }