izzum\statemachine\persistence\MongoDB::updateState PHP Method

updateState() protected method

{@inheritDoc}
protected updateState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier
    protected function updateState(Identifier $identifier, $state, $message = null)
    {
        try {
            $client = $this->getClient();
            //find the state
            //https://php.net/manual/en/mongocollection.findone.php
            $query = array("machine" => $identifier->getMachine(), "entity_id" => $identifier->getEntityId());
            $data = $client->izzum->states->findOne($query);
            if ($data) {
                //update the state and timestamp
                //$_id = $data['_id'];
                $data['timestamp'] = time();
                $data['state'] = $state;
                //save into the 'states' collection
                //https://php.net/manual/en/mongocollection.save.php
                $client->izzum->states->save($data);
            } else {
                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);
            }
        } catch (\Exception $e) {
            throw new Exception(sprintf('updating state failed: [%s]', $e->getMessage()), Exception::PERSISTENCE_LAYER_EXCEPTION);
        }
    }