public static function ContentHubReindex::reExportEntities in Acquia Content Hub 8
Re-export Entities.
Parameters
int $limit: The number of entities to re-export in a single batch process.
mixed $context: The context array.
1 call to ContentHubReindex::reExportEntities()
- ContentHubReindexTest::testReExportEntities in tests/
src/ Unit/ Controller/ ContentHubReindexTest.php - Test the reExportEntities function.
File
- src/
Controller/ ContentHubReindex.php, line 306
Class
- ContentHubReindex
- Class for reindexing Content Hub content.
Namespace
Drupal\acquia_contenthub\ControllerCode
public static function reExportEntities($limit, &$context) {
// Sleep for 3 seconds before start processing.
sleep(3);
/** @var \Drupal\acquia_contenthub\Controller\ContentHubReindex $reindex */
$reindex = \Drupal::service('acquia_contenthub.acquia_contenthub_reindex');
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = $reindex
->getCountReExportEntities();
}
/** @var \Drupal\acquia_contenthub\EntityManager $entity_manager */
$entity_manager = \Drupal::service('acquia_contenthub.entity_manager');
$entities = $reindex
->getReExportEntities(0, $limit);
$messages = [];
foreach ($entities as $entity_item) {
$entity_type = $entity_item->entity_type;
$entity_id = $entity_item->entity_id;
$entity = \Drupal::entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
$entity_manager
->enqueueCandidateEntity($entity);
// Storing Results and.
$context['results'][] = $entity_id;
$context['sandbox']['progress']++;
$messages[] = $reindex
->t('(type = @type, id = @id, uuid = @uuid)', [
'@type' => $entity_type,
'@id' => $entity_id,
'@uuid' => $entity_item->entity_uuid,
]);
}
$context['message'] = $reindex
->t('Exporting entities: @entities', [
'@entities' => implode(',', $messages),
]);
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}