Allow sorting results in generator

Created on 25 August 2023, about 1 year ago
Updated 4 September 2024, 3 months ago

Problem/Motivation

This request might be very specific to the situation we are in now. So i can imagine this won't make it into the module in the end.

The API we are consuming cannot be sorted on the property that we need to use as high water mark. Having the results in the right order is a requirement for updates to work properly with high water marks.

Steps to reproduce

TBD

Proposed resolution

Introduce an event that can be used to do some custom sort on the results before the yield in the generator.

Remaining tasks

-
- Review MR
- Merge MR (?)

User interface changes

N/A

API changes

It is possible to subscribe to a "result sort" event.

Data model changes

N/A

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇳🇱Netherlands ricovandevin

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

Merge Requests

Comments & Activities

  • Issue created by @ricovandevin
  • Merge request !11Resolve #3383370 "Allow sorting results" → (Merged) created by ricovandevin
  • Assigned to ricovandevin
  • Status changed to Needs review about 1 year ago
  • 🇳🇱Netherlands ricovandevin

    Updated the PR as we need to check to migration ID in the event subscriber to see if we should actually act on the migration that is running when the event is dispatched.

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @ricovandevin,
    thanks again for your constant activity on the module!

    I would like to embed also this feature but i think that we need to work on a exphansive documentation. I've already created a doc page:
    https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib...
    But need to be completed of all module's features.

    I will take some more time to review it and possibly integrate it into the branch, accompanying the change, however, with documentation.

    Thanks,
    let me know what do you thinks about.

  • Status changed to Needs work 5 months ago
  • 🇳🇱Netherlands ricovandevin

    Resolved merge conflicts in MR.

    Needs work for the documentation part.

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @ricovandevin, thanks for your contribution!

    Recently i worked on the new documentation, including all about *-dev merged features (read more: https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... ).

    I will merge your MR in 2.x-dev and i think that the module is ready for a new stable release 2.0.8 but not before adding the instructions about the ResultsEvent (let me know if you want to do it by your self modifying the documentation page or if you can't; then i'll do it as soon as possible).

    Thanks very much!

  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    Hi @ricovandevin, i merged all things into 2.1.0, a new major release.
    I've also wrote the documentation part about your ResultsEvent.

    Here a summary:
    ---
    ResultsEvent for Data Manipulation

    Starting from version 2.1.0, the Migrate Source GraphQL module introduces the ResultsEvent, allowing other modules to modify the results obtained from a GraphQL query during migration.
    Key Features

    - getResults(): Retrieves the current query results.
    - setResults(array $results): Allows modification of these results.

    Usage Example
    Modules can subscribe to the ResultsEvent to manipulate the migration data:

    use Drupal\migrate_source_graphql\Event\ResultsEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class MyModuleSubscriber implements EventSubscriberInterface {
      public static function getSubscribedEvents() {
        return [ResultsEvent::class => 'onResultsEvent'];
      }
    
      public function onResultsEvent(ResultsEvent $event) {
        $results = $event->getResults();
        // Custom modifications to results.
        $results['custom_field'] = 'custom_value';
        $event->setResults($results);
      }
    }
    
    

    The GraphQL plugin now dispatches this event, enabling custom data handling during migrations.

    Thanks

  • Status changed to Fixed 3 months ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹

    MR was merged into 2.1.0, a new major release.
    I've also wrote the documentation part about your ResultsEvent.

  • Status changed to Fixed 3 months ago
  • 🇮🇹Italy reinchek Napoli 🌋, 🇮🇹
Production build 0.71.5 2024