Skip to content

Comments

fix: Media-Liste category_id=0 Filter + mediaIsInUse 500er absichern#32

Open
skerbis wants to merge 2 commits intomainfrom
fix/media-category-id-zero-filter
Open

fix: Media-Liste category_id=0 Filter + mediaIsInUse 500er absichern#32
skerbis wants to merge 2 commits intomainfrom
fix/media-category-id-zero-filter

Conversation

@skerbis
Copy link
Member

@skerbis skerbis commented Feb 20, 2026

Fixes

1. Media-Liste filter[category_id]=0 wird jetzt korrekt verarbeitet

Problem: Beim Filtern mit filter[category_id]=0 (Root-Kategorie) wurde der Filter ignoriert und alle Medien zurückgegeben.

Ursache: Die Bedingung 0 < $Query["filter"]["category_id"] war für category_id=0 immer false.

Fix:

  • category_id=0 wird jetzt als SQL WHERE-Bedingung gesetzt
  • rex_media_category::get() wird nur für id > 0 geprüft (Root hat keine Kategorie-Instanz)
  • Expliziter Cast auf (int) für Type Safety

2. handleGetMedia(): mediaIsInUse() in try-catch wrappen

Problem: rex_mediapool::mediaIsInUse() ruft den Extension Point MEDIA_IS_IN_USE auf. Fehlerhafte EP-Listener (z.B. $ep->setSubject(true) statt Array) können einen TypeError auslösen und die API mit HTTP 500 crashen lassen.

Konkreter Fall: mediapool_tools setzte $ep->setSubject(true) statt das Warning-Array korrekt weiterzugeben. Das führte in mediapool.php Zeile 100 zu implode("", true) → TypeError.

Fix:

  • mediaIsInUse() wird in try/catch(\Throwable) gewrapped
  • Bei Fehler: is_in_use: false als sicherer Fallback
  • Eine REST-API sollte nie wegen fehlerhafter Drittanbieter-EP-Listener mit 500 crashen

Die Bedingung 0 < category_id hat dazu geführt, dass category_id=0 (Root-Kategorie)
ignoriert wurde und stattdessen alle Medien ohne Filter zurückgegeben wurden.
Jetzt wird category_id=0 korrekt als WHERE-Bedingung angewendet.
Die rex_media_category::get()-Prüfung wird nur für id > 0 durchgeführt,
da Root keine eigene Kategorie-Instanz hat.
Copilot AI review requested due to automatic review settings February 20, 2026 13:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where filtering the media list by filter[category_id]=0 (root category) was incorrectly ignored, returning all media without any category filter instead. The fix correctly applies the SQL WHERE condition for category_id=0 while maintaining proper validation logic for categories with ID > 0.

Changes:

  • Fixed the conditional logic to apply category_id filter for value 0 (root category)
  • Extracted category_id to a variable with explicit int cast for type safety
  • Moved rex_media_category validation inside a nested condition that only executes for category_id > 0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…P-Listener zu verhindern

rex_mediapool::mediaIsInUse() ruft den Extension Point MEDIA_IS_IN_USE auf.
Fehlerhafte Listener (z.B. setSubject(true) statt Array) können einen
TypeError auslösen. Der try-catch fängt das ab und gibt is_in_use: false
als sicheren Fallback zurück.
@skerbis skerbis changed the title fix: Media-Liste filter[category_id]=0 wird jetzt korrekt verarbeitet fix: Media-Liste category_id=0 Filter + mediaIsInUse 500er absichern Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant