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

EmitFileEvent.php: Call to undefined function getFileUri() #1848

Open
alxp opened this issue Jun 11, 2021 · 6 comments
Open

EmitFileEvent.php: Call to undefined function getFileUri() #1848

alxp opened this issue Jun 11, 2021 · 6 comments
Labels
Type: bug identifies a problem in the software with clear steps to reproduce

Comments

@alxp
Copy link
Contributor

alxp commented Jun 11, 2021

There seems to be times when the function generateData is calling $entity->getFIleUri() on an object of class Media that does not have that function. This causes a white screen and interferes with generating derivatives.

Steps to reproduce:

Fresh Islandora install using the islandora_profile install profile, done via the playbook. (install_profile branch). Have not yet tested on ISLE, but probably should,.)

Create a repository item node, and then add a media of type Document.

Upload a PDF and set as Original File.

Save the media.

Inspecting the $entity object at islandora/..//EmitFileEvent.php :106

protected function generateData(EntityInterface $entity) {
$uri = $entity->getFileUri();

get_class($entity);
"Drupal\media\Entity\Media"

Call Stack:
Drupal\islandora\Plugin\Action\EmitFileEvent->generateData (/var/www/html/drupal/web/modules/contrib/islandora/src/Plugin/Action/EmitFileEvent.php:108)
Drupal\islandora\Plugin\Action\EmitFileEvent->execute (/var/www/html/drupal/web/modules/contrib/islandora/src/EventGenerator/EmitEvent.php:148)
Drupal\islandora\Plugin\Action\EmitFileEvent->executeMultiple (/var/www/html/drupal/web/core/lib/Drupal/Core/Action/ActionBase.php:22)
Drupal\system\Entity\Action->execute (/var/www/html/drupal/web/core/modules/system/src/Entity/Action.php:129)
Drupal\islandora\Plugin\ContextReaction\IndexReaction->execute (/var/www/html/drupal/web/modules/contrib/islandora/src/PresetReaction/PresetReaction.php:59)
Drupal\islandora\IslandoraUtils->executeMediaReactions (/var/www/html/drupal/web/modules/contrib/islandora/src/IslandoraUtils.php:348)
islandora_media_insert (/var/www/html/drupal/web/modules/contrib/islandora/islandora.module:86)
call_user_func_array:{/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403} (/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403)
Drupal\Core\Extension\ModuleHandler->invokeAll (/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403)
Drupal\media\MediaStorage->invokeHook (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:199)
Drupal\media\MediaStorage->invokeHook (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:800)
Drupal\media\MediaStorage->doPostSave (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:530)
Drupal\media\MediaStorage->doPostSave (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:685)
Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:455)
Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:801)
Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/modules/media/src/MediaStorage.php:29)
Drupal\media\Entity\Media->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityBase.php:339)
Drupal\media\MediaForm->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityForm.php:285)
Drupal\media\MediaForm->save (/var/www/html/drupal/web/core/modules/media/src/MediaForm.php:61)
call_user_func_array:{/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php:113} (/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php:113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers (/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php:113)
Drupal\Core\Form\FormSubmitter->doSubmitForm (/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormSubmitter.php:51)
Drupal\Core\Form\FormBuilder->processForm (/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php:593)
Drupal\Core\Form\FormBuilder->buildForm (/var/www/html/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php:321)
Drupal\Core\Entity\HtmlEntityFormController->getContentResult (/var/www/html/drupal/web/core/lib/Drupal/Core/Controller/FormController.php:73)
call_user_func_array:{/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure:/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:121-124} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123)
Drupal\Core\Render\Renderer->executeInRenderContext (/var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php:573)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure:/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:96-98} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:97)
Symfony\Component\HttpKernel\HttpKernel->handleRaw (/var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php:158)
Symfony\Component\HttpKernel\HttpKernel->handle (/var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php:80)
Drupal\Core\StackMiddleware\Session->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php:57)
Drupal\Core\StackMiddleware\KernelPreHandle->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:47)
Drupal\page_cache\StackMiddleware\PageCache->pass (/var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106)
Drupal\page_cache\StackMiddleware\PageCache->handle (/var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:47)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:52)
Stack\StackedHttpKernel->handle (/var/www/html/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23)
Drupal\Core\DrupalKernel->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php:706)
{main} (/var/www/html/drupal/web/index.php:19)

@alxp alxp changed the title EmitFileEvent.php: Call to undefined function getFIleUri() EmitFileEvent.php: Call to undefined function getFileUri() Jun 11, 2021
@dannylamb
Copy link
Contributor

I juuuuuuust ran into this on Friday before clocking out for the weekend. I was testing ISLE with islandora_profile. Thanks for making the issue.

@alxp
Copy link
Contributor Author

alxp commented Jun 15, 2021

