Skip to content

Commit

Permalink
Fixed install command
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz committed Oct 12, 2014
1 parent 0948b51 commit bc78966
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Security/ExtendedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
52 changes: 32 additions & 20 deletions src/System/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "<info>%s</info>"', $name));
$output->writeln(sprintf('Creating role "<info>%s</info>"', $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;
}
}

}

0 comments on commit bc78966

Please sign in to comment.