You are here

class FileUsageMigrateSubscriber in Multiversion 8

FileUsageMigrateSubscriber class.

Records in the file usage table associated with the migrated entity type needs to be removed, they will be automatically re-created when this entity type records will be migrated back by file field handler.

Hierarchy

  • class \Drupal\multiversion\EventSubscriber\FileUsageMigrateSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of FileUsageMigrateSubscriber

1 string reference to 'FileUsageMigrateSubscriber'
multiversion.services.yml in ./multiversion.services.yml
multiversion.services.yml
1 service uses FileUsageMigrateSubscriber
multiversion.file_usage_migrate_subscriber in ./multiversion.services.yml
Drupal\multiversion\EventSubscriber\FileUsageMigrateSubscriber

File

src/EventSubscriber/FileUsageMigrateSubscriber.php, line 18

Namespace

Drupal\multiversion\EventSubscriber
View source
class FileUsageMigrateSubscriber implements EventSubscriberInterface {

  /**
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * @var \Drupal\Core\Extension\ModuleHandler
   */
  protected $moduleHandler;

  /**
   * Class constructor.
   *
   * @param \Drupal\Core\Database\Connection $connection
   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
   */
  public function __construct(Connection $connection, ModuleHandler $module_handler) {
    $this->connection = $connection;
    $this->moduleHandler = $module_handler;
  }

  /**
   * Remove file usage records associated with the migrated entity type.
   *
   * @param \Drupal\multiversion\Event\MultiversionManagerEvent $event
   */
  public function onPreMigrateFileUsage(MultiversionManagerEvent $event) {
    if ($this->moduleHandler
      ->moduleExists('file')) {
      foreach ($event
        ->getEntityTypes() as $entity_type) {
        $type = $entity_type
          ->id();
        $this->connection
          ->delete('file_usage')
          ->condition('type', $type)
          ->execute();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      MultiversionManagerEvents::PRE_MIGRATE => [
        'onPreMigrateFileUsage',
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileUsageMigrateSubscriber::$connection protected property
FileUsageMigrateSubscriber::$moduleHandler protected property
FileUsageMigrateSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FileUsageMigrateSubscriber::onPreMigrateFileUsage public function Remove file usage records associated with the migrated entity type.
FileUsageMigrateSubscriber::__construct public function Class constructor.