Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2021-03-02 23:46:51 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2021-03-02 23:46:51 +0300
commitdc7eb2bd85dbf2d43dcabd15b6f5ecdd65c6cb6e (patch)
treee344b66abd6686fecb8fc63bd8fb5d404db7e578 /apps/provisioning_api
parentef5389603c79df944ec5d0573e6e745c22c213e3 (diff)
LoggerInterface for provisioning API Controllers
Sweep swoop swaap swuup away with the deprecated stuff Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/lib/Controller/GroupsController.php6
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php61
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php6
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php19
4 files changed, 49 insertions, 43 deletions
diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php
index 0f37b63caa1..d91f5892f05 100644
--- a/apps/provisioning_api/lib/Controller/GroupsController.php
+++ b/apps/provisioning_api/lib/Controller/GroupsController.php
@@ -42,16 +42,16 @@ use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
+use Psr\Log\LoggerInterface;
class GroupsController extends AUserData {
- /** @var ILogger */
+ /** @var LoggerInterface */
private $logger;
public function __construct(string $appName,
@@ -62,7 +62,7 @@ class GroupsController extends AUserData {
IUserSession $userSession,
AccountManager $accountManager,
IFactory $l10nFactory,
- ILogger $logger) {
+ LoggerInterface $logger) {
parent::__construct($appName,
$request,
$userManager,
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 34c0135485f..9b249a9db5f 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -60,7 +60,6 @@ use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -70,6 +69,7 @@ use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use Psr\Log\LoggerInterface;
class UsersController extends AUserData {
@@ -77,7 +77,7 @@ class UsersController extends AUserData {
private $appManager;
/** @var IURLGenerator */
protected $urlGenerator;
- /** @var ILogger */
+ /** @var LoggerInterface */
private $logger;
/** @var IFactory */
protected $l10nFactory;
@@ -101,7 +101,7 @@ class UsersController extends AUserData {
IUserSession $userSession,
AccountManager $accountManager,
IURLGenerator $urlGenerator,
- ILogger $logger,
+ LoggerInterface $logger,
IFactory $l10nFactory,
NewUserMailHelper $newUserMailHelper,
FederatedShareProviderFactory $federatedShareProviderFactory,
@@ -417,36 +417,40 @@ class UsersController extends AUserData {
} catch (\Exception $e) {
// Mail could be failing hard or just be plain not configured
// Logging error as it is the hardest of the two
- $this->logger->logException($e, [
- 'message' => "Unable to send the invitation mail to $email",
- 'level' => ILogger::ERROR,
- 'app' => 'ocs_api',
- ]);
+ $this->logger->error("Unable to send the invitation mail to $email",
+ [
+ 'app' => 'ocs_api',
+ 'exception' => $e,
+ ]
+ );
}
}
}
return new DataResponse(['id' => $userid]);
} catch (HintException $e) {
- $this->logger->logException($e, [
- 'message' => 'Failed addUser attempt with hint exception.',
- 'level' => ILogger::WARN,
- 'app' => 'ocs_api',
- ]);
+ $this->logger->warning('Failed addUser attempt with hint exception.',
+ [
+ 'app' => 'ocs_api',
+ 'exception' => $e,
+ ]
+ );
throw new OCSException($e->getHint(), 107);
} catch (OCSException $e) {
- $this->logger->logException($e, [
- 'message' => 'Failed addUser attempt with ocs exeption.',
- 'level' => ILogger::ERROR,
- 'app' => 'ocs_api',
- ]);
+ $this->logger->warning('Failed addUser attempt with ocs exeption.',
+ [
+ 'app' => 'ocs_api',
+ 'exception' => $e,
+ ]
+ );
throw $e;
} catch (\Exception $e) {
- $this->logger->logException($e, [
- 'message' => 'Failed addUser attempt with exception.',
- 'level' => ILogger::ERROR,
- 'app' => 'ocs_api',
- ]);
+ $this->logger->error('Failed addUser attempt with exception.',
+ [
+ 'app' => 'ocs_api',
+ 'exception' => $e
+ ]
+ );
throw new OCSException('Bad request', 101);
}
}
@@ -1047,11 +1051,12 @@ class UsersController extends AUserData {
$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
} catch (\Exception $e) {
- $this->logger->logException($e, [
- 'message' => "Can't send new user mail to $email",
- 'level' => ILogger::ERROR,
- 'app' => 'settings',
- ]);
+ $this->logger->error("Can't send new user mail to $email",
+ [
+ 'app' => 'settings',
+ 'exception' => $e,
+ ]
+ );
throw new OCSException('Sending email failed', 102);
}
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index bb8ec854390..0624c9e0b75 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -37,13 +37,13 @@ use OC\User\NoUserException;
use OCA\Provisioning_API\Controller\GroupsController;
use OCP\Accounts\IAccountManager;
use OCP\IConfig;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\UserInterface;
+use Psr\Log\LoggerInterface;
class GroupsControllerTest extends \Test\TestCase {
@@ -59,7 +59,7 @@ class GroupsControllerTest extends \Test\TestCase {
protected $userSession;
/** @var AccountManager|\PHPUnit\Framework\MockObject\MockObject */
protected $accountManager;
- /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
/** @var SubAdmin|\PHPUnit\Framework\MockObject\MockObject */
protected $subAdminManager;
@@ -78,7 +78,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->accountManager = $this->createMock(AccountManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->subAdminManager = $this->createMock(SubAdmin::class);
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 10f5a4841d4..3130fce3e9c 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -56,7 +56,6 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUser;
@@ -68,6 +67,7 @@ use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\Security\ISecureRandom;
use OCP\UserInterface;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class UsersControllerTest extends TestCase {
@@ -82,7 +82,7 @@ class UsersControllerTest extends TestCase {
protected $groupManager;
/** @var IUserSession|MockObject */
protected $userSession;
- /** @var ILogger|MockObject */
+ /** @var LoggerInterface|MockObject */
protected $logger;
/** @var UsersController|MockObject */
protected $api;
@@ -113,7 +113,7 @@ class UsersControllerTest extends TestCase {
$this->appManager = $this->createMock(IAppManager::class);
$this->groupManager = $this->createMock(Manager::class);
$this->userSession = $this->createMock(IUserSession::class);
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->request = $this->createMock(IRequest::class);
$this->accountManager = $this->createMock(AccountManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
@@ -715,12 +715,13 @@ class UsersControllerTest extends TestCase {
->will($this->throwException($exception));
$this->logger
->expects($this->once())
- ->method('logException')
- ->with($exception, [
- 'message' => 'Failed addUser attempt with exception.',
- 'level' => ILogger::ERROR,
- 'app' => 'ocs_api',
- ]);
+ ->method('error')
+ ->with('Failed addUser attempt with exception.',
+ [
+ 'app' => 'ocs_api',
+ 'exception' => $exception
+ ]
+ );
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();