public function handle() { DB::table('page_urls')->where('page_id', '=', $this->url->getPageId())->where('id', '!=', $this->url->getId())->where('is_primary', '=', true)->update(['is_primary' => false]); $this->url->setPrimary(true); URLFacade::save($this->url); DB::table('pages')->where('id', '=', $this->url->getPageId())->update(['primary_uri' => $this->url->getLocation()]); }
/** * @param string $uri * * @return mixed */ public function process($uri) { $this->page = Page::findByUri($uri); if (!$this->page) { $url = URL::findByLocation($uri); // The URL isn't in use or // The URL is in use and has a page - the page must not be visible to the current user // // 404. if (!$url || !$url->getPage()->isVisible()) { throw new NotFoundHttpException(); } // The url is in use but doesn't have a page. // The page must have been deleted. // // 410. throw new GoneHttpException(); } if (Editor::isDisabled() && !$this->page->isVisible()) { throw new NotFoundHttpException(); } if (!$this->page->url()->is($uri)) { return redirect((string) $this->page->url(), 301); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $uri = $request->route()->getParameter('location'); $page = Page::findByUri($uri); if (!$page) { $url = URL::findByLocation($uri); // The URL isn't in use or // The URL is in use and has a page - the page must not be visible to the current user // // 404. if (!$url || !$url->getPage()->isVisible()) { throw new NotFoundHttpException(); } // The url is in use but doesn't have a page. // The page must have been deleted. // // 410. throw new GoneHttpException(); } if (Editor::isDisabled() && !$page->isVisible()) { throw new NotFoundHttpException(); } if (!$page->url()->is($uri)) { return redirect((string) $page->url(), 301); } $request->route()->setParameter('page', $page); Editor::setActivePage($page); View::share('page', $page); return $next($request); }
public function destroy(Page $page, URL $url) { $this->auth($page); if (!$url->isPrimary()) { URLFacade::delete($url); } }
public function handle() { $url = $this->location !== null ? $this->location : URLHelper::fromTitle($this->page->getSite(), $this->prefix, $this->page->getTitle()); $url = URLFacade::create($url, $this->page, true); Bus::dispatch(new MakeURLPrimary($url)); return $url; }
public function testHandle() { $page = $this->validPage(); $url = m::mock(URL::class); $url->shouldReceive('setPageId')->with($page->getId())->andReturnSelf(); $url->shouldReceive('setIsPrimary')->with(false)->andReturnSelf(); URLFacade::shouldReceive('save')->with($url); }
/** * @param string $path * * @return mixed */ public function routePage($path) { $url = URL::findByLocation($path); if ($url) { $page = $url->getPage(); if (!$page) { // The url is in use but doesn't have a page. // The page must have been deleted. throw new GoneHttpException(); } if (Editor::isDisabled() && !$page->isVisible()) { throw new NotFoundHttpException(); } if (!$page->url()->matches($path)) { return redirect((string) $page->url(), 301); } $this->setActivePage($page); return; } throw new NotFoundHttpException(); }
public function handle() { $this->url->setPageId($this->page->getId())->setIsPrimary(false); URLFacade::save($this->url); }
public function postDelete() { if (!$this->url->isPrimary()) { URL::delete($this->url); } }
/** * Set the title of the page. * * @param Request $request * @param Page $page * * @return array */ public function postTitle(Request $request, Page $page) { $this->authorize('edit', $page); $oldTitle = $page->getTitle(); $page->setTitle($request->input('title')); Event::fire(new Events\PageTitleWasChanged($page, $oldTitle, $page->getTitle())); return ['status' => $page->getCurrentVersion()->getStatus(), 'location' => (string) URLFacade::page($page)]; }
/** * Increments a numeric suffix until the URL is unique. * * @param string $url * * @return string */ public static function makeUnique($url) { return Str::unique($url, function ($url) { return URLFacade::isAvailable($url); }); }