public function processGetState(Identifier $identifier)
{
$state = null;
try {
//check if indexes exists every x times this method is called
$this->checkAndCreateIndexesIfNecessary(500);
//find the state
//https://php.net/manual/en/mongocollection.findone.php
$query = array("entity_id" => $identifier->getEntityId(), "machine" => $identifier->getMachine());
$data = $this->getClient()->izzum->states->findOne($query);
if ($data) {
$state = $data['state'];
}
} catch (\Exception $e) {
throw new Exception(sprintf('getting current state failed: [%s]', $e->getMessage()), Exception::PERSISTENCE_LAYER_EXCEPTION);
}
if (!$state) {
throw new Exception(sprintf('no state found for [%s]. Did you "$machine->add()" it to the persistence layer?', $identifier->getId(true)), Exception::PERSISTENCE_LAYER_EXCEPTION);
}
return $state;
}