public function ContentHubReindex::setExportedEntitiesToReindex in Acquia Content Hub 8
Set Exported Entities to be Re-indexed.
Parameters
string $entity_type_id: The Entity type.
string $bundle_id: The Entity bundle.
Return value
bool TRUE if subscription can be re-indexed, FALSE otherwise.
File
- src/
Controller/ ContentHubReindex.php, line 203
Class
- ContentHubReindex
- Class for reindexing Content Hub content.
Namespace
Drupal\acquia_contenthub\ControllerCode
public function setExportedEntitiesToReindex($entity_type_id = NULL, $bundle_id = NULL) {
// Set exported entities with the REINDEX flag.
$this->contentHubEntitiesTracking
->setExportedEntitiesForReindex($entity_type_id, $bundle_id);
// Collect all entities that were flagged for REINDEX.
$entities = $this->contentHubEntitiesTracking
->getEntitiesToReindex();
if (count($entities) == 0) {
$this
->setReindexStateNone();
return FALSE;
}
// Delete all entities set to reindex from Content Hub.
foreach ($entities as $entity) {
$this->clientManager
->createRequest('deleteEntity', [
$entity->entity_uuid,
]);
}
// We have a sent a lot of delete requests to Content Hub, wait 10 seconds
// before proceeding to reindex the subscription.
sleep(10);
// Now reindex subscription.
if ($response = $this->clientManager
->createRequest('reindex')) {
if (isset($response['success']) && $response['success'] === TRUE) {
// Saving Reindexing State.
$this
->setReindexStateSent();
return TRUE;
}
}
// The reindex request has failed, then set the reindex state as failed.
$this
->setReindexStateFailed();
return FALSE;
}