Problem/Motivation
When Xymatic triggers a delete event in XymaticWebhookController following error is thrown:
NOTICE: PHP message: TypeError: xymatic_migrate_xymatic_webhook(): Argument #1 ($media) must be of type Drupal\media\MediaInterface, bool given in /var/www/html/docroot/modules/contrib/xymatic/modules/xymatic_migrate/xymatic_migrate.module on line 13 #0 [internal function]: xymatic_migrate_xymatic_webhook()
#1 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(426): call_user_func_array()
#2 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()
#3 /var/www/html/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(433): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#4 /var/www/html/docroot/modules/contrib/xymatic/src/Controller/XymaticWebhookController.php(110): Drupal\Core\Extension\ModuleHandler->invokeAll()
#5 [internal function]: Drupal\xymatic\Controller\XymaticWebhookController->handle()
#6 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#7 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#9 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#10 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#12 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#13 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#14 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#15 /var/www/html/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#16 /var/www/html/vendor/asm89/stack-cors/src/Asm89/Stack/Cors.php(49): Drupal\page_cache\StackMiddleware\PageCache->handle()
#17 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle()
#18 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#19 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#20 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#21 /var/www/html/docroot/index.php(19): Drupal\Core\DrupalKernel->handle()
#22 {main}
Steps to reproduce
Trigger Xymatic delete event on Drupal's Xymatic webhook endpoint with enabled xymatic_migrate sub-module.
Proposed resolution
Replace
if (isset($media)) {
$this->moduleHandler()->invokeAll('xymatic_webhook', [$media, $content]);
}
with
if (isset($media) && $media instanceof MediaInterface) {
$this->moduleHandler()->invokeAll('xymatic_webhook', [$media, $content]);
}
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork xymatic-3356917
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
it-cruIf hook_xymatic_webhook() also should provide custom code handling for delete events, it will be better to trigger $media->delete() after invokeAll() call or invokeAll() call should be triggert in each event case separate.
Comment #4
chr.fritschI moved the trigger of the hook into each case statement.
Comment #6
it-cruWith patch included from MR error on delete is gone.
+1 for RTBC
Only open discussion should the
$this->moduleHandler()->invokeAll('xymatic_webhook', [$media, $content]);fired before or after$media->save().Comment #7
chr.fritschComment #9
chr.fritsch