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

addHistory() protected method

{@inheritDoc}
protected addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false )
$identifier izzum\statemachine\Identifier
    protected function addHistory(Identifier $identifier, $state, $message = null, $is_exception = false)
    {
        //find in history from mongo shell: db.history.find({"machine" : "test-machine", "state": "done"},{entity_id: 1, state: 1, datetime: 1})
        try {
            $data = new \stdClass();
            $data->entity_id = $identifier->getEntityId();
            $data->machine = $identifier->getMachine();
            $data->state = $state;
            if ($message) {
                if (is_string($message)) {
                    $info = new \stdClass();
                    $info->message = $message;
                    $message = $info;
                }
            }
            $data->message = $message;
            $timestamp = time();
            $data->timestamp = $timestamp;
            $data->datetime = date('Y-m-d H:i:s', $timestamp);
            //ISO_8601
            $data->is_exception = $is_exception;
            //insert into the 'history' collection
            $this->getClient()->izzum->history->insert($data);
        } catch (\Exception $e) {
            throw new Exception(sprintf('adding history failed: [%s]', $e->getMessage()), Exception::PERSISTENCE_LAYER_EXCEPTION);
        }
    }