You are here

public static function PushEntities::batch in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Controller/PushEntities.php \Drupal\cms_content_sync\Controller\PushEntities::batch()
  2. 2.0.x src/Controller/PushEntities.php \Drupal\cms_content_sync\Controller\PushEntities::batch()

Batch push callback used by the following operations:

  • Flow: Push All
  • Content overview: Push changes
  • Draggableviews: Push changes.

Parameters

string $flow_id:

string $entity_type_id:

int $entity_id:

array $context:

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\GuzzleHttp\Exception\GuzzleException

File

src/Controller/PushEntities.php, line 294

Class

PushEntities
Pull controller.

Namespace

Drupal\cms_content_sync\Controller

Code

public static function batch($flow_id, $entity_type_id, $entity_id, &$context) {
  $message = 'Pushing...';
  $results = [];
  if (isset($context['results'])) {
    $results = $context['results'];
  }

  /**
   * @var \Drupal\cms_content_sync\Entity\Flow $flow
   */
  $flow = Flow::getAll()[$flow_id];

  /**
   * @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
   */
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $entity = $entity_type_manager
    ->getStorage($entity_type_id)
    ->load($entity_id);
  try {
    $status = PushIntent::pushEntity($entity, PushIntent::PUSH_FORCED, SyncIntent::ACTION_CREATE, $flow);
  } catch (\Exception $exception) {
    \Drupal::messenger()
      ->addWarning(t('Item %label could not be pushed: %exception', [
      '%label' => $entity
        ->label(),
      '%exception' => $exception
        ->getMessage(),
    ]));
    $status = false;
  }
  $results[] = $status;
  $context['message'] = $message;
  $context['results'] = $results;
}