Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

SiteId is not saving correctly #109

Open
leadstar116 opened this issue Apr 2, 2020 · 3 comments
Open

SiteId is not saving correctly #109

leadstar116 opened this issue Apr 2, 2020 · 3 comments

Comments

@leadstar116
Copy link

I have English and Espanol site in Craft CMS version 3.4.12
I add a new redirect and make sure it is for the English site.
When I save the new redirect, it adds it to the Espanol list of redirects but not for English as it should.
If I add a redirect and choose Espanol, it adds it to the English list, but still does not work properly.
Not sure why id is changing.
When I debug in SettingsController/actionSaveRedirect() function, the request param is correct.
And it get correct SiteId.
But after saving $res = Craft::$app->getElements()->saveElement($redirect, true, false);
siteId in elements_sites table changes to different id.
I also noticed that you have afterSave() function in elements/Redirect.php so checked it also.

// remove form other sites Craft::$app->getDb()->createCommand() ->delete('{{%elements_sites}}', [ 'AND', ['elementId' => $record->id], ['!=', 'siteId', $this->siteId] ]) ->execute();

Maybe above code changes some?
Not sure exactly. Hope to hear your idea! Please let me fix things asap.
Thanks.

@leadstar116
Copy link
Author

       $redirect = new Redirect();
        $redirect->id = $request->getBodyParam('redirectId');
        $redirect->sourceUrl = $request->getBodyParam('sourceUrl');
        $redirect->destinationUrl = $request->getBodyParam('destinationUrl');
        $redirect->statusCode = $request->getBodyParam('statusCode');
        $siteId = $request->getBodyParam('siteId');
        if ($siteId == null) {
            $siteId = Craft::$app->getSites()->currentSite->id;
        }

        $redirect->siteId = $siteId;
        $res = Craft::$app->getElements()->saveElement($redirect, true, false);

$redirect->siteId is 1 but when element is saved to 2 in the elements_site table. weird.

@VdVChiel
Copy link

I can second this issue, I have a website in dutch and english and all my redirects are being saved in the english website. When I try to edit and save the redirect to the dutch version I get an 'Integrity constraint violation'

Schermafbeelding 2020-06-23 om 09 41 01

@mateostabio
Copy link

My client just told me about this issue. I am reproducing it:

  • I have English and French site languages.
  • I add a redirect URL on the English side.
  • It saves to the French side.
  • I have to go to the French side and edit the redirect URL
  • Click the site dropdown and select English.
  • Hit save. Now the redirect URL is in the English...

Can we get a fix on this ASAP?
Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants