Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add guard:user:groups-list task
  • Loading branch information
thePanz committed Jan 17, 2018
commit f65675f09cf35c0e6926e226ebb98d42f6076b09
69 changes: 69 additions & 0 deletions lib/task/sfGuardUserGroupsListTask.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Add a permission to a user.
*
* @package symfony
* @subpackage task
* @author Fabien Potencier <[email protected]>
* @version SVN: $Id$
*/
class sfGuardUserGroupsListTask extends sfBaseTask
{
/**
* @see sfTask
*/
protected function configure()
{
$this->addArguments(array(
new sfCommandArgument('username', sfCommandArgument::REQUIRED, 'The user name'),
));

$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
));

$this->name = 'user:groups-list';
$this->namespace = 'guard';
$this->briefDescription = 'List the Groups associated to a user';

$this->detailedDescription = <<<EOF
The [guard:user:groups-list|INFO] task adds a permission to a user:

[./symfony guard:user:group-list fabien|INFO]

The user must exist in the database.
EOF;
}

/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);

$model = sfConfig::get('app_sf_guard_user_model', 'sfGuardUser');

/** @var sfGuardUser $user */
$user = Doctrine_Core::getTable($model)->findOneByUsername($arguments['username']);
if (!$user)
{
throw new sfCommandException(sprintf('User "%s" does not exist.', $arguments['username']));
}

$this->logSection('guard', sprintf('Listing groups associated to user %s', $arguments['username']));
foreach ($user->getGroupNames() as $groupName) {
$this->logSection('guard', sprintf(' - %s', $groupName));
}
}
}