Skip to content

Commit fedf85b

Browse files
committed
[BF] Better error handling for dup alias - fixes #260
1 parent c410c1b commit fedf85b

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

application/controllers/MailboxController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,18 @@ public function addAction()
357357
);
358358

359359
$this->notify( 'mailbox', 'add', 'addPreflush', $this );
360-
$this->getD2EM()->flush();
360+
361+
try {
362+
$this->getD2EM()->flush();
363+
} catch( Doctrine\DBAL\Exception\UniqueConstraintViolationException $e ) {
364+
if( strpos( $e->getMessage(), 'occurred while executing \'INSERT INTO alias' ) > 0 ) {
365+
$this->addMessage(_("An alias already exists for the mailbox you are trying to create. Please delete the alias first."), OSS_Message::ERROR);
366+
return;
367+
}
368+
throw $e;
369+
}
370+
371+
361372
$this->notify( 'mailbox', 'add', 'addPostflush', $this, [ 'options' => $this->_options ] );
362373

363374
if( $form->getValue( 'welcome_email' ) )

0 commit comments

Comments
 (0)