public static function FlowPull::force_pull_entity in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Controller/FlowPull.php \Drupal\cms_content_sync\Controller\FlowPull::force_pull_entity()
- 2.0.x src/Controller/FlowPull.php \Drupal\cms_content_sync\Controller\FlowPull::force_pull_entity()
Force pull an entity for a specific flow.
Parameters
$flow_id:
$entity_type:
$entity_uuid:
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
3 calls to FlowPull::force_pull_entity()
- CliService::force_pull_entity in src/
Cli/ CliService.php - Kindly ask the Sync Core to force pull a specific entity.
- CliService::pull in src/
Cli/ CliService.php - Kindly ask the Sync Core to pull all entities for a specific flow, or to force pull one specific entity.
- PullStatusEntity::execute in modules/
cms_content_sync_views/ src/ Plugin/ Action/ PullStatusEntity.php
File
- src/
Controller/ FlowPull.php, line 77
Class
- FlowPull
- Pull controller.
Namespace
Drupal\cms_content_sync\ControllerCode
public static function force_pull_entity($flow_id, $entity_type, $entity_uuid) {
$entity = EntityStatus::getInfosForEntity($entity_type, $entity_uuid, [
'flow' => $flow_id,
]);
$entity = reset($entity);
/** @var \Drupal\cms_content_sync\Entity\EntityStatus $entity */
if ($entity instanceof EntityStatus) {
// If the entity is embedded, we need to pull the parent entity instead.
if ($entity
->wasPulledEmbedded()) {
$parent = $entity
->getParentEntity();
if (!$parent) {
$raw = $entity
->getData(EntityStatus::DATA_PARENT_ENTITY);
\Drupal::messenger()
->addMessage(t("The @type with the ID @uuid was pulled embedded into another entity but that parent @parent_type with ID @parent_uuid doesn't exist.", [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'@uuid' => $entity
->get('entity_uuid')
->getValue()[0]['value'],
'@parent_type' => $raw['type'],
'@parent_uuid' => $raw['uuid'],
]), 'warning');
return;
}
self::force_pull_entity($flow_id, $parent
->getEntityTypeId(), $parent
->uuid());
}
$source = $entity
->getEntity();
if (empty($source)) {
\Drupal::messenger()
->addMessage(t("The @type with the ID @uuid doesn't exist locally, pull skipped.", [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'@uuid' => $entity
->get('entity_uuid')
->getValue()[0]['value'],
]), 'warning');
return;
}
$pool = $entity
->getPool();
if (empty($pool)) {
\Drupal::messenger()
->addMessage(t('The Pool for @type %label doesn\'t exist anymore, push skipped.', [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'%label' => $source
->label(),
]), 'warning');
return;
}
$entity_type_name = $source
->getEntityTypeId();
$entity_bundle = $source
->bundle();
$manual = false;
$flow = $entity
->getFlow();
if (!$flow || !$flow
->canPullEntity($entity_type_name, $entity_bundle, PullIntent::PULL_AUTOMATICALLY, SyncIntent::ACTION_CREATE, true)) {
if ($flow && $flow
->canPullEntity($entity_type_name, $entity_bundle, PullIntent::PULL_MANUALLY, SyncIntent::ACTION_CREATE, true)) {
$manual = true;
}
elseif (!$flow || !$flow
->canPullEntity($entity_type_name, $entity_bundle, PullIntent::PULL_AS_DEPENDENCY, SyncIntent::ACTION_CREATE, true)) {
// The flow from the status entity no longer pulls this entity type / bundle => look for a new Flow to replace it.
$flow = Flow::getFlowForApiAndEntityType($pool, $entity_type_name, $entity_bundle, PullIntent::PULL_AUTOMATICALLY, SyncIntent::ACTION_CREATE, true);
if (!$flow) {
$flow = Flow::getFlowForApiAndEntityType($pool, $entity_type_name, $entity_bundle, PullIntent::PULL_MANUALLY, SyncIntent::ACTION_CREATE, true);
if ($flow) {
$manual = true;
}
else {
$flow = Flow::getFlowForApiAndEntityType($pool, $entity_type_name, $entity_bundle, PullIntent::PULL_AS_DEPENDENCY, SyncIntent::ACTION_CREATE, true);
if (!$flow) {
\Drupal::messenger()
->addMessage(t('No Flow exists to pull @type %label, pull skipped.', [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'%label' => $source
->label(),
]), 'warning');
return;
}
}
}
}
}
if ($source instanceof ConfigEntityInterface) {
$shared_entity_id = $source
->id();
}
else {
$shared_entity_id = $source
->uuid();
}
try {
$pool
->getClient()
->getSyndicationService()
->pullSingle($flow->id, $entity_type_name, $entity_bundle, $shared_entity_id)
->fromPool($pool->id)
->manually((bool) $manual)
->execute();
\Drupal::messenger()
->addMessage(t('Pull of @type %label has been triggered.', [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'%label' => $source
->label(),
]));
} catch (SyncCoreException $e) {
\Drupal::messenger()
->addMessage(t('Failed to pull @type %label: @message', [
'@type' => $entity
->get('entity_type')
->getValue()[0]['value'],
'%label' => $source
->label(),
'@message' => $e
->getMessage(),
]), 'warning');
}
}
else {
\Drupal::messenger()
->addMessage(t('No local status entity found for Entity Type: @type having UUID: @uuid.', [
'@type' => $entity_type,
'@uuid' => $entity_uuid,
]), 'warning');
return;
}
}