Skip to content

Conversation

@adam-vessey
Copy link
Contributor

@adam-vessey adam-vessey commented Jan 28, 2026

Builds on top of #171

Summary by CodeRabbit

  • New Features

    • Added event handling for stub migration operations with pre/post event tracking
    • Extended stub migration creation to support default values parameter
  • Chores

    • Enhanced internal event dispatcher integration for migration synchronization
    • Improved service configuration for event-driven architecture

✏️ Tip: You can customize this high-level summary in your review settings.

Seems like migrate_tools has some behaviors in its executable that
widely hit on the migrate events, so let's avoid the base events to
avoid its behaviours.
@adam-vessey adam-vessey added the patch Backwards compatible bug fixes. label Jan 28, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The changes introduce an event-dispatching wrapper around the core migrate.stub service, enabling lifecycle event hooks during stub creation. A new StubMigrateEvents class defines four stub event constants. The MigrateStub class is extended with lazy-loaded dependencies and event dispatching in the stub creation flow, while a new MigrateStubEventWrapper decorator orchestrates pre/post import events. Event subscribers across the module are updated to listen for these new stub events.

Changes

Cohort / File(s) Summary
Service Configuration
dgi_migrate.services.yml
Added 2 new services: dgi_migrate.migrate_stub.event_wrapper (decorator wrapping migrate.stub with event dispatching) and dgi_migrate.migrate_message
Stub Event System
src/EventSubscriber/StubMigrateEvents.php, src/MigrateStubEventWrapper.php, src/MigrateStub.php
New StubMigrateEvents class with 4 event constants (PRE_IMPORT, POST_IMPORT, PRE_SAVE, POST_SAVE); new MigrateStubEventWrapper decorator implementing event dispatch logic; MigrateStub extended with lazy-loaded event dispatcher and migrate message properties, event dispatching in doCreateStub, and default_values parameter support
Event Subscribers
modules/dgi_migrate_imagemagick_cleanup/src/EventSubscriber/EventSubscriber.php, src/EventSubscriber/MigrationImmediateIndexingDeferralEventSubscriber.php
Added subscriptions for StubMigrateEvents to handle stack operations (imagemagick_cleanup) and batch tracking deferral (indexing deferral)

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Wrapper as MigrateStubEventWrapper
    participant Dispatcher as EventDispatcher
    participant Inner as MigrateStub (inner)
    participant Subscribers as Event Subscribers

    Client->>Wrapper: createStub(migration_id, source_ids, default_values)
    Wrapper->>Wrapper: getMigration(migration_id)
    Wrapper->>Dispatcher: dispatch(PRE_IMPORT event)
    Dispatcher->>Subscribers: notify PRE_IMPORT listeners
    Subscribers->>Subscribers: execute handlers
    Wrapper->>Inner: createStub(migration, source_ids, default_values)
    Inner->>Inner: doCreateStub with event dispatches
    Inner->>Dispatcher: dispatch(PRE_SAVE event)
    Dispatcher->>Subscribers: notify PRE_SAVE listeners
    Inner->>Inner: perform import
    Inner->>Dispatcher: dispatch(POST_SAVE event)
    Dispatcher->>Subscribers: notify POST_SAVE listeners
    Inner-->>Wrapper: return stub result
    Wrapper->>Dispatcher: dispatch(POST_IMPORT event)
    Dispatcher->>Subscribers: notify POST_IMPORT listeners
    Subscribers->>Subscribers: execute handlers
    Wrapper-->>Client: return stub result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops with glee through stubble and event streams,
