public function create(Entity $entity)
{
$result = $this->shouldExecuteEvents($entity, 'before', 'create');
if (!$result) {
return false;
}
$queryBuilder = $this->database->createQueryBuilder();
$queryBuilder->insert('`' . $this->definition->getTable() . '`')->setValue('created_at', 'UTC_TIMESTAMP()')->setValue('updated_at', 'UTC_TIMESTAMP()')->setValue('version', 0);
$this->setValuesAndParameters($entity, $queryBuilder, 'setValue');
$id = $this->generateUUID();
if ($this->useUUIDs) {
$queryBuilder->setValue('`id`', '?');
$uuidI = count($this->getFormFields());
$queryBuilder->setParameter($uuidI, $id);
}
$queryBuilder->execute();
if (!$this->useUUIDs) {
$id = $this->database->lastInsertId();
}
$this->enrichEntityWithMetaData($id, $entity);
$this->saveMany($entity);
$this->shouldExecuteEvents($entity, 'after', 'create');
return true;
}