craft-plugin-redirect
craft-plugin-redirect copied to clipboard
SiteId is not saving correctly
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.
$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.
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'
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!