[Pkg-owncloud-commits] [owncloud] 21/215: Unify the output of the user commands and use DI

David Prévot taffit at moszumanska.debian.org
Tue May 5 01:01:15 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit eec92a16d639afdec72c2bd0c2f346774235c062
Author: Joas Schilling <nickvergessen at owncloud.com>
Date:   Thu Apr 23 12:40:13 2015 +0200

    Unify the output of the user commands and use DI
---
 core/command/user/add.php           |  2 +-
 core/command/user/delete.php        |  4 ++--
 core/command/user/lastseen.php      | 17 ++++++++++++++---
 core/command/user/report.php        | 16 ++++++++++++++--
 core/command/user/resetpassword.php |  9 +++++----
 core/register_command.php           |  8 ++++----
 6 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/core/command/user/add.php b/core/command/user/add.php
index 60c70bf..c52ec4d 100644
--- a/core/command/user/add.php
+++ b/core/command/user/add.php
@@ -119,7 +119,7 @@ class Add extends Command {
 		);
 
 		if ($user instanceof IUser) {
-			$output->writeln('The user "' . $user->getUID() . '" was created successfully');
+			$output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
 		} else {
 			$output->writeln('<error>An error occurred while creating the user</error>');
 			return 1;
diff --git a/core/command/user/delete.php b/core/command/user/delete.php
index 2db80da..8cac031 100644
--- a/core/command/user/delete.php
+++ b/core/command/user/delete.php
@@ -54,12 +54,12 @@ class Delete extends Command {
 	protected function execute(InputInterface $input, OutputInterface $output) {
 		$user = $this->userManager->get($input->getArgument('uid'));
 		if (is_null($user)) {
-			$output->writeln('User does not exist');
+			$output->writeln('<error>User does not exist</error>');
 			return;
 		}
 
 		if ($user->delete()) {
-			$output->writeln('The specified user was deleted');
+			$output->writeln('<info>The specified user was deleted</info>');
 			return;
 		}
 
diff --git a/core/command/user/lastseen.php b/core/command/user/lastseen.php
index 308b3c6..92fcb1d 100644
--- a/core/command/user/lastseen.php
+++ b/core/command/user/lastseen.php
@@ -22,12 +22,24 @@
 
 namespace OC\Core\Command\User;
 
+use OCP\IUserManager;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Input\InputArgument;
 
 class LastSeen extends Command {
+	/** @var IUserManager */
+	protected $userManager;
+
+	/**
+	 * @param IUserManager $userManager
+	 */
+	public function __construct(IUserManager $userManager) {
+		$this->userManager = $userManager;
+		parent::__construct();
+	}
+
 	protected function configure() {
 		$this
 			->setName('user:lastseen')
@@ -40,10 +52,9 @@ class LastSeen extends Command {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
-		$userManager = \OC::$server->getUserManager();
-		$user = $userManager->get($input->getArgument('uid'));
+		$user = $this->userManager->get($input->getArgument('uid'));
 		if(is_null($user)) {
-			$output->writeln('User does not exist');
+			$output->writeln('<error>User does not exist</error>');
 			return;
 		}
 
diff --git a/core/command/user/report.php b/core/command/user/report.php
index 13bb5df..5d89c0a 100644
--- a/core/command/user/report.php
+++ b/core/command/user/report.php
@@ -23,11 +23,23 @@
 
 namespace OC\Core\Command\User;
 
+use OCP\IUserManager;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Report extends Command {
+	/** @var IUserManager */
+	protected $userManager;
+
+	/**
+	 * @param IUserManager $userManager
+	 */
+	public function __construct(IUserManager $userManager) {
+		$this->userManager = $userManager;
+		parent::__construct();
+	}
+
 	protected function configure() {
 		$this
 			->setName('user:report')
@@ -35,6 +47,7 @@ class Report extends Command {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
+		/** @var \Symfony\Component\Console\Helper\TableHelper $table */
 		$table = $this->getHelperSet()->get('table');
 		$table->setHeaders(array('User Report', ''));
 		$userCountArray = $this->countUsers();
@@ -61,8 +74,7 @@ class Report extends Command {
 	}
 
 	private function countUsers() {
-		$userManager = \OC::$server->getUserManager();
-		return $userManager->countUsers();
+		return $this->userManager->countUsers();
 	}
 
 	private function countUserDirectories() {
diff --git a/core/command/user/resetpassword.php b/core/command/user/resetpassword.php
index 3e16c8f..7c40559 100644
--- a/core/command/user/resetpassword.php
+++ b/core/command/user/resetpassword.php
@@ -23,6 +23,7 @@
 
 namespace OC\Core\Command\User;
 
+use OCP\IUserManager;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputArgument;
@@ -31,10 +32,10 @@ use Symfony\Component\Console\Output\OutputInterface;
 
 class ResetPassword extends Command {
 
-	/** @var \OC\User\Manager */
+	/** @var IUserManager */
 	protected $userManager;
 
-	public function __construct(\OC\User\Manager $userManager) {
+	public function __construct(IUserManager $userManager) {
 		$this->userManager = $userManager;
 		parent::__construct();
 	}
@@ -60,10 +61,10 @@ class ResetPassword extends Command {
 	protected function execute(InputInterface $input, OutputInterface $output) {
 		$username = $input->getArgument('user');
 
-		/** @var $user \OC\User\User */
+		/** @var $user \OCP\IUser */
 		$user = $this->userManager->get($username);
 		if (is_null($user)) {
-			$output->writeln("<error>There is no user called " . $username . "</error>");
+			$output->writeln('<error>User does not exist</error>');
 			return 1;
 		}
 
diff --git a/core/register_command.php b/core/register_command.php
index 701fb10..75c0245 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -42,11 +42,11 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
 	$application->add(new OC\Core\Command\App\Enable());
 	$application->add(new OC\Core\Command\App\ListApps());
 	$application->add(new OC\Core\Command\Maintenance\Repair($repair, \OC::$server->getConfig()));
-	$application->add(new OC\Core\Command\User\Report());
-	$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
-	$application->add(new OC\Core\Command\User\LastSeen());
-	$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
 	$application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
+	$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
+	$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
+	$application->add(new OC\Core\Command\User\Report(\OC::$server->getUserManager()));
+	$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
 	$application->add(new OC\Core\Command\Background\Cron(\OC::$server->getConfig()));
 	$application->add(new OC\Core\Command\Background\WebCron(\OC::$server->getConfig()));
 	$application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig()));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list