public function addHistory(Identifier $identifier, $state, $message = null, $is_exception = false)
{
$connection = $this->getConnection();
$prefix = $this->getPrefix();
try {
$query = 'INSERT INTO ' . $prefix . 'statemachine_history
(machine, entity_id, state, message, changetime, exception)
VALUES
(:machine, :entity_id, :state, :message, :timestamp, :exception)';
$statement = $connection->prepare($query);
$machine = $identifier->getMachine();
$entity_id = $identifier->getEntityId();
$timestamp = $this->getTimestampForDriver();
$is_exception = $this->getBooleanForDriver($is_exception);
$statement->bindParam(":machine", $machine);
$statement->bindParam(":entity_id", $entity_id);
$statement->bindParam(":state", $state);
if ($message) {
if (is_string($message)) {
$info = new \stdClass();
$info->message = $message;
$message = $info;
}
//always json encode it so we can pass objects as the message and store it
$message = json_encode($message);
}
$statement->bindParam(":message", $message);
$statement->bindParam(":timestamp", $timestamp);
$statement->bindParam(":exception", $is_exception);
$result = $statement->execute();
if ($result === false) {
throw new Exception($this->getErrorInfo($statement));
}
} catch (\Exception $e) {
throw new Exception(sprintf('query for updating state failed: [%s]', $e->getMessage()), Exception::PERSISTENCE_LAYER_EXCEPTION);
}
}