Skip to content

Commit

Permalink
chore(apps): Apply "use" auto-import of Nextcloud classes to all apps
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Sep 26, 2024
1 parent ec5b140 commit 63099de
Show file tree
Hide file tree
Showing 315 changed files with 2,157 additions and 1,662 deletions.
17 changes: 9 additions & 8 deletions apps/admin_audit/lib/Actions/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -41,7 +42,7 @@ public function read(BeforeNodeReadEvent $event): void {
'path' => mb_substr($node->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file read: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand All @@ -63,7 +64,7 @@ public function beforeRename(BeforeNodeRenamedEvent $event): void {
$source = $event->getSource();
$this->renamedNodes[$source->getId()] = $source;
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file rename: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand All @@ -85,7 +86,7 @@ public function afterRename(NodeRenamedEvent $event): void {
'newpath' => mb_substr($target->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file rename: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand All @@ -111,7 +112,7 @@ public function create(NodeCreatedEvent $event): void {
'path' => mb_substr($event->getNode()->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file create: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand Down Expand Up @@ -140,7 +141,7 @@ public function copy(NodeCopiedEvent $event): void {
'newpath' => mb_substr($event->getTarget()->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file copy: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand All @@ -165,7 +166,7 @@ public function write(BeforeNodeWrittenEvent $event): void {
'path' => mb_substr($node->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file write: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand Down Expand Up @@ -193,7 +194,7 @@ public function update(NodeWrittenEvent $event): void {
'path' => mb_substr($event->getNode()->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file update: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand All @@ -217,7 +218,7 @@ public function delete(NodeDeletedEvent $event): void {
'path' => mb_substr($event->getNode()->getInternalPath(), 5),
];
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file delete: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand Down
3 changes: 2 additions & 1 deletion apps/admin_audit/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use OCP\Share;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\SystemTag\ManagerEvent;
use OCP\User\Events\BeforeUserLoggedInEvent;
use OCP\User\Events\BeforeUserLoggedOutEvent;
use OCP\User\Events\PasswordUpdatedEvent;
Expand Down Expand Up @@ -157,7 +158,7 @@ private function sharingLegacyHooks(IAuditLogger $logger): void {

private function tagHooks(IAuditLogger $logger,
IEventDispatcher $eventDispatcher): void {
$eventDispatcher->addListener(\OCP\SystemTag\ManagerEvent::EVENT_CREATE, function (\OCP\SystemTag\ManagerEvent $event) use ($logger): void {
$eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, function (ManagerEvent $event) use ($logger): void {

Check notice

Code scanning / Psalm

DeprecatedConstant Note

Constant OCP\SystemTag\ManagerEvent::EVENT_CREATE is deprecated
$tagActions = new TagManagement($logger);
$tagActions->createTag($event->getTag());
});
Expand Down
3 changes: 2 additions & 1 deletion apps/admin_audit/lib/Listener/FileEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -47,7 +48,7 @@ private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void {
array_keys($params)
);
} catch (InvalidPathException|NotFoundException $e) {
\OCP\Server::get(LoggerInterface::class)->error(
Server::get(LoggerInterface::class)->error(
'Exception thrown in file preview: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Util;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -276,7 +277,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
private function mapUid($uid) {
// FIXME this should be a method in the user management instead
$this->logger->debug('shareWith before, ' . $uid, ['app' => $this->appName]);
\OCP\Util::emitHook(
Util::emitHook(
'\OCA\Files_Sharing\API\Server2Server',
'preLoginNameUsedAsUserName',
['uid' => &$uid]
Expand Down
4 changes: 2 additions & 2 deletions apps/comments/tests/Unit/Notification/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ListenerTest extends TestCase {
protected function setUp(): void {
parent::setUp();

$this->notificationManager = $this->createMock(\OCP\Notification\IManager::class);
$this->userManager = $this->createMock(\OCP\IUserManager::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->userManager = $this->createMock(IUserManager::class);

$this->listener = new Listener(
$this->notificationManager,
Expand Down
9 changes: 5 additions & 4 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

use OCA\Dashboard\Service\DashboardService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\FeaturePolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IIconWidget;
Expand All @@ -24,6 +24,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Util;

#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class DashboardController extends Controller {
Expand All @@ -49,8 +50,8 @@ public function __construct(
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/')]
public function index(): TemplateResponse {
\OCP\Util::addStyle('dashboard', 'dashboard');
\OCP\Util::addScript('dashboard', 'main', 'theming');
Util::addStyle('dashboard', 'dashboard');
Util::addScript('dashboard', 'main', 'theming');

$widgets = array_map(function (IWidget $widget) {
return [
Expand All @@ -76,7 +77,7 @@ public function index(): TemplateResponse {
]);

// For the weather widget we should allow the geolocation
$featurePolicy = new Http\FeaturePolicy();
$featurePolicy = new FeaturePolicy();
$featurePolicy->addAllowedGeoLocationDomain('\'self\'');
$response->setFeaturePolicy($featurePolicy);

Expand Down
23 changes: 15 additions & 8 deletions apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarRoot;
use OCA\DAV\CalDAV\DefaultCalendarValidator;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Schedule\Plugin;
use OCA\DAV\CalDAV\Security\RateLimitingPlugin;
use OCA\DAV\CalDAV\Sharing\Backend;
use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin;
use OCA\DAV\Connector\LegacyDAVACL;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
use OCA\DAV\Connector\Sabre\Principal;
use OCP\Accounts\IAccountManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;

$authBackend = new Auth(
Expand All @@ -35,7 +42,7 @@
\OC::$server->getShareManager(),
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
\OC::$server->query(ProxyMapper::class),

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OC\ServerContainer::query has been marked as deprecated
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig(),
\OC::$server->getL10NFactory(),
Expand All @@ -45,8 +52,8 @@
$userManager = \OC::$server->getUserManager();
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->get(LoggerInterface::class);
$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
$config = \OC::$server->get(\OCP\IConfig::class);
$dispatcher = \OC::$server->get(IEventDispatcher::class);
$config = \OC::$server->get(IConfig::class);

$calDavBackend = new CalDavBackend(
$db,
Expand All @@ -56,7 +63,7 @@
$logger,
$dispatcher,
$config,
OC::$server->get(\OCA\DAV\CalDAV\Sharing\Backend::class),
OC::$server->get(Backend::class),
true
);

Expand Down Expand Up @@ -93,14 +100,14 @@

$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class)));
$server->addPlugin(new Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class)));

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OC\Server::getConfig has been marked as deprecated

if ($sendInvitations) {
$server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
$server->addPlugin(\OC::$server->query(IMipPlugin::class));

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OC\ServerContainer::query has been marked as deprecated
}
$server->addPlugin(new ExceptionLoggerPlugin('caldav', $logger));
$server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
$server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class));
$server->addPlugin(Server::get(RateLimitingPlugin::class));
$server->addPlugin(Server::get(CalDavValidatePlugin::class));

// And off we go!
$server->exec();
21 changes: 14 additions & 7 deletions apps/dav/appinfo/v1/carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
// Backends
use OC\KnownUser\KnownUserService;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\CardDAV\AddressBookRoot;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ImageExportPlugin;
use OCA\DAV\CardDAV\PhotoCache;
use OCA\DAV\CardDAV\Security\CardDavRateLimitingPlugin;
use OCA\DAV\CardDAV\Sharing\Backend;
use OCA\DAV\CardDAV\Validation\CardDavValidatePlugin;
use OCA\DAV\Connector\LegacyDAVACL;
use OCA\DAV\Connector\Sabre\Auth;
Expand All @@ -19,6 +23,9 @@
use OCA\DAV\Connector\Sabre\Principal;
use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
use Sabre\CardDAV\Plugin;

Expand All @@ -37,7 +44,7 @@
\OC::$server->getShareManager(),
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
\OC::$server->query(ProxyMapper::class),

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OC\ServerContainer::query has been marked as deprecated
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig(),
\OC::$server->getL10NFactory(),
Expand All @@ -48,8 +55,8 @@
$db,
$principalBackend,
\OC::$server->getUserManager(),
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class),
\OC::$server->get(IEventDispatcher::class),
\OC::$server->get(Backend::class),
);

$debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
Expand All @@ -59,7 +66,7 @@
$principalCollection->disableListing = !$debugging; // Disable listing

$pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
$addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(\OCP\IGroupManager::class));
$addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(IGroupManager::class));
$addressBookRoot->disableListing = !$debugging; // Disable listing

$nodes = [
Expand All @@ -84,13 +91,13 @@

$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
$server->addPlugin(new ImageExportPlugin(new PhotoCache(
\OC::$server->getAppDataDir('dav-photocache'),
\OC::$server->get(LoggerInterface::class)
)));
$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class)));
$server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class));
$server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class));
$server->addPlugin(Server::get(CardDavRateLimitingPlugin::class));
$server->addPlugin(Server::get(CardDavValidatePlugin::class));

// And off we go!
$server->exec();
Loading

0 comments on commit 63099de

Please sign in to comment.