Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f88c462 authored by Ronak Patel's avatar Ronak Patel
Browse files

added try-catch at function level

parent fb18af42
Loading
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@ declare(strict_types=1);

namespace OCA\EcloudAccounts\Command;

use Exception;
use OCA\EcloudAccounts\AppInfo\Application;
use OCA\EcloudAccounts\Service\UserService;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
@@ -16,10 +18,12 @@ class MapActiveAttributetoLDAP extends Command {
	private OutputInterface $commandOutput;
	private IUserManager $userManager;
	private $userService;
	private $logger;

	public function __construct(IUserManager $userManager, UserService $userService) {
	public function __construct(IUserManager $userManager, ILogger $logger, UserService $userService) {
		$this->userManager = $userManager;
		$this->userService = $userService;
		$this->logger = $logger;
		parent::__construct();
	}

@@ -36,7 +40,11 @@ class MapActiveAttributetoLDAP extends Command {
				if ($this->isUserValid($user)) {
					$username = $user->getUID();
					$isEnabled = $user->isEnabled() ? true : false;
					try {
						$this->userService->mapActiveAttributesInLDAP($username, $isEnabled);
					} catch (Exception $e) {
						$this->logger->error('Failed to update LDAP attributes for user: ' . $username, ['exception' => $e]);
					}
				}
			});
			$this->commandOutput->writeln('Active attributes mapped successfully.');
+5 −1
Original line number Diff line number Diff line
@@ -68,7 +68,11 @@ class UserChangedListener implements IEventListener {
		/** @var mixed $newValue */
		$newValue = $event->getValue();
		if ($feature === self::ENABLED_FEATURE) {
			try {
				$this->userService->mapActiveAttributesInLDAP($username, $newValue);
			} catch (Exception $e) {
				$this->logger->error('Failed to update LDAP attributes for user: ' . $username, ['exception' => $e]);
			}
		}
	}