class PruneImportedEntitiesFromExport in Acquia Content Hub 8.2
Prunes imported entities so they are not exported.
@package Drupal\acquia_contenthub_subscriber\EventSubscriber\PrunePublishEntities
Hierarchy
- class \Drupal\acquia_contenthub_subscriber\EventSubscriber\PrunePublishEntities\PruneImportedEntitiesFromExport implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of PruneImportedEntitiesFromExport
1 file declares its use of PruneImportedEntitiesFromExport
- PruneImportedEntitiesFromExportTest.php in tests/
src/ Kernel/ EventSubscriber/ ExportUnownedContentOnDualConfigSites/ PruneImportedEntitiesFromExportTest.php
1 string reference to 'PruneImportedEntitiesFromExport'
- acquia_contenthub_subscriber.services.yml in modules/
acquia_contenthub_subscriber/ acquia_contenthub_subscriber.services.yml - modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.services.yml
1 service uses PruneImportedEntitiesFromExport
File
- modules/
acquia_contenthub_subscriber/ src/ EventSubscriber/ PrunePublishEntities/ PruneImportedEntitiesFromExport.php, line 17
Namespace
Drupal\acquia_contenthub_subscriber\EventSubscriber\PrunePublishEntitiesView source
class PruneImportedEntitiesFromExport implements EventSubscriberInterface {
/**
* Keep track of the tracker table.
*
* @var \Drupal\acquia_contenthub_subscriber\SubscriberTracker
*/
protected $tracker;
/**
* Status Checker.
*
* @var \Drupal\acquia_contenthub\PubSubModuleStatusChecker
*/
private $checker;
/**
* Entity Repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
private $entityRepository;
/**
* TrackTotals constructor.
*
* @param \Drupal\acquia_contenthub_subscriber\SubscriberTracker $tracker
* Subscriber tracker.
* @param \Drupal\acquia_contenthub\PubSubModuleStatusChecker $checker
* Status checker.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* Entity Repository.
*/
public function __construct(SubscriberTracker $tracker, PubSubModuleStatusChecker $checker, EntityRepositoryInterface $entity_repository) {
$this->tracker = $tracker;
$this->checker = $checker;
$this->entityRepository = $entity_repository;
}
/**
* Retrieve subscribed events.
*
* @return array
* Subscribed event.
*/
public static function getSubscribedEvents() : array {
return [
AcquiaContentHubEvents::PRUNE_PUBLISH_CDF_ENTITIES => 'onPrunePublishCdfEntitiesIfSiteHasDualConfiguration',
];
}
/**
* OnPrunePublishCdfEntities event handler.
*
* @param \Drupal\acquia_contenthub\Event\PrunePublishCdfEntitiesEvent $event
* Prune published cdf entities event.
*
* @throws \ReflectionException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function onPrunePublishCdfEntitiesIfSiteHasDualConfiguration(PrunePublishCdfEntitiesEvent $event) : void {
if (!$this->checker
->siteHasDualConfiguration()) {
return;
}
/** @var \Acquia\ContentHubClient\CDFDocument $document */
$document = $event
->getDocument();
$doc_uuids = array_keys($document
->getEntities());
$untracked_uuids = $this->tracker
->getUntracked($doc_uuids);
$tracked_uuids = array_diff($doc_uuids, $untracked_uuids);
// Leave untracked uuids by removing all tracked uuids from the document.
foreach ($tracked_uuids as $remove_uuid) {
$document
->removeCdfEntity($remove_uuid);
}
// Fetch all entities from Plexus from the list of untracked uuids.
$remote_entities = $event
->getClient()
->getEntities($untracked_uuids);
$site_origin = $event
->getOrigin();
foreach ($remote_entities
->getEntities() as $entity) {
$uuid = $entity
->getUuid();
// It's eligible to be exported iff owned by self.
if ($entity
->getOrigin() === $site_origin) {
continue;
}
// Remove from the document to prevent it from being exported.
$cdf = $document
->getCdfEntity($uuid);
$document
->removeCdfEntity($uuid);
// Add to the tracking table so it never ends up in the export queue.
$local_entity = $this->entityRepository
->loadEntityByUuid($cdf
->getAttribute('entity_type')
->getValue()['und'], $uuid);
if ($local_entity) {
$this->tracker
->track($local_entity, $entity
->getAttribute('hash')
->getValue()['und']);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PruneImportedEntitiesFromExport:: |
private | property | Status Checker. | |
PruneImportedEntitiesFromExport:: |
private | property | Entity Repository. | |
PruneImportedEntitiesFromExport:: |
protected | property | Keep track of the tracker table. | |
PruneImportedEntitiesFromExport:: |
public static | function | Retrieve subscribed events. | |
PruneImportedEntitiesFromExport:: |
public | function | OnPrunePublishCdfEntities event handler. | |
PruneImportedEntitiesFromExport:: |
public | function | TrackTotals constructor. |