Add an option to only compare within the same media bundle

Created on 4 July 2023, 12 months ago
Updated 21 September 2023, 9 months ago

Problem/Motivation

We just had the case that a media had to be reuploaded as a different media type, while the file is exactly the same. This is a seldom case, but not totally untypical.

In our case it was a header slide, that needed to be re-uploaded as image.
Another example might be a download (document) that needs to be re-uploaded for example as audio file or something else.

Steps to reproduce

Proposed resolution

Add a setting:
Title: "Only compare within the same media buldes"
Description: "If this is enabled, duplicates are enabled across media bundles, but not within the same media bundles"

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • Yes, this is really annoying :/
    I'd love to see this option.

  • First commit to issue fork.
  • @grevil opened merge request.
  • Assigned to Anybody
  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Grevil

    Ok, it SHOULD theoretically already work, but there are two problems:
    "$entity->id()" is NULL inside "/src/Plugin/Validation/Constraint/MediaUniqueChecksumValidator.php" "validate()". Since the entity is given down to 'checksumExists()' it is still NULL there, and we can not check its bundle (since it is NULL).

    Furthermore, (and I don't get this problem at all), with the MR applied, the only enabling the restrict_duplicates setting, doesn't restrict users from creating duplicate media items anymore. This doesn't make sense to me at all... I debugged every if case and anything I added to the code everything works as expected and the old code should still work the same, but it doesn't.... Really weird, maybe some AJAX racing condition.

    It also seems very odd to execute a database query through AJAX Validation? Seems very prone to issues... what are your thoughts on this @Anybody? The code should be fine like this.

  • Status changed to Active 10 months ago
  • 🇩🇪Germany Grevil

    Ok, I am super confused... How is "$entity->id()" NULL, but "$entity->bundle()" isn't? I couldn't debug "$entity" itself, since it is too much for the AJAX reponse. But yea using the entity->id() check instead of $entity will resolve the issue...

  • 🇩🇪Germany Grevil

    Ok, I see now... $media is already initialized and has its type set inside the validation, but since the media isn't submitted (aka created) yet, it doesn't have an ID!

    So because 'checksumExists()' is only called once in code inside the validation, this check here:

        if ($entity->id() !== NULL) {
          $query->condition('mid', $entity->id(), '!=');
        }
    

    is unnecessary, since '$entity->id()' is to 100% of all method calls NULL. I'll create a follow-up issue for that!

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Works like a charm now! 😍

    Please review!

  • Issue was unassigned.
  • Well done, thx! I tested with the setting active and inactive, everything works as expected.

    Should @anybody review the code?

  • Assigned to Grevil
  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @Grevil, nice work!
    I'm just not happy with the labels, don't think this is clear enough for someone using the module for the first time.

    Back to NW for the wordings. Please also rename the variables accordingly once we have a clear wording. We need a native speaker ;)

  • 🇩🇪Germany Anybody Porta Westfalica

    Triggering @nterbogt as native speaker, perhaps he has a nice wording suggestion?

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Grevil

    Really like "compare_within_bundle_only", maybe "compare_within_same_bundle_only"? Or a bit too long for a machine name?

  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil:
    I think let's use

    1. compare_within_same_bundle_only
    2. compare_within_bundle_only
    3. compare_only_within_bundle

    2nd is my favorite now.
    Please replace all occurrences (variables etc.) then we should be ready to go, if it was tested with and without the option.

  • 🇩🇪Germany Grevil

    Alright, on it.

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    All done, please rereview!

  • Status changed to Needs work 10 months ago
  • 🇩🇪Germany Grevil

    Oh, my apologies, there is no update hook!

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany Grevil

    Done, please review.

  • Issue was unassigned.
  • 🇩🇪Germany Anybody Porta Westfalica

    @thomas.frobieter could you perhaps test this? Code is fine! But should be tested manually to be sure it works as expected. You left a comment at ZMP where it would help you.

  • Status changed to Needs work 9 months ago
  • Doesn't seem to work, only one option left after switching to the issue branch, two options on the dev branch.

    On branch 3372255-add-an-option
    Your branch is up to date with 'origin/3372255-add-an-option'

  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    @thomas.frobieter the new option is a dependent option, did you mark the checkbox?

  • Assigned to thomas.frobieter
  • Status changed to Needs review 9 months ago
  • Probably not, I'll try again later.

  • Issue was unassigned.
  • Status changed to RTBC 9 months ago
  • Tried all combinations, works very well, great job!

  • Status changed to Fixed 9 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks, merged!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024