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'
1 service uses FileUsageMigrateSubscriber
File
- src/
EventSubscriber/ FileUsageMigrateSubscriber.php, line 18
Namespace
Drupal\multiversion\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileUsageMigrateSubscriber:: |
protected | property | ||
FileUsageMigrateSubscriber:: |
protected | property | ||
FileUsageMigrateSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
FileUsageMigrateSubscriber:: |
public | function | Remove file usage records associated with the migrated entity type. | |
FileUsageMigrateSubscriber:: |
public | function | Class constructor. |