public function ReplicationFinished::onInternalReplicationFinished in Workspace 8
Listener for replication finished.
Parameters
\Drupal\workspace\Event\ReplicationEvent $event: Drupal\workspace\Event\WorkspaceReplicationFinishedEvent.
File
- src/
EventSubscriber/ ReplicationFinished.php, line 75
Class
- ReplicationFinished
- Class ReplicationFinished.
Namespace
Drupal\workspace\EventSubscriberCode
public function onInternalReplicationFinished(ReplicationEvent $event) {
$replication = $event
->getReplication();
if ($replication
->getReplicationStatus() == Replication::REPLICATED && $this->aliasTypeManager && $this->pathAutoGenerator) {
$source_workspace_pointer = $replication
->get('source')->entity;
$target_workspace_pointer = $replication
->get('target')->entity;
// Filtered events. If the event is triggered by a pull from external
// source, we use the onExternalPullReplicationFinished method.
// If the target workspace is on external sources
// we do not handle the event.
if (!$source_workspace_pointer
->hasField('remote_pointer') && !$source_workspace_pointer
->hasField('remote_database') && !$target_workspace_pointer
->hasField('remote_pointer') && !$target_workspace_pointer
->hasField('remote_database') || empty($source_workspace_pointer
->get('remote_pointer')->target_id) && empty($source_workspace_pointer
->get('remote_database')->value) && empty($target_workspace_pointer
->get('remote_pointer')->target_id) && empty($target_workspace_pointer
->get('remote_database')->value)) {
$target_workspace = $target_workspace_pointer
->getWorkspace();
$current_workspace = $this->workspaceManager
->getActiveWorkspace();
$this->workspaceManager
->setActiveWorkspace($target_workspace);
$definitions = $this->aliasTypeManager
->getVisibleDefinitions();
foreach ($definitions as $definition) {
foreach ($definition['context'] as $entity_type => $context_definition) {
$this
->updateEntitiesAlias($entity_type);
}
}
$this->workspaceManager
->setActiveWorkspace($current_workspace);
}
}
}