lunar icon indicating copy to clipboard operation
lunar copied to clipboard

Force Media RM to always have 1 primary record

Open wychoong opened this issue 1 year ago • 8 comments

to always ensure 1 record is primary

  • if current record is primary, unset others
  • if current is not primary, set other as primary
  • if no other record is primary, current will be primary
  • after delete, if no primary record, set other as primary

wychoong avatar Jun 21 '24 05:06 wychoong

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2024 7:38am

vercel[bot] avatar Jun 21 '24 05:06 vercel[bot]

Just thinking, would this sort of thing be better off in an observer/listener, since media can be changed without the panel this code will never fire.

alecritson avatar Jun 24 '24 10:06 alecritson

Just thinking, would this sort of thing be better off in an observer/listener, since media can be changed without the panel this code will never fire.

That is very true, and I have considered that. But why I didn’t implement as observer is because of bulk delete, it will trigger for all.

I can implement as observer to be inline with default flag as other model.

wychoong avatar Jun 24 '24 12:06 wychoong

Yeah we have something similar here https://github.com/lunarphp/lunar/blob/1.x/packages/core/src/Observers/UrlObserver.php if that was what you was referring to?

alecritson avatar Jun 25 '24 07:06 alecritson

Yeah we have something similar here https://github.com/lunarphp/lunar/blob/1.x/packages/core/src/Observers/UrlObserver.php if that was what you was referring to?

Yup

wychoong avatar Jun 25 '24 07:06 wychoong

@alecritson I've updated the implementation to use observer

wychoong avatar Jun 25 '24 11:06 wychoong

Thanks @wychoong it would be good to have a few test assertions for this as it's quite complex

alecritson avatar Jul 02 '24 08:07 alecritson

Thanks @wychoong it would be good to have a few test assertions for this as it's quite complex

Added the test.

should the observer apply to: a. all collections b. or only the one configured in config('lunar.media.collection') c. or all collections only if the media is with custom_properties.primary = true

wychoong avatar Jul 02 '24 15:07 wychoong

Thanks @wychoong it would be good to have a few test assertions for this as it's quite complex

Added the test.

should the observer apply to: a. all collections b. or only the one configured in config('lunar.media.collection') c. or all collections only if the media is with custom_properties.primary = true

Appreciate this @wychoong . I made a few tweaks, just to clean up tests a little and remove the need for an actual image in the filesystem. I also got rid of the nested if statements on the observer, hopefully it's all good. Well move to @glennjacobs for last review.

alecritson avatar Jul 03 '24 07:07 alecritson