From 2bbcfc88c14be0ad0070fa00ca4757162b6e6aa7 Mon Sep 17 00:00:00 2001 From: Baptiste Fotia Date: Thu, 2 Nov 2023 11:51:34 +0100 Subject: [PATCH] feature(php): Add logs for the command lines I added logs for the command lines. Signed-off-by: Baptiste Fotia --- lib/Commands/Create.php | 10 ++++++++++ lib/Commands/Import.php | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Commands/Create.php b/lib/Commands/Create.php index 1f386ca84..cfb799b7b 100644 --- a/lib/Commands/Create.php +++ b/lib/Commands/Create.php @@ -29,6 +29,7 @@ use OCA\Workspace\Space\SpaceManager; use OCA\Workspace\User\UserFinder; use OCA\Workspace\User\UserPresenceChecker; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -43,6 +44,7 @@ class Create extends Command { public function __construct(private SpaceManager $spaceManager, private AdminGroup $adminGroup, + private LoggerInterface $logger, private UserPresenceChecker $userChecker, private UserFinder $userFinder) { parent::__construct(); @@ -87,11 +89,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($input->hasParameterOption('--user-workspace-manager')) { $pattern = $input->getOption('user-workspace-manager'); if (!$this->userChecker->checkUserExist($pattern)) { + $this->logger->error("The $pattern user or email is not exist."); throw new \Exception("The $pattern user or email is not exist."); } } if ($this->checkValueFormatOptionIsValid($input)) { + $this->logger->error( + sprintf( + "The value is not valid.\nPlease, define an option valid : %s", + implode(', ', self::OPTION_FORMAT_AVAILABLE) + ) + ); throw new \Exception( sprintf( "The value is not valid.\nPlease, define an option valid : %s", @@ -117,6 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } + $this->logger->info(sprintf("The workspace created with %s", $outputMessage)); $output->writeln($outputMessage); return 0; diff --git a/lib/Commands/Import.php b/lib/Commands/Import.php index 3604b275f..267198e69 100644 --- a/lib/Commands/Import.php +++ b/lib/Commands/Import.php @@ -34,6 +34,7 @@ use OCP\IGroupManager; use OCP\IRequest; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -42,15 +43,16 @@ class Import extends Command { public function __construct( + private AdminGroup $adminGroup, + private Csv $csvCreatingWorkspaces, private IGroupManager $groupManager, private IRequest $request, private IUserManager $userManager, - private Csv $csvCreatingWorkspaces, private SpaceManager $spaceManager, - private AdminGroup $adminGroup, - private UserPresenceChecker $userChecker, private UserFinder $userFinder, - private WorkspaceCheckService $workspaceCheckService) { + private UserPresenceChecker $userChecker, + private WorkspaceCheckService $workspaceCheckService, + private LoggerInterface $logger) { parent::__construct(); } @@ -58,10 +60,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $path = realpath($input->getArgument('path')); if (!$this->csvCreatingWorkspaces->isCsvFile($path)) { + $this->logger->critical("It's not a csv file. Your file is a " . (string)$this->csvCreatingWorkspaces->getMimeType($path) . " mimetype."); throw new \Exception("It's not a csv file. Your file is a " . (string)$this->csvCreatingWorkspaces->getMimeType($path) . " mimetype."); } if (!$this->csvCreatingWorkspaces->hasProperHeader($path)) { + $this->logger->error(sprintf( + "No respect the glossary headers. " + . "Please, you must define these 2 headers : " + . "%s : To specify the workspace name; " + . "%s : To specify the user's uid or email address.", + implode(", ", Csv::WORKSPACE_FIELD), + implode(", ", Csv::USER_FIELD) + )); throw new \Exception( sprintf( "No respect the glossary headers.\n\n" @@ -79,6 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $spacenamesWithCharacterSpecials = $this->getWorkspacesWithCharacterSpecials($dataFormated); if (!is_null($spacenamesWithCharacterSpecials)) { + $this->logger->error($spacenamesWithCharacterSpecials); throw new \Exception($spacenamesWithCharacterSpecials); } @@ -86,6 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $message .= $this->getUsersArentExist($dataFormated); if (!empty($message)) { + $this->logger->error($message); throw new \Exception($message); } @@ -98,6 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->adminGroup->addUser($user, $groupname); } + $this->logger->info("The import is done."); $output->writeln("The import is done."); return 0;