Implement duplicate detection as a service

Created on 14 June 2024, 7 months ago

It would be useful if the duplicateFileDetection and duplicateMediaImageDetection methods were implemented as services. That would allow you to create a custom event subscriber on the MigrateEvents::PRE_IMPORT event to automatically run duplicate file detection before a migration runs.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain Peacog

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

Comments & Activities

  • Issue created by @Peacog
  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 3454659-duplicate-detection-service to hidden.

  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 3454659-duplicate-detection-service to active.

  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 3454659-duplicate-detection-service to hidden.

  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 3454659-implement-duplicate-detection to hidden.

  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 3454659-implement-duplicate-detection to active.

  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Peacog β†’ changed the visibility of the branch 2.0.x to hidden.

  • @peacog opened merge request.
  • Status changed to Needs review 7 months ago
  • πŸ‡ͺπŸ‡ΈSpain Peacog

    Here's an example of the custom pre-import event that uses the service in this patch.

    <?php
    
    namespace Drupal\my_custom_migrate\EventSubscriber;
    
    use Drupal\migrate\Event\MigrateImportEvent;
    use Drupal\migrate_file_to_media\Services\DuplicateDetectionService;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use Drupal\migrate\Event\MigrateEvents;
    
    /**
     * Custom migrate event subscriber.
     */
    class MyCustomMigrateSubscriber implements EventSubscriberInterface {
      /**
       * The duplicate file detection service.
       *
       * @var \Drupal\migrate_file_to_media\Services\DuplicateDetectionService
       */
      protected DuplicateDetectionService $duplicateDetectionService;
    
      /**
       * Constructs a MyCustomMigrateSubscriber object.
       *
       * @param \Drupal\migrate_file_to_media\Services\DuplicateDetectionService $duplicateDetectionService
       *   The search links service.
       */
      public function __construct(DuplicateDetectionService $duplicateDetectionService) {
        $this->duplicateDetectionService = $duplicateDetectionService;
      }
    
      /**
       * Run migrate:duplicate-file-detection before migrate_file_to_media
       * migrations.
       **
       * @param \Drupal\migrate\Event\MigrateImportEvent $event
       *   Response event.
       */
      public function onPreImport(MigrateImportEvent $event) {
        $config = $event->getMigration()->getPluginDefinition();
    
        if (($config['source']['plugin'] ?? '') !== 'media_entity_generator_d7') {
          return;
        }
    
        // Run the migrate:duplicate-file-detection command for the migration.
        $this->duplicateDetectionService->duplicateFileDetection($config['id'], [FALSE, TRUE]);
      }
    
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents() {
        return [
          MigrateEvents::PRE_IMPORT => ['onPreImport'],
        ];
      }
    
    }
    
    
  • Status changed to Needs work 24 days ago
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    MR must be rebased from the dev branch

Production build 0.71.5 2024