diff --git a/src/Security/ExtendedUser.php b/src/Security/ExtendedUser.php
index 51d5e4f4..bccce2f4 100644
--- a/src/Security/ExtendedUser.php
+++ b/src/Security/ExtendedUser.php
@@ -29,7 +29,7 @@ abstract class ExtendedUser extends \Kdyby\Doctrine\Entities\BaseEntity
* @ORM\OneToOne(targetEntity="\Venne\Security\User", cascade={"all"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
*/
- protected $user;
+ private $user;
public function __construct()
{
diff --git a/src/System/Commands/InstallCommand.php b/src/System/Commands/InstallCommand.php
index e29d4e1f..9f756083 100755
--- a/src/System/Commands/InstallCommand.php
+++ b/src/System/Commands/InstallCommand.php
@@ -15,6 +15,7 @@
use Nette\Utils\Validators;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+use Tracy\Debugger;
use Venne\Security\DefaultType\User;
use Venne\Security\Permission;
use Venne\Security\Role;
@@ -84,36 +85,47 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}, false);
- $roles = array();
- foreach (array('guest' => null, 'authenticated' => 'guest', 'admin' => 'authenticated') as $name => $parent) {
+ $this->entityManager->beginTransaction();
+ try {
+ $roles = array();
+ foreach (array('guest' => null, 'authenticated' => 'guest', 'admin' => 'authenticated') as $name => $parent) {
- $output->writeln(sprintf('Creating role "%s"', $name));
+ $output->writeln(sprintf('Creating role "%s"', $name));
- $roles[$name] = $role = new Role;
- $role->setName($name);
+ $roles[$name] = $role = new Role;
+ $role->setName($name);
- if ($parent) {
- $role->setParent($roles[$parent]);
+ if ($parent) {
+ $role->setParent($roles[$parent]);
+ }
+
+ $this->entityManager->persist($role);
}
+ $this->entityManager->flush($roles);
- $this->entityManager->persist($role);
- }
- $this->entityManager->flush($roles);
+ $output->writeln('Setting permission for administrator');
- $output->writeln('Setting permission for administrator');
+ $permission = new Permission($roles['admin']);
+ $this->entityManager->persist($permission);
- $permission = new Permission($roles['admin']);
- $this->entityManager->persist($permission);
+ $output->writeln('Creating administrator account');
- $output->writeln('Creating administrator account');
+ $user = new User;
+ $user->getUser()->setPassword($password);
+ $user->getUser()->setEmail($email);
+ $user->getUser()->addRoleEntity($roles['admin']);
- $user = new User;
- $user->user->setPassword($password);
- $user->user->setEmail($email);
- $user->user->addRoleEntity($roles['admin']);
+ $this->entityManager->persist($user->getUser());
+ $this->entityManager->flush($user->getUser());
+ $this->entityManager->persist($user);
+ $this->entityManager->flush($user);
- $this->entityManager->persist($user);
- $this->entityManager->flush();
+ $this->entityManager->commit();
+ } catch (\Exception $e) {
+ $this->entityManager->rollback();
+
+ throw $e;
+ }
}
}