<commit_before><?php

namespace BoomCMS\Http\Controllers\CMS\Page\Urls;

use BoomCMS\Jobs\MakeURLPrimary;
use BoomCMS\Support\Facades\URL;
use Illuminate\Support\Facades\Bus;

class Save extends BaseController
{
    public function add()
    {
        $location = $this->request->input('location');
        $this->url = URL::findByLocation($location);

        if ($this->url->loaded() && !$this->url->isForPage($this->page)) {
            // Url is being used for a different page.
            // Notify that the url is already in use so that the JS can load a prompt to move the url.
            return ['existing_url_id' => $this->url->getId()];
        } elseif (!$this->url->loaded()) {
            URL::create($location, $this->page->getId());
        }
    }

    public function delete()
    {
        if (!$this->url->isPrimary()) {
            URL::delete($this->url);
        }
    }

    public function makePrimary()
    {
        Bus::dispatch(new MakeURLPrimary($this->url));
    }

    public function move()
    {
        $this->url
            ->setPageId($this->page->getId())
            ->setIsPrimary(false);

        $this->provider->save($this->url);
    }<commit_msg>Fixed bug in URL save controller<commit_after><?php

namespace BoomCMS\Http\Controllers\CMS\Page\Urls;

use BoomCMS\Jobs\MakeURLPrimary;
use BoomCMS\Support\Facades\URL;
use Illuminate\Support\Facades\Bus;

class Save extends BaseController
{
    public function add()
    {
        $location = $this->request->input('location');
        $this->url = URL::findByLocation($location);

        if ($this->url->loaded() && !$this->url->isForPage($this->page)) {
            // Url is being used for a different page.
            // Notify that the url is already in use so that the JS can load a prompt to move the url.
            return ['existing_url_id' => $this->url->getId()];
        } elseif (!$this->url->loaded()) {
            URL::create($location, $this->page->getId());
        }
    }

    public function delete()
    {
        if (!$this->url->isPrimary()) {
            URL::delete($this->url);
        }
    }

    public function makePrimary()
    {
        Bus::dispatch(new MakeURLPrimary($this->url));
    }

    public function move()
    {
        $this->url
            ->setPageId($this->page->getId())
            ->setIsPrimary(false);

        URL::save($this->url);
    }
{'fraction_non_alphanumeric': 0.15851108322877458, 'fraction_numerical': 0.0, 'mean_word_length': 2.2947658402203857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930083', 'n_tokens_mistral': 715, 'n_tokens_neox': 715, 'n_words': 157}