A wrapper spins tales of pre and post dreams,
With messages dispatched and defaults in place,
We migrate with grace—events set the pace! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'UI-401: Fix/imagemagick stub cleanup' directly relates to the core changes: adding event handling for stub migrations in imagemagick cleanup and introducing stub-specific migration events.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/MigrateStubEventWrapper.php`:
- Around line 5-26: The constructor currently type-hints
EventDispatcherInterface from PSR-14 but the class calls dispatch($event,
$eventName) (Symfony-style); update the constructor and use statement to
type-hint Symfony's event dispatcher (e.g.
Symfony\Contracts\EventDispatcher\EventDispatcherInterface or
Symfony\Component\EventDispatcher\EventDispatcherInterface) so
MigrateStubEventWrapper::__construct(...) accepts the Symfony dispatcher used by
the dispatch($event, $eventName) calls; adjust the import and keep the parameter
name (eventDispatcher) unchanged.
🧹 Nitpick comments (1)
src/MigrateStub.php (1)

22-78: Align dispatcher type with the event-name dispatch usage here as well.

This code calls dispatch($event, $eventName), which requires Symfony's dispatcher signature. PSR-14's EventDispatcherInterface only supports dispatch(object $event) without an event name parameter. While Drupal's event_dispatcher service is Symfony-based and functionally supports this usage, the type hint should match: switch to Symfony\Component\EventDispatcher\EventDispatcherInterface in the import, property docblock, and method return type.

♻️ Proposed change
-use Psr\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;

-   * `@var` \Psr\EventDispatcher\EventDispatcherInterface|null
+   * `@var` \Symfony\Component\EventDispatcher\EventDispatcherInterface|null
   */
  protected ?EventDispatcherInterface $eventDispatcher = NULL;

-   * `@return` \Psr\EventDispatcher\EventDispatcherInterface
+   * `@return` \Symfony\Component\EventDispatcher\EventDispatcherInterface
   *   The event dispatcher service.
   */
  protected function getEventDispatcher() : EventDispatcherInterface {
    return $this->eventDispatcher ??= \Drupal::service('event_dispatcher');
  }

Comment on lines +5 to +26
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\dgi_migrate\EventSubscriber\StubMigrateEvents;
use Drupal\migrate\Event\MigrateImportEvent;
use Drupal\migrate\MigrateMessageInterface;
use Drupal\migrate\MigrateStubInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;

/**
* Wrap import/creation of stubs to ensure events fire for them.
*/
class MigrateStubEventWrapper implements MigrateStubInterface {

/**
* Constructor.
*/
public function __construct(
protected MigrateStubInterface $inner,
protected MigrationPluginManagerInterface $migrationPluginManager,
protected EventDispatcherInterface $eventDispatcher,
protected MigrateMessageInterface $migrateMessage,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cd /repo && find . -name "MigrateStubEventWrapper.php" -type f

Repository: discoverygarden/dgi_migrate

Length of output: 126


🏁 Script executed:

wc -l src/MigrateStubEventWrapper.php

Repository: discoverygarden/dgi_migrate

Length of output: 105


🏁 Script executed:

cat -n src/MigrateStubEventWrapper.php

Repository: discoverygarden/dgi_migrate

Length of output: 3282


🌐 Web query:

PSR-14 EventDispatcherInterface dispatch method signature

💡 Result:

In PSR-14, Psr\EventDispatcher\EventDispatcherInterface::dispatch() is defined as:

public function dispatch(object $event);

There is no declared return type in the method signature, but the spec requires the dispatcher to return the same event object (typically documented as @return object). [1] [2]

Sources: [1] [2]


🌐 Web query:

Symfony EventDispatcherInterface dispatch method signature

💡 Result:

Current Symfony (Contracts; used by Symfony 5+ / 6 / 7 / 8) uses:

public function dispatch(object $event, ?string $eventName = null): object;

(generically, it returns the same event type T that you pass in). [1][3]

Older Symfony (e.g. 4.1-era symfony/event-dispatcher) used:

public function dispatch(string $eventName, Event $event = null);

[2]


Switch to Symfony's dispatcher interface because the code passes an event name parameter.

Lines 36 and 40 call dispatch($event, $eventName), which is Symfony's API. PSR-14's EventDispatcherInterface::dispatch() accepts only a single parameter: dispatch(object $event). Using the PSR-14 interface here is incorrect and would fail at runtime if a PSR-14-only dispatcher is injected.

Proposed change
-use Psr\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
🤖 Prompt for AI Agents
In `@src/MigrateStubEventWrapper.php` around lines 5 - 26, The constructor
currently type-hints EventDispatcherInterface from PSR-14 but the class calls
dispatch($event, $eventName) (Symfony-style); update the constructor and use
statement to type-hint Symfony's event dispatcher (e.g.
Symfony\Contracts\EventDispatcher\EventDispatcherInterface or
Symfony\Component\EventDispatcher\EventDispatcherInterface) so
MigrateStubEventWrapper::__construct(...) accepts the Symfony dispatcher used by
the dispatch($event, $eventName) calls; adjust the import and keep the parameter
name (eventDispatcher) unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Backwards compatible bug fixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant