Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug? hook_media_update(), $parent->save(), generates EmitMediaEvent for a Node #2069

Closed
antbrown opened this issue Mar 30, 2022 · 8 comments
Closed

Comments

@antbrown
Copy link

Steps to reproduce.

  1. Implement hook_media_update()
  2. Fetch parent node $islandora = \Drupal::service('islandora.utils'); $parent = $islandora->getParentNode($media);
  3. Make changes to parent node and save: $parent->save();
  4. Observe the error: "Error generating event: Bundle islandora_object does not exist" (or whatever bundle your parent node is).

Big note: This occurs on #cb52ddd, I need to update to 2.x before confirming it exists there as well, but this will take me a couple of days based on current workload. If anyone is able to do it faster, or knows if EmitEvent/EmitMediaEvent has addressed this issue since then, it would be much appreciated.

Further observations:

If anyone knows this part of the system and could point me in the right direction, that would be awesome.

Cheers,
Ant

@jordandukart jordandukart self-assigned this Mar 30, 2022
@jordandukart
Copy link
Member

jordandukart commented Mar 30, 2022

Hey @antbrown did the following and couldn't reproduce:

<?php

use Drupal\media\MediaInterface;

/**
 * Implements hook_media_update().
 */
function mymodule_media_update(MediaInterface $media) {
  $parent = \Drupal::service('islandora.utils')->getParentNode($media);
  $parent->set('title', 'test');
  $parent->save();
}

My parent node returned from the utils call gets its title updated. Any further information as to what's triggering / a bigger stacktrace?

My method of testing was:
Create a media, save it.
Go back and update some value that triggers the above hook, save.

@jordandukart jordandukart removed their assignment Mar 30, 2022
@antbrown
Copy link
Author

Hi @jordandukart, thanks for the quick turnaround. I'll try get some more data for you later today. Out of interest, when you tested did you use islandora 2.x or #cb52ddd? Cheers, Ant.

@jordandukart
Copy link
Member

jordandukart commented Mar 30, 2022

I'm running off of HEAD currently, feel free to ping me in Slack as well if you'd like!

@jordandukart
Copy link
Member

Hey @antbrown any progress / updates on this?

@lucasvanschaik
Copy link

Hi @antbrown and @jordandukart,

I got the same error when trying to migrate objects from Islandora 7 to Islandora 8.
After much debugging I noticed that Islandora provides its own ContextManager (Drupal\islandora\IslandoraContextManager) that extends Drupal\context\ContextManager and that the latter has received two bug fixes that the former did not get.
After applying the bug fixes, the error disappears. Apparently some contexts are not evaluated properly resulting in emitting the wrong event(s).

The code changes and issues are described here:
https://git.drupalcode.org/project/context/-/commit/b7e8b7f2295d661dc83513e282df4234c9c390c1
https://git.drupalcode.org/project/context/-/commit/d31cd87b909737abd1beab10e68c62ec29acce35

These changes result in firing less events, but I think only the right events fire now. I will test this change on our development server, but please review and test this as well.

NB: these changes might also solve another bug (that was already solved another way): #1848

regards,
Lucas

@seth-shaw-asu
Copy link
Member

@lucasvanschaik, would you be willing to issue a pull request with the specific changes?

@lucasvanschaik
Copy link

lucasvanschaik commented Feb 17, 2023

I have tested some more and noticed that the above fix did not fully solve the problem. I've dug deeper and found another issue and solution.
Both are in the PR: Islandora/islandora#931

@jordandukart
Copy link
Member

Think we may be able to close this with Islandora/islandora#931 and Islandora/islandora#932 being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants