I have an entity named Theme, its name is not the Id, but should be indexed and unique :
/**
* @Entity @Table(name="themes",
* uniqueConstraints={@UniqueConstraint(name="theme_unique",columns={"name"})},
* indexes={@Index(name="theme_idx", columns={"name"})})
*/
class Theme {...}
I create a new theme with an existing name. This delivers an error, the script stops. How should I fetch that error and continue the script?
function CreateTheme($newThemeName) {
//$theme = $this->FindByThemeName ( $newThemeName );
//if (! $theme) {
$theme = new Theme ();
$theme->setName ( $newThemeName );
$theme->setIsActive ( false );
$theme->setIsDefault ( false );
$this->entityManager->persist ( $theme );
$this->entityManager->flush ();
return $theme;
//} else {
// $this->error = "Error in flush was avoided (name not being unique)!";
// return null;
//}