Dolphiq / craft-plugin-redirect

Craft 3 redirect plugin provides an easy way to enter and maintain 301 and 302 redirects and 404 pages. The plugin provides a clear user interface for admin and non-admin users.
MIT License
54 stars 34 forks source link

New redirects always save with highest ID site #100

Closed lmaucoin closed 5 years ago

lmaucoin commented 5 years ago

Hi, love the plugin! However, I recently upgraded to Craft 3.2.7 and have found that redirects are no longer saving on the correct sites.

I did some sleuthing and found that though the $propagate parameter is set to false when saving the redirect, this only stops it from being saved to all sites if the record exists (see Arguments here).

To get around this, in the afterSave callback, all element records created for sites that aren't the relevant one are deleted. Unfortunately, this is run every time a record is saved (and it always gets saved for all sites when a new record is created), meaning that the only lingering redirect record is one on the highest site ID.

This PR shifts the record deletion to occur in the Controller's action for saving instead of in a post-save callback, so it's only executed for the record on the relevant site.

janmeeus commented 5 years ago

Hi, I tried your solutions and it seems to work on first save of a redirect. However, when I try to edit and re-save an existing redirect, I get an error:

Schermafbeelding 2019-09-05 om 17 06 17
lmaucoin commented 5 years ago

@janmeeus Thanks for finding that! I can have a look into this soon.

In the meantime, another fork of this repo at https://github.com/nyby/craft3-plugin-redirect by @nyby seems to address this same issue ... probably more eloquently.

janmeeus commented 5 years ago

@johanzandstra Thanks for the fix. When are you planning to make a new release with these adjustments?

EFWall commented 5 years ago

@johanzandstra yes, also wondering when a new release with be posted to correct these issues. We are currently unable to save any redirects. Can you advise?

tarmooo commented 5 years ago

Waiting for it too

emilyfitton commented 4 years ago

+1 for this one please. @johanzandstra

janmeeus commented 4 years ago

@johanzandstra Thanks for the fix. When are you planning to make a new release with these adjustments?

martindffrnt commented 4 years ago

@johanzandstra I am running into the same issue, when is this being released? I see the last release was a year ago April, is this code still being maintained and when is the next release?