/**
* @param string $endpointName
*
* @return int
*/
public function fetchOrGenerateEndpointId($endpointName)
{
$endpointId = 0;
$this->connection->transactional(function (Connection $connection) use($endpointName, &$endpointId) {
$lookupHash = md5($endpointName);
$endpointRecord = $connection->executeQuery("SELECT * FROM {$this->endpointsTableName} WHERE lookup_hash = ?", [hex2bin($lookupHash)])->fetch(\PDO::FETCH_ASSOC);
if (!$endpointRecord) {
$connection->insert($this->endpointsTableName, ['lookup_hash' => hex2bin($lookupHash), 'name' => $endpointName]);
$endpointId = (int) $connection->lastInsertId();
} else {
$endpointId = (int) $endpointRecord['id'];
}
});
return $endpointId;
}