Add an option to occ ldap:showremnants to output a json encoded array for use in scripts and other tools.

This commit is contained in:
Stephen Colebrook 2015-12-22 16:28:32 -05:00
parent 5e3710d746
commit 064580a56e
1 changed files with 15 additions and 11 deletions

View File

@ -24,6 +24,7 @@ namespace OCA\user_ldap\Command;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use OCA\user_ldap\lib\user\DeletedUsersIndex; use OCA\user_ldap\lib\user\DeletedUsersIndex;
@ -50,7 +51,7 @@ class ShowRemnants extends Command {
$this $this
->setName('ldap:show-remnants') ->setName('ldap:show-remnants')
->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.') ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.')
; ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.');
} }
/** /**
@ -70,18 +71,21 @@ class ShowRemnants extends Command {
$hAS = $user->getHasActiveShares() ? 'Y' : 'N'; $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
$lastLogin = ($user->getLastLogin() > 0) ? $lastLogin = ($user->getLastLogin() > 0) ?
$this->dateFormatter->formatDate($user->getLastLogin()) : '-'; $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
$rows[] = array( $rows[] = array('ocName' => $user->getOCName(),
$user->getOCName(), 'displayName' => $user->getDisplayName(),
$user->getDisplayName(), 'uid' => $user->getUid(),
$user->getUid(), 'dn' => $user->getDN(),
$user->getDN(), 'lastLogin' => $lastLogin,
$lastLogin, 'homePath' => $user->getHomePath(),
$user->getHomePath(), 'sharer' => $hAS
$hAS
); );
} }
$table->setRows($rows); if ($input->getOption('json')) {
$table->render($output); $output->writeln(json_encode($rows));
} else {
$table->setRows($rows);
$table->render($output);
}
} }
} }