@dannylamb So I stopped the error by adding a check in the method above to make sure that the getFileUri() method exists before calling it. But I don't know if that's the correct solution. Should "emitFileEvent" be being called on Media entity types? I see it gets called for file entities. Should there be a check above in the function that goes through all the context reactions that determines which ones to run?

@alxp
Copy link
Contributor Author

alxp commented Jun 18, 2021

Running his through a debugger, I've found that the action called "index_file_as_fedora_external_file" is being called on the Media entity, but the action itself assumes that it is getting a file entity.

It makes sense that this action would want to e performed on such a media, so we need to either:

  1. Check that the action is already being called on the File entity independently, or:
  2. Explicitly extract the media's source file object, if one exists, and get its file URI to add to the $data array.
Stack trace follows: Drupal\islandora\Plugin\Action\EmitFileEvent->generateData (/var/www/html/drupal/web/modules/contrib/islandora/src/Plugin/Action/EmitFileEvent.php:108) Drupal\islandora\Plugin\Action\EmitFileEvent->execute (/var/www/html/drupal/web/modules/contrib/islandora/src/EventGenerator/EmitEvent.php:148) Drupal\islandora\Plugin\Action\EmitFileEvent->executeMultiple (/var/www/html/drupal/web/core/lib/Drupal/Core/Action/ActionBase.php:22) Drupal\system\Entity\Action->execute (/var/www/html/drupal/web/core/modules/system/src/Entity/Action.php:129) Drupal\islandora\Plugin\ContextReaction\IndexReaction->execute (/var/www/html/drupal/web/modules/contrib/islandora/src/PresetReaction/PresetReaction.php:59) Drupal\islandora\IslandoraUtils->executeMediaReactions (/var/www/html/drupal/web/modules/contrib/islandora/src/IslandoraUtils.php:348) islandora_media_insert (/var/www/html/drupal/web/modules/contrib/islandora/islandora.module:86) call_user_func_array:{/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403} (/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403) Drupal\Core\Extension\ModuleHandler->invokeAll (/var/www/html/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:403) Drupal\media\MediaStorage->invokeHook (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:199) Drupal\media\MediaStorage->invokeHook (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:800) Drupal\media\MediaStorage->doPostSave (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:530) Drupal\media\MediaStorage->doPostSave (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:685) Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:455) Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:801) Drupal\media\MediaStorage->save (/var/www/html/drupal/web/core/modules/media/src/MediaStorage.php:29) Drupal\media\Entity\Media->save (/var/www/html/drupal/web/core/lib/Drupal/Core/Entity/EntityBase.php:339) Drupal\islandora\MediaSource\MediaSourceService->putToNode (/var/www/html/drupal/web/modules/contrib/islandora/src/MediaSource/MediaSourceService.php:315) Drupal\islandora\Controller\MediaSourceController->putToNode (/var/www/html/drupal/web/modules/contrib/islandora/src/Controller/MediaSourceController.php:168) call_user_func_array:{/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure:/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:121-124} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123) Drupal\Core\Render\Renderer->executeInRenderContext (/var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php:573) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure:/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:96-98} (/var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:97) Symfony\Component\HttpKernel\HttpKernel->handleRaw (/var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php:158) Symfony\Component\HttpKernel\HttpKernel->handle (/var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php:80) Drupal\Core\StackMiddleware\Session->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php:57) Drupal\Core\StackMiddleware\KernelPreHandle->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:47) Drupal\page_cache\StackMiddleware\PageCache->pass (/var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106) Drupal\page_cache\StackMiddleware\PageCache->handle (/var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:47) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:52) Stack\StackedHttpKernel->handle (/var/www/html/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23) Drupal\Core\DrupalKernel->handle (/var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php:706) {main} (/var/www/html/drupal/web/index.php:19)

@alxp
Copy link
Contributor Author

alxp commented Jun 18, 2021

After the generateData function is run, the generate event code does explicitly check the entity type and uses different logic to get the file URL.

public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) {

    $user_url = $this->utils->getEntityUrl($user);

    $entity_type = $entity->getEntityTypeId();

    if ($entity_type == 'file') {
      $entity_url = $this->utils->getDownloadUrl($entity);
      $mimetype = $entity->getMimeType();
    }
    else {
      $entity_url = $this->utils->getEntityUrl($entity);
      $mimetype = 'text/html';
    }

This indicates that the ggenerateData function should do the same, in lieu of a more graceful cascade that filters entity types.

@kstapelfeldt
Copy link
Member

Not sure if architecture or bug?

@seth-shaw-unlv
Copy link
Contributor

@alxp and @dannylamb did Islandora/islandora#838 and the other two PRs resolve this, or was there something left to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug identifies a problem in the software with clear steps to reproduce
Projects
Development

No branches or pull requests

4 participants