Skip to content

Commit

Permalink
feature(php): Add logs for the command lines
Browse files Browse the repository at this point in the history
I added logs for the command lines.

Signed-off-by: Baptiste Fotia <[email protected]>
  • Loading branch information
zak39 committed Nov 2, 2023
1 parent d761f59 commit 2bbcfc8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/Commands/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand Down
22 changes: 18 additions & 4 deletions lib/Commands/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,26 +43,36 @@
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();
}

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"
Expand All @@ -79,13 +90,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$spacenamesWithCharacterSpecials = $this->getWorkspacesWithCharacterSpecials($dataFormated);

if (!is_null($spacenamesWithCharacterSpecials)) {
$this->logger->error($spacenamesWithCharacterSpecials);
throw new \Exception($spacenamesWithCharacterSpecials);
}

$message = $this->getSpacenamesDuplicated($dataFormated);
$message .= $this->getUsersArentExist($dataFormated);

if (!empty($message)) {
$this->logger->error($message);
throw new \Exception($message);
}

Expand All @@ -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;
Expand Down

0 comments on commit 2bbcfc8

Please sign in to comment.