aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/Adapter.php20
-rw-r--r--lib/private/DB/AdapterOCI8.php2
-rw-r--r--lib/private/DB/AdapterPgSql.php2
-rw-r--r--lib/private/DB/Connection.php29
-rw-r--r--lib/private/Files/Config/MountProviderCollection.php116
-rw-r--r--lib/private/Files/Config/UserMountCache.php31
-rw-r--r--lib/private/Files/SetupManager.php12
-rw-r--r--lib/private/Files/Template/TemplateManager.php65
-rw-r--r--lib/private/PreviewManager.php8
-rw-r--r--lib/private/Repair.php3
-rw-r--r--lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php24
-rw-r--r--lib/private/Security/Bruteforce/Throttler.php26
-rw-r--r--lib/private/Server.php463
-rw-r--r--lib/private/Share20/ProviderFactory.php206
-rw-r--r--lib/private/User/LazyUser.php4
-rw-r--r--lib/private/User/User.php13
-rw-r--r--lib/private/legacy/OC_Helper.php5
-rw-r--r--lib/private/legacy/OC_Util.php3
18 files changed, 253 insertions, 779 deletions
diff --git a/lib/private/DB/Adapter.php b/lib/private/DB/Adapter.php
index edd8c1bf023..8f1b8e6d75f 100644
--- a/lib/private/DB/Adapter.php
+++ b/lib/private/DB/Adapter.php
@@ -28,25 +28,11 @@ class Adapter {
/**
* @param string $table name
*
- * @return int id of last insert statement, 0 in case there was no INSERT before or it failed to get the ID
+ * @return int id of last insert statement
* @throws Exception
*/
- public function lastInsertId($table, bool $allowRetry = true): int {
- $return = $this->conn->realLastInsertId($table);
- if ($return === 0 && $allowRetry) {
- /**
- * During a reconnect we are losing the connection and when the
- * realLastInsertId call is the one triggering the reconnect, it
- * does not return the ID. But inside the reconnect, we were able
- * to save the last insert id, so calling it a second time is going
- * to be successful.
- * We can not return the result on the initial call, as we are already
- * way deeper in the stack performing the actual database query on
- * the doctrine driver.
- */
- return $this->lastInsertId($table, false);
- }
- return $return;
+ public function lastInsertId($table) {
+ return (int)$this->conn->realLastInsertId($table);
}
/**
diff --git a/lib/private/DB/AdapterOCI8.php b/lib/private/DB/AdapterOCI8.php
index f5ad9f7c934..0a509090bca 100644
--- a/lib/private/DB/AdapterOCI8.php
+++ b/lib/private/DB/AdapterOCI8.php
@@ -8,7 +8,7 @@
namespace OC\DB;
class AdapterOCI8 extends Adapter {
- public function lastInsertId($table, bool $allowRetry = true): int {
+ public function lastInsertId($table) {
if (is_null($table)) {
throw new \InvalidArgumentException('Oracle requires a table name to be passed into lastInsertId()');
}
diff --git a/lib/private/DB/AdapterPgSql.php b/lib/private/DB/AdapterPgSql.php
index b321fcf4715..db48c81c2c5 100644
--- a/lib/private/DB/AdapterPgSql.php
+++ b/lib/private/DB/AdapterPgSql.php
@@ -9,7 +9,7 @@ namespace OC\DB;
class AdapterPgSql extends Adapter {
- public function lastInsertId($table, bool $allowRetry = true): int {
+ public function lastInsertId($table) {
$result = $this->conn->executeQuery('SELECT lastval()');
$val = $result->fetchOne();
$result->free();
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 4ba2d2a341d..96dd578b2ef 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -92,8 +92,6 @@ class Connection extends PrimaryReadReplicaConnection {
protected ShardConnectionManager $shardConnectionManager;
protected AutoIncrementHandler $autoIncrementHandler;
protected bool $isShardingEnabled;
- protected bool $disableReconnect = false;
- protected int $lastInsertId = 0;
public const SHARD_PRESETS = [
'filecache' => [
@@ -512,9 +510,9 @@ class Connection extends PrimaryReadReplicaConnection {
* because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
* columns or sequences.
*
- * @param ?string $name Name of the sequence object from which the ID should be returned.
+ * @param string $seqName Name of the sequence object from which the ID should be returned.
*
- * @return int the last inserted ID, 0 in case there was no INSERT before or it failed to get the ID
+ * @return int the last inserted ID.
* @throws Exception
*/
public function lastInsertId($name = null): int {
@@ -528,13 +526,8 @@ class Connection extends PrimaryReadReplicaConnection {
* @internal
* @throws Exception
*/
- public function realLastInsertId($seqName = null): int {
- if ($this->lastInsertId !== 0) {
- $lastInsertId = $this->lastInsertId;
- $this->lastInsertId = 0;
- return $lastInsertId;
- }
- return (int)parent::lastInsertId($seqName);
+ public function realLastInsertId($seqName = null) {
+ return parent::lastInsertId($seqName);
}
/**
@@ -903,23 +896,11 @@ class Connection extends PrimaryReadReplicaConnection {
if (
!isset($this->lastConnectionCheck[$this->getConnectionName()]) ||
time() <= $this->lastConnectionCheck[$this->getConnectionName()] + 30 ||
- $this->isTransactionActive() ||
- $this->disableReconnect
+ $this->isTransactionActive()
) {
return;
}
- if ($this->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
- /**
- * Before reconnecting we save the lastInsertId, so that if the reconnect
- * happens between the INSERT executeStatement() and the getLastInsertId call
- * we are able to return the correct result after all.
- */
- $this->disableReconnect = true;
- $this->lastInsertId = (int)parent::lastInsertId();
- $this->disableReconnect = false;
- }
-
try {
$this->_conn->query($this->getDriver()->getDatabasePlatform()->getDummySelectSQL());
$this->lastConnectionCheck[$this->getConnectionName()] = time();
diff --git a/lib/private/Files/Config/MountProviderCollection.php b/lib/private/Files/Config/MountProviderCollection.php
index 6a5407934c8..9d63184e05f 100644
--- a/lib/private/Files/Config/MountProviderCollection.php
+++ b/lib/private/Files/Config/MountProviderCollection.php
@@ -24,60 +24,43 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
use EmitterTrait;
/**
- * @var \OCP\Files\Config\IHomeMountProvider[]
+ * @var list<IHomeMountProvider>
*/
- private $homeProviders = [];
+ private array $homeProviders = [];
/**
- * @var \OCP\Files\Config\IMountProvider[]
+ * @var list<IMountProvider>
*/
- private $providers = [];
+ private array $providers = [];
- /** @var \OCP\Files\Config\IRootMountProvider[] */
- private $rootProviders = [];
+ /** @var list<IRootMountProvider> */
+ private array $rootProviders = [];
- /**
- * @var \OCP\Files\Storage\IStorageFactory
- */
- private $loader;
-
- /**
- * @var \OCP\Files\Config\IUserMountCache
- */
- private $mountCache;
-
- /** @var callable[] */
- private $mountFilters = [];
+ /** @var list<callable> */
+ private array $mountFilters = [];
- private IEventLogger $eventLogger;
-
- /**
- * @param \OCP\Files\Storage\IStorageFactory $loader
- * @param IUserMountCache $mountCache
- */
public function __construct(
- IStorageFactory $loader,
- IUserMountCache $mountCache,
- IEventLogger $eventLogger,
+ private IStorageFactory $loader,
+ private IUserMountCache $mountCache,
+ private IEventLogger $eventLogger,
) {
- $this->loader = $loader;
- $this->mountCache = $mountCache;
- $this->eventLogger = $eventLogger;
}
+ /**
+ * @return list<IMountPoint>
+ */
private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
$class = str_replace('\\', '_', get_class($provider));
$uid = $user->getUID();
$this->eventLogger->start('fs:setup:provider:' . $class, "Getting mounts from $class for $uid");
$mounts = $provider->getMountsForUser($user, $loader) ?? [];
$this->eventLogger->end('fs:setup:provider:' . $class);
- return $mounts;
+ return array_values($mounts);
}
/**
- * @param IUser $user
- * @param IMountProvider[] $providers
- * @return IMountPoint[]
+ * @param list<IMountProvider> $providers
+ * @return list<IMountPoint>
*/
private function getUserMountsForProviders(IUser $user, array $providers): array {
$loader = $this->loader;
@@ -90,10 +73,16 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
return $this->filterMounts($user, $mounts);
}
+ /**
+ * @return list<IMountPoint>
+ */
public function getMountsForUser(IUser $user): array {
return $this->getUserMountsForProviders($user, $this->providers);
}
+ /**
+ * @return list<IMountPoint>
+ */
public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
$providers = array_filter(
$this->providers,
@@ -102,7 +91,10 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
return $this->getUserMountsForProviders($user, $providers);
}
- public function addMountForUser(IUser $user, IMountManager $mountManager, ?callable $providerFilter = null) {
+ /**
+ * @return list<IMountPoint>
+ */
+ public function addMountForUser(IUser $user, IMountManager $mountManager, ?callable $providerFilter = null): array {
// shared mount provider gets to go last since it needs to know existing files
// to check for name collisions
$firstMounts = [];
@@ -135,18 +127,15 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
array_walk($lateMounts, [$mountManager, 'addMount']);
$this->eventLogger->end('fs:setup:add-mounts');
- return array_merge($lateMounts, $firstMounts);
+ return array_values(array_merge($lateMounts, $firstMounts));
}
/**
* Get the configured home mount for this user
*
- * @param \OCP\IUser $user
- * @return \OCP\Files\Mount\IMountPoint
* @since 9.1.0
*/
- public function getHomeMountForUser(IUser $user) {
- /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
+ public function getHomeMountForUser(IUser $user): IMountPoint {
$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
foreach ($providers as $homeProvider) {
if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
@@ -159,34 +148,36 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
/**
* Add a provider for mount points
- *
- * @param \OCP\Files\Config\IMountProvider $provider
*/
- public function registerProvider(IMountProvider $provider) {
+ public function registerProvider(IMountProvider $provider): void {
$this->providers[] = $provider;
$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
}
- public function registerMountFilter(callable $filter) {
+ public function registerMountFilter(callable $filter): void {
$this->mountFilters[] = $filter;
}
- private function filterMounts(IUser $user, array $mountPoints) {
- return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
+ /**
+ * @param list<IMountPoint> $mountPoints
+ * @return list<IMountPoint>
+ */
+ private function filterMounts(IUser $user, array $mountPoints): array {
+ return array_values(array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
foreach ($this->mountFilters as $filter) {
if ($filter($mountPoint, $user) === false) {
return false;
}
}
return true;
- });
+ }));
}
/**
* Add a provider for home mount points
*
- * @param \OCP\Files\Config\IHomeMountProvider $provider
+ * @param IHomeMountProvider $provider
* @since 9.1.0
*/
public function registerHomeProvider(IHomeMountProvider $provider) {
@@ -196,21 +187,19 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
/**
* Get the mount cache which can be used to search for mounts without setting up the filesystem
- *
- * @return IUserMountCache
*/
- public function getMountCache() {
+ public function getMountCache(): IUserMountCache {
return $this->mountCache;
}
- public function registerRootProvider(IRootMountProvider $provider) {
+ public function registerRootProvider(IRootMountProvider $provider): void {
$this->rootProviders[] = $provider;
}
/**
* Get all root mountpoints
*
- * @return \OCP\Files\Mount\IMountPoint[]
+ * @return list<IMountPoint>
* @since 20.0.0
*/
public function getRootMounts(): array {
@@ -226,16 +215,33 @@ class MountProviderCollection implements IMountProviderCollection, Emitter {
throw new \Exception('No root mounts provided by any provider');
}
- return $mounts;
+ return array_values($mounts);
}
- public function clearProviders() {
+ public function clearProviders(): void {
$this->providers = [];
$this->homeProviders = [];
$this->rootProviders = [];
}
+ /**
+ * @return list<IMountProvider>
+ */
public function getProviders(): array {
return $this->providers;
}
+
+ /**
+ * @return list<IHomeMountProvider>
+ */
+ public function getHomeProviders(): array {
+ return $this->homeProviders;
+ }
+
+ /**
+ * @return list<IRootMountProvider>
+ */
+ public function getRootProviders(): array {
+ return $this->rootProviders;
+ }
}
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index 9c1e2314262..09ac6d1416a 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -11,6 +11,10 @@ use OC\User\LazyUser;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\Event\UserMountAddedEvent;
+use OCP\Files\Config\Event\UserMountRemovedEvent;
+use OCP\Files\Config\Event\UserMountUpdatedEvent;
use OCP\Files\Config\ICachedMountFileInfo;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
@@ -46,6 +50,7 @@ class UserMountCache implements IUserMountCache {
private IUserManager $userManager,
private LoggerInterface $logger,
private IEventLogger $eventLogger,
+ private IEventDispatcher $eventDispatcher,
) {
$this->cacheInfoCache = new CappedMemoryCache();
$this->internalPathCache = new CappedMemoryCache();
@@ -108,17 +113,29 @@ class UserMountCache implements IUserMountCache {
$this->removeFromCache($mount);
unset($this->mountsForUsers[$userUID][$mount->getKey()]);
}
- foreach ($changedMounts as $mount) {
- $this->logger->debug("Updating mount '{$mount->getKey()}' for user '$userUID'", ['app' => 'files', 'mount_provider' => $mount->getMountProvider()]);
- $this->updateCachedMount($mount);
+ foreach ($changedMounts as $mountPair) {
+ $newMount = $mountPair[1];
+ $this->logger->debug("Updating mount '{$newMount->getKey()}' for user '$userUID'", ['app' => 'files', 'mount_provider' => $newMount->getMountProvider()]);
+ $this->updateCachedMount($newMount);
/** @psalm-suppress InvalidArgument */
- $this->mountsForUsers[$userUID][$mount->getKey()] = $mount;
+ $this->mountsForUsers[$userUID][$newMount->getKey()] = $newMount;
}
$this->connection->commit();
} catch (\Throwable $e) {
$this->connection->rollBack();
throw $e;
}
+
+ // Only fire events after all mounts have already been adjusted in the database.
+ foreach ($addedMounts as $mount) {
+ $this->eventDispatcher->dispatchTyped(new UserMountAddedEvent($mount));
+ }
+ foreach ($removedMounts as $mount) {
+ $this->eventDispatcher->dispatchTyped(new UserMountRemovedEvent($mount));
+ }
+ foreach ($changedMounts as $mountPair) {
+ $this->eventDispatcher->dispatchTyped(new UserMountUpdatedEvent($mountPair[0], $mountPair[1]));
+ }
}
$this->eventLogger->end('fs:setup:user:register');
}
@@ -126,9 +143,9 @@ class UserMountCache implements IUserMountCache {
/**
* @param array<string, ICachedMountInfo> $newMounts
* @param array<string, ICachedMountInfo> $cachedMounts
- * @return ICachedMountInfo[]
+ * @return list<list{0: ICachedMountInfo, 1: ICachedMountInfo}> Pairs of old and new mounts
*/
- private function findChangedMounts(array $newMounts, array $cachedMounts) {
+ private function findChangedMounts(array $newMounts, array $cachedMounts): array {
$changed = [];
foreach ($cachedMounts as $key => $cachedMount) {
if (isset($newMounts[$key])) {
@@ -138,7 +155,7 @@ class UserMountCache implements IUserMountCache {
$newMount->getMountId() !== $cachedMount->getMountId() ||
$newMount->getMountProvider() !== $cachedMount->getMountProvider()
) {
- $changed[] = $newMount;
+ $changed[] = [$cachedMount, $newMount];
}
}
}
diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php
index 2b8121a529d..4ab40b01f4a 100644
--- a/lib/private/Files/SetupManager.php
+++ b/lib/private/Files/SetupManager.php
@@ -23,7 +23,6 @@ use OC\Share\Share;
use OC\Share20\ShareDisableChecker;
use OC_App;
use OC_Hook;
-use OC_Util;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\Files_Sharing\External\Mount;
use OCA\Files_Sharing\ISharedMountPoint;
@@ -34,6 +33,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IRootMountProvider;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\BeforeFileSystemSetupEvent;
use OCP\Files\Events\InvalidateMountCacheEvent;
@@ -156,7 +156,7 @@ class SetupManager {
if ($mount instanceof HomeMountPoint) {
$user = $mount->getUser();
return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
- return OC_Util::getUserQuota($user);
+ return $user->getQuotaBytes();
}, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]);
}
@@ -280,9 +280,13 @@ class SetupManager {
$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
return str_starts_with($mount->getMountPoint(), $userRoot);
});
- $allProviders = array_map(function (IMountProvider $provider) {
+ $allProviders = array_map(function (IMountProvider|IHomeMountProvider|IRootMountProvider $provider) {
return get_class($provider);
- }, $this->mountProviderCollection->getProviders());
+ }, array_merge(
+ $this->mountProviderCollection->getProviders(),
+ $this->mountProviderCollection->getHomeProviders(),
+ $this->mountProviderCollection->getRootProviders(),
+ ));
$newProviders = array_diff($allProviders, $previouslySetupProviders);
$mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
return !in_array($mount->getMountProvider(), $previouslySetupProviders);
diff --git a/lib/private/Files/Template/TemplateManager.php b/lib/private/Files/Template/TemplateManager.php
index 8032cdf941f..80ef5a14786 100644
--- a/lib/private/Files/Template/TemplateManager.php
+++ b/lib/private/Files/Template/TemplateManager.php
@@ -19,6 +19,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Template\BeforeGetTemplatesEvent;
+use OCP\Files\Template\Field;
use OCP\Files\Template\FileCreatedFromTemplateEvent;
use OCP\Files\Template\ICustomTemplateProvider;
use OCP\Files\Template\ITemplateManager;
@@ -125,6 +126,19 @@ class TemplateManager implements ITemplateManager {
}, $this->listCreators()));
}
+ public function listTemplateFields(int $fileId): array {
+ foreach ($this->listCreators() as $creator) {
+ $fields = $this->getTemplateFields($creator, $fileId);
+ if (empty($fields)) {
+ continue;
+ }
+
+ return $fields;
+ }
+
+ return [];
+ }
+
/**
* @param string $filePath
* @param string $templateId
@@ -187,6 +201,20 @@ class TemplateManager implements ITemplateManager {
* @return list<Template>
*/
private function getTemplateFiles(TemplateFileCreator $type): array {
+ $templates = array_merge(
+ $this->getProviderTemplates($type),
+ $this->getUserTemplates($type)
+ );
+
+ $this->eventDispatcher->dispatchTyped(new BeforeGetTemplatesEvent($templates, false));
+
+ return $templates;
+ }
+
+ /**
+ * @return list<Template>
+ */
+ private function getProviderTemplates(TemplateFileCreator $type): array {
$templates = [];
foreach ($this->getRegisteredProviders() as $provider) {
foreach ($type->getMimetypes() as $mimetype) {
@@ -195,11 +223,22 @@ class TemplateManager implements ITemplateManager {
}
}
}
+
+ return $templates;
+ }
+
+ /**
+ * @return list<Template>
+ */
+ private function getUserTemplates(TemplateFileCreator $type): array {
+ $templates = [];
+
try {
$userTemplateFolder = $this->getTemplateFolder();
} catch (\Exception $e) {
return $templates;
}
+
foreach ($type->getMimetypes() as $mimetype) {
foreach ($userTemplateFolder->searchByMime($mimetype) as $templateFile) {
$template = new Template(
@@ -212,11 +251,33 @@ class TemplateManager implements ITemplateManager {
}
}
- $this->eventDispatcher->dispatchTyped(new BeforeGetTemplatesEvent($templates));
-
return $templates;
}
+ /*
+ * @return list<Field>
+ */
+ private function getTemplateFields(TemplateFileCreator $type, int $fileId): array {
+ $providerTemplates = $this->getProviderTemplates($type);
+ $userTemplates = $this->getUserTemplates($type);
+
+ $matchedTemplates = array_filter(
+ array_merge($providerTemplates, $userTemplates),
+ function (Template $template) use ($fileId) {
+ return $template->jsonSerialize()['fileid'] === $fileId;
+ });
+
+ if (empty($matchedTemplates)) {
+ return [];
+ }
+
+ $this->eventDispatcher->dispatchTyped(new BeforeGetTemplatesEvent($matchedTemplates, true));
+
+ return array_values(array_map(function (Template $template) {
+ return $template->jsonSerialize()['fields'] ?? [];
+ }, $matchedTemplates));
+ }
+
/**
* @param Node|File $file
* @return array
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index 1f618dab22d..fa62a7b0257 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -154,7 +154,7 @@ class PreviewManager implements IPreview {
$mimeType = null,
bool $cacheResult = true,
): ISimpleFile {
- $this->throwIfPreviewsDisabled();
+ $this->throwIfPreviewsDisabled($file);
$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
try {
@@ -178,7 +178,7 @@ class PreviewManager implements IPreview {
* @since 19.0.0
*/
public function generatePreviews(File $file, array $specifications, $mimeType = null) {
- $this->throwIfPreviewsDisabled();
+ $this->throwIfPreviewsDisabled($file);
return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
}
@@ -455,8 +455,8 @@ class PreviewManager implements IPreview {
/**
* @throws NotFoundException if preview generation is disabled
*/
- private function throwIfPreviewsDisabled(): void {
- if (!$this->enablePreviews) {
+ private function throwIfPreviewsDisabled(File $file): void {
+ if (!$this->isAvailable($file)) {
throw new NotFoundException('Previews disabled');
}
}
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index c5069bff48e..7fbf776d9a1 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -61,6 +61,7 @@ use OCP\AppFramework\QueryException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\Resources\IManager;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\AppData\IAppDataFactory;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
@@ -173,7 +174,7 @@ class Repair implements IOutput {
\OCP\Server::get(ClearGeneratedAvatarCache::class),
new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
- new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)),
+ new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OCP\Server::get(IAppDataFactory::class), \OC::$server->get(LoggerInterface::class)),
new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->get(INotificationManager::class), \OCP\Server::get(ITimeFactory::class)),
new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)),
diff --git a/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php
index a9cbbb4cbbf..646dd2c5e83 100644
--- a/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php
+++ b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php
@@ -6,9 +6,10 @@ declare(strict_types=1);
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+
namespace OC\Repair\NC16;
-use OCP\Files\IAppData;
+use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
@@ -27,18 +28,11 @@ use RuntimeException;
* photo could be returned for this vcard. These invalid files are removed by this migration step.
*/
class CleanupCardDAVPhotoCache implements IRepairStep {
- /** @var IConfig */
- private $config;
-
- /** @var IAppData */
- private $appData;
-
- private LoggerInterface $logger;
-
- public function __construct(IConfig $config, IAppData $appData, LoggerInterface $logger) {
- $this->config = $config;
- $this->appData = $appData;
- $this->logger = $logger;
+ public function __construct(
+ private IConfig $config,
+ private IAppDataFactory $appDataFactory,
+ private LoggerInterface $logger,
+ ) {
}
public function getName(): string {
@@ -46,8 +40,10 @@ class CleanupCardDAVPhotoCache implements IRepairStep {
}
private function repair(IOutput $output): void {
+ $photoCacheAppData = $this->appDataFactory->get('dav-photocache');
+
try {
- $folders = $this->appData->getDirectoryListing();
+ $folders = $photoCacheAppData->getDirectoryListing();
} catch (NotFoundException $e) {
return;
} catch (RuntimeException $e) {
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php
index 065f720ba72..574f6c80c3f 100644
--- a/lib/private/Security/Bruteforce/Throttler.php
+++ b/lib/private/Security/Bruteforce/Throttler.php
@@ -206,25 +206,27 @@ class Throttler implements IThrottler {
* {@inheritDoc}
*/
public function sleepDelayOrThrowOnMax(string $ip, string $action = ''): int {
- $attempts = $this->getAttempts($ip, $action, 0.5);
- if ($attempts > $this->config->getSystemValueInt('auth.bruteforce.max-attempts', self::MAX_ATTEMPTS)) {
- $this->logger->info('IP address blocked because it reached the maximum failed attempts in the last 30 minutes [action: {action}, attempts: {attempts}, ip: {ip}]', [
- 'action' => $action,
- 'ip' => $ip,
- 'attempts' => $attempts,
- ]);
- // If the ip made too many attempts within the last 30 mins we don't execute anymore
- throw new MaxDelayReached('Reached maximum delay');
- }
-
+ $maxAttempts = $this->config->getSystemValueInt('auth.bruteforce.max-attempts', self::MAX_ATTEMPTS);
$attempts = $this->getAttempts($ip, $action);
- if ($attempts > 10) {
+ if ($attempts > $maxAttempts) {
+ $attempts30mins = $this->getAttempts($ip, $action, 0.5);
+ if ($attempts30mins > $maxAttempts) {
+ $this->logger->info('IP address blocked because it reached the maximum failed attempts in the last 30 minutes [action: {action}, attempts: {attempts}, ip: {ip}]', [
+ 'action' => $action,
+ 'ip' => $ip,
+ 'attempts' => $attempts30mins,
+ ]);
+ // If the ip made too many attempts within the last 30 mins we don't execute anymore
+ throw new MaxDelayReached('Reached maximum delay');
+ }
+
$this->logger->info('IP address throttled because it reached the attempts limit in the last 12 hours [action: {action}, attempts: {attempts}, ip: {ip}]', [
'action' => $action,
'ip' => $ip,
'attempts' => $attempts,
]);
}
+
if ($attempts > 0) {
return $this->calculateDelay($attempts);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 545ceacbe81..ea8c1ce3797 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -124,10 +124,6 @@ use OC\User\DisplayNameCache;
use OC\User\Listeners\BeforeUserDeletedListener;
use OC\User\Listeners\UserChangedListener;
use OC\User\Session;
-use OCA\Files_External\Service\BackendService;
-use OCA\Files_External\Service\GlobalStoragesService;
-use OCA\Files_External\Service\UserGlobalStoragesService;
-use OCA\Files_External\Service\UserStoragesService;
use OCA\Theming\ImageManager;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\ThemingDefaults;
@@ -138,7 +134,6 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Authentication\LoginCredentials\IStore;
use OCP\Authentication\Token\IProvider as OCPIProvider;
use OCP\BackgroundJob\IJobList;
-use OCP\Collaboration\AutoComplete\IManager;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Command\IBus;
use OCP\Comments\ICommentsManager;
@@ -189,7 +184,6 @@ use OCP\IRequest;
use OCP\IRequestId;
use OCP\IServerContainer;
use OCP\ISession;
-use OCP\ITagManager;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\IUserManager;
@@ -212,7 +206,6 @@ use OCP\RichObjectStrings\IRichTextFormatter;
use OCP\RichObjectStrings\IValidator;
use OCP\Route\IRouter;
use OCP\Security\Bruteforce\IThrottler;
-use OCP\Security\IContentSecurityPolicyManager;
use OCP\Security\ICredentialsManager;
use OCP\Security\ICrypto;
use OCP\Security\IHasher;
@@ -1125,7 +1118,7 @@ class Server extends ServerContainer implements IServerContainer {
$config = $c->get(\OCP\IConfig::class);
$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
/** @var \OCP\Share\IProviderFactory $factory */
- return new $factoryClass($this);
+ return $c->get($factoryClass);
});
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
@@ -1305,30 +1298,6 @@ class Server extends ServerContainer implements IServerContainer {
$hookConnector->viewToNode();
}
- /**
- * @return \OCP\Calendar\IManager
- * @deprecated 20.0.0
- */
- public function getCalendarManager() {
- return $this->get(\OC\Calendar\Manager::class);
- }
-
- /**
- * @return \OCP\Calendar\Resource\IManager
- * @deprecated 20.0.0
- */
- public function getCalendarResourceBackendManager() {
- return $this->get(\OC\Calendar\Resource\Manager::class);
- }
-
- /**
- * @return \OCP\Calendar\Room\IManager
- * @deprecated 20.0.0
- */
- public function getCalendarRoomBackendManager() {
- return $this->get(\OC\Calendar\Room\Manager::class);
- }
-
private function connectDispatcher(): void {
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->get(IEventDispatcher::class);
@@ -1366,14 +1335,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OCP\Encryption\Keys\IStorage
- * @deprecated 20.0.0
- */
- public function getEncryptionKeyStorage() {
- return $this->get(IStorage::class);
- }
-
- /**
* The current request object holding all information about the request
* currently being processed is returned from this method.
* In case the current execution was not initiated by a web request null is returned
@@ -1386,61 +1347,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Returns the preview manager which can create preview images for a given file
- *
- * @return IPreview
- * @deprecated 20.0.0
- */
- public function getPreviewManager() {
- return $this->get(IPreview::class);
- }
-
- /**
- * Returns the tag manager which can get and set tags for different object types
- *
- * @see \OCP\ITagManager::load()
- * @return ITagManager
- * @deprecated 20.0.0
- */
- public function getTagManager() {
- return $this->get(ITagManager::class);
- }
-
- /**
- * Returns the system-tag manager
- *
- * @return ISystemTagManager
- *
- * @since 9.0.0
- * @deprecated 20.0.0
- */
- public function getSystemTagManager() {
- return $this->get(ISystemTagManager::class);
- }
-
- /**
- * Returns the system-tag object mapper
- *
- * @return ISystemTagObjectMapper
- *
- * @since 9.0.0
- * @deprecated 20.0.0
- */
- public function getSystemTagObjectMapper() {
- return $this->get(ISystemTagObjectMapper::class);
- }
-
- /**
- * Returns the avatar manager, used for avatar functionality
- *
- * @return IAvatarManager
- * @deprecated 20.0.0
- */
- public function getAvatarManager() {
- return $this->get(IAvatarManager::class);
- }
-
- /**
* Returns the root folder of ownCloud's data directory
*
* @return IRootFolder
@@ -1524,22 +1430,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OC\Authentication\TwoFactorAuth\Manager
- * @deprecated 20.0.0
- */
- public function getTwoFactorAuthManager() {
- return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
- }
-
- /**
- * @return \OC\NavigationManager
- * @deprecated 20.0.0
- */
- public function getNavigationManager() {
- return $this->get(INavigationManager::class);
- }
-
- /**
* @return \OCP\IConfig
* @deprecated 20.0.0
*/
@@ -1556,16 +1446,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Returns the app config manager
- *
- * @return IAppConfig
- * @deprecated 20.0.0
- */
- public function getAppConfig() {
- return $this->get(IAppConfig::class);
- }
-
- /**
* @return IFactory
* @deprecated 20.0.0
*/
@@ -1594,14 +1474,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return AppFetcher
- * @deprecated 20.0.0
- */
- public function getAppFetcher() {
- return $this->get(AppFetcher::class);
- }
-
- /**
* Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
* getMemCacheFactory() instead.
*
@@ -1623,17 +1495,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Returns an \OC\RedisFactory instance
- *
- * @return \OC\RedisFactory
- * @deprecated 20.0.0
- */
- public function getGetRedisFactory() {
- return $this->get('RedisFactory');
- }
-
-
- /**
* Returns the current session
*
* @return \OCP\IDBConnection
@@ -1664,25 +1525,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return ILogFactory
- * @throws \OCP\AppFramework\QueryException
- * @deprecated 20.0.0
- */
- public function getLogFactory() {
- return $this->get(ILogFactory::class);
- }
-
- /**
- * Returns a router for generating and matching urls
- *
- * @return IRouter
- * @deprecated 20.0.0
- */
- public function getRouter() {
- return $this->get(IRouter::class);
- }
-
- /**
* Returns a SecureRandom instance
*
* @return \OCP\Security\ISecureRandom
@@ -1713,16 +1555,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Returns a CredentialsManager instance
- *
- * @return ICredentialsManager
- * @deprecated 20.0.0
- */
- public function getCredentialsManager() {
- return $this->get(ICredentialsManager::class);
- }
-
- /**
* Get the certificate manager
*
* @return \OCP\ICertificateManager
@@ -1732,40 +1564,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Returns an instance of the HTTP client service
- *
- * @return IClientService
- * @deprecated 20.0.0
- */
- public function getHTTPClientService() {
- return $this->get(IClientService::class);
- }
-
- /**
- * Get the active event logger
- *
- * The returned logger only logs data when debug mode is enabled
- *
- * @return IEventLogger
- * @deprecated 20.0.0
- */
- public function getEventLogger() {
- return $this->get(IEventLogger::class);
- }
-
- /**
- * Get the active query logger
- *
- * The returned logger only logs data when debug mode is enabled
- *
- * @return IQueryLogger
- * @deprecated 20.0.0
- */
- public function getQueryLogger() {
- return $this->get(IQueryLogger::class);
- }
-
- /**
* Get the manager for temporary files and folders
*
* @return \OCP\ITempManager
@@ -1806,66 +1604,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OC\OCSClient
- * @deprecated 20.0.0
- */
- public function getOcsClient() {
- return $this->get('OcsClient');
- }
-
- /**
- * @return IDateTimeZone
- * @deprecated 20.0.0
- */
- public function getDateTimeZone() {
- return $this->get(IDateTimeZone::class);
- }
-
- /**
- * @return IDateTimeFormatter
- * @deprecated 20.0.0
- */
- public function getDateTimeFormatter() {
- return $this->get(IDateTimeFormatter::class);
- }
-
- /**
- * @return IMountProviderCollection
- * @deprecated 20.0.0
- */
- public function getMountProviderCollection() {
- return $this->get(IMountProviderCollection::class);
- }
-
- /**
- * Get the IniWrapper
- *
- * @return IniGetWrapper
- * @deprecated 20.0.0
- */
- public function getIniWrapper() {
- return $this->get(IniGetWrapper::class);
- }
-
- /**
- * @return \OCP\Command\IBus
- * @deprecated 20.0.0
- */
- public function getCommandBus() {
- return $this->get(IBus::class);
- }
-
- /**
- * Get the trusted domain helper
- *
- * @return TrustedDomainHelper
- * @deprecated 20.0.0
- */
- public function getTrustedDomainHelper() {
- return $this->get(TrustedDomainHelper::class);
- }
-
- /**
* Get the locking provider
*
* @return ILockingProvider
@@ -1877,22 +1615,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return IMountManager
- * @deprecated 20.0.0
- **/
- public function getMountManager() {
- return $this->get(IMountManager::class);
- }
-
- /**
- * @return IUserMountCache
- * @deprecated 20.0.0
- */
- public function getUserMountCache() {
- return $this->get(IUserMountCache::class);
- }
-
- /**
* Get the MimeTypeDetector
*
* @return IMimeTypeDetector
@@ -1913,16 +1635,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Get the manager of all the capabilities
- *
- * @return CapabilitiesManager
- * @deprecated 20.0.0
- */
- public function getCapabilitiesManager() {
- return $this->get(CapabilitiesManager::class);
- }
-
- /**
* Get the Notification Manager
*
* @return \OCP\Notification\IManager
@@ -1934,14 +1646,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return ICommentsManager
- * @deprecated 20.0.0
- */
- public function getCommentsManager() {
- return $this->get(ICommentsManager::class);
- }
-
- /**
* @return \OCA\Theming\ThemingDefaults
* @deprecated 20.0.0
*/
@@ -1958,14 +1662,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OC\Session\CryptoWrapper
- * @deprecated 20.0.0
- */
- public function getSessionCryptoWrapper() {
- return $this->get('CryptoWrapper');
- }
-
- /**
* @return CsrfTokenManager
* @deprecated 20.0.0
*/
@@ -1974,22 +1670,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return IThrottler
- * @deprecated 20.0.0
- */
- public function getBruteForceThrottler() {
- return $this->get(Throttler::class);
- }
-
- /**
- * @return IContentSecurityPolicyManager
- * @deprecated 20.0.0
- */
- public function getContentSecurityPolicyManager() {
- return $this->get(ContentSecurityPolicyManager::class);
- }
-
- /**
* @return ContentSecurityPolicyNonceManager
* @deprecated 20.0.0
*/
@@ -1998,80 +1678,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Not a public API as of 8.2, wait for 9.0
- *
- * @return \OCA\Files_External\Service\BackendService
- * @deprecated 20.0.0
- */
- public function getStoragesBackendService() {
- return $this->get(BackendService::class);
- }
-
- /**
- * Not a public API as of 8.2, wait for 9.0
- *
- * @return \OCA\Files_External\Service\GlobalStoragesService
- * @deprecated 20.0.0
- */
- public function getGlobalStoragesService() {
- return $this->get(GlobalStoragesService::class);
- }
-
- /**
- * Not a public API as of 8.2, wait for 9.0
- *
- * @return \OCA\Files_External\Service\UserGlobalStoragesService
- * @deprecated 20.0.0
- */
- public function getUserGlobalStoragesService() {
- return $this->get(UserGlobalStoragesService::class);
- }
-
- /**
- * Not a public API as of 8.2, wait for 9.0
- *
- * @return \OCA\Files_External\Service\UserStoragesService
- * @deprecated 20.0.0
- */
- public function getUserStoragesService() {
- return $this->get(UserStoragesService::class);
- }
-
- /**
- * @return \OCP\Share\IManager
- * @deprecated 20.0.0
- */
- public function getShareManager() {
- return $this->get(\OCP\Share\IManager::class);
- }
-
- /**
- * @return \OCP\Collaboration\Collaborators\ISearch
- * @deprecated 20.0.0
- */
- public function getCollaboratorSearch() {
- return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
- }
-
- /**
- * @return \OCP\Collaboration\AutoComplete\IManager
- * @deprecated 20.0.0
- */
- public function getAutoCompleteManager() {
- return $this->get(IManager::class);
- }
-
- /**
- * Returns the LDAP Provider
- *
- * @return \OCP\LDAP\ILDAPProvider
- * @deprecated 20.0.0
- */
- public function getLDAPProvider() {
- return $this->get('LDAPProvider');
- }
-
- /**
* @return \OCP\Settings\IManager
* @deprecated 20.0.0
*/
@@ -2090,14 +1696,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * @return \OCP\Lockdown\ILockdownManager
- * @deprecated 20.0.0
- */
- public function getLockdownManager() {
- return $this->get('LockdownManager');
- }
-
- /**
* @return \OCP\Federation\ICloudIdManager
* @deprecated 20.0.0
*/
@@ -2105,65 +1703,6 @@ class Server extends ServerContainer implements IServerContainer {
return $this->get(ICloudIdManager::class);
}
- /**
- * @return \OCP\GlobalScale\IConfig
- * @deprecated 20.0.0
- */
- public function getGlobalScaleConfig() {
- return $this->get(IConfig::class);
- }
-
- /**
- * @return \OCP\Federation\ICloudFederationProviderManager
- * @deprecated 20.0.0
- */
- public function getCloudFederationProviderManager() {
- return $this->get(ICloudFederationProviderManager::class);
- }
-
- /**
- * @return \OCP\Remote\Api\IApiFactory
- * @deprecated 20.0.0
- */
- public function getRemoteApiFactory() {
- return $this->get(IApiFactory::class);
- }
-
- /**
- * @return \OCP\Federation\ICloudFederationFactory
- * @deprecated 20.0.0
- */
- public function getCloudFederationFactory() {
- return $this->get(ICloudFederationFactory::class);
- }
-
- /**
- * @return \OCP\Remote\IInstanceFactory
- * @deprecated 20.0.0
- */
- public function getRemoteInstanceFactory() {
- return $this->get(IInstanceFactory::class);
- }
-
- /**
- * @return IStorageFactory
- * @deprecated 20.0.0
- */
- public function getStorageFactory() {
- return $this->get(IStorageFactory::class);
- }
-
- /**
- * Get the Preview GeneratorHelper
- *
- * @return GeneratorHelper
- * @since 17.0.0
- * @deprecated 20.0.0
- */
- public function getGeneratorHelper() {
- return $this->get(\OC\Preview\GeneratorHelper::class);
- }
-
private function registerDeprecatedAlias(string $alias, string $target) {
$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
try {
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index 7335c863df0..eba3f4f26f1 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -1,32 +1,21 @@
<?php
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
+
namespace OC\Share20;
use OC\Share20\Exception\ProviderException;
-use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
-use OCA\FederatedFileSharing\Notifications;
-use OCA\FederatedFileSharing\TokenHandler;
-use OCA\ShareByMail\Settings\SettingsManager;
use OCA\ShareByMail\ShareByMailProvider;
use OCA\Talk\Share\RoomShareProvider;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Defaults;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\Federation\ICloudFederationFactory;
-use OCP\Files\IRootFolder;
-use OCP\Http\Client\IClientService;
-use OCP\IServerContainer;
-use OCP\L10N\IFactory;
-use OCP\Mail\IMailer;
-use OCP\Security\IHasher;
-use OCP\Security\ISecureRandom;
-use OCP\Share\IManager;
+use OCP\App\IAppManager;
+use OCP\Server;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
@@ -38,30 +27,22 @@ use Psr\Log\LoggerInterface;
* @package OC\Share20
*/
class ProviderFactory implements IProviderFactory {
- /** @var DefaultShareProvider */
- private $defaultProvider = null;
- /** @var FederatedShareProvider */
- private $federatedProvider = null;
- /** @var ShareByMailProvider */
- private $shareByMailProvider;
- /** @var \OCA\Circles\ShareByCircleProvider */
- private $shareByCircleProvider = null;
- /** @var bool */
- private $circlesAreNotAvailable = false;
- /** @var \OCA\Talk\Share\RoomShareProvider */
+ private ?DefaultShareProvider $defaultProvider = null;
+ private ?FederatedShareProvider $federatedProvider = null;
+ private ?ShareByMailProvider $shareByMailProvider = null;
+ /**
+ * @psalm-suppress UndefinedDocblockClass
+ * @var ?RoomShareProvider
+ */
private $roomShareProvider = null;
- private $registeredShareProviders = [];
+ private array $registeredShareProviders = [];
- private $shareProviders = [];
+ private array $shareProviders = [];
- /**
- * IProviderFactory constructor.
- *
- * @param IServerContainer $serverContainer
- */
public function __construct(
- private IServerContainer $serverContainer,
+ protected IAppManager $appManager,
+ protected LoggerInterface $logger,
) {
}
@@ -71,81 +52,24 @@ class ProviderFactory implements IProviderFactory {
/**
* Create the default share provider.
- *
- * @return DefaultShareProvider
*/
- protected function defaultShareProvider() {
- if ($this->defaultProvider === null) {
- $this->defaultProvider = new DefaultShareProvider(
- $this->serverContainer->getDatabaseConnection(),
- $this->serverContainer->getUserManager(),
- $this->serverContainer->getGroupManager(),
- $this->serverContainer->get(IRootFolder::class),
- $this->serverContainer->get(IMailer::class),
- $this->serverContainer->get(Defaults::class),
- $this->serverContainer->get(IFactory::class),
- $this->serverContainer->getURLGenerator(),
- $this->serverContainer->get(ITimeFactory::class),
- $this->serverContainer->get(LoggerInterface::class),
- $this->serverContainer->get(IManager::class),
- );
- }
-
- return $this->defaultProvider;
+ protected function defaultShareProvider(): DefaultShareProvider {
+ return Server::get(DefaultShareProvider::class);
}
/**
* Create the federated share provider
- *
- * @return FederatedShareProvider
*/
- protected function federatedShareProvider() {
+ protected function federatedShareProvider(): ?FederatedShareProvider {
if ($this->federatedProvider === null) {
/*
* Check if the app is enabled
*/
- $appManager = $this->serverContainer->getAppManager();
- if (!$appManager->isEnabledForUser('federatedfilesharing')) {
+ if (!$this->appManager->isEnabledForUser('federatedfilesharing')) {
return null;
}
- /*
- * TODO: add factory to federated sharing app
- */
- $l = $this->serverContainer->getL10N('federatedfilesharing');
- $addressHandler = new AddressHandler(
- $this->serverContainer->getURLGenerator(),
- $l,
- $this->serverContainer->getCloudIdManager()
- );
- $notifications = new Notifications(
- $addressHandler,
- $this->serverContainer->get(IClientService::class),
- $this->serverContainer->get(\OCP\OCS\IDiscoveryService::class),
- $this->serverContainer->getJobList(),
- \OC::$server->getCloudFederationProviderManager(),
- \OC::$server->get(ICloudFederationFactory::class),
- $this->serverContainer->get(IEventDispatcher::class),
- $this->serverContainer->get(LoggerInterface::class),
- );
- $tokenHandler = new TokenHandler(
- $this->serverContainer->get(ISecureRandom::class)
- );
-
- $this->federatedProvider = new FederatedShareProvider(
- $this->serverContainer->getDatabaseConnection(),
- $addressHandler,
- $notifications,
- $tokenHandler,
- $l,
- $this->serverContainer->get(IRootFolder::class),
- $this->serverContainer->getConfig(),
- $this->serverContainer->getUserManager(),
- $this->serverContainer->getCloudIdManager(),
- $this->serverContainer->getGlobalScaleConfig(),
- $this->serverContainer->getCloudFederationProviderManager(),
- $this->serverContainer->get(LoggerInterface::class),
- );
+ $this->federatedProvider = Server::get(FederatedShareProvider::class);
}
return $this->federatedProvider;
@@ -153,90 +77,34 @@ class ProviderFactory implements IProviderFactory {
/**
* Create the federated share provider
- *
- * @return ShareByMailProvider
*/
- protected function getShareByMailProvider() {
+ protected function getShareByMailProvider(): ?ShareByMailProvider {
if ($this->shareByMailProvider === null) {
/*
* Check if the app is enabled
*/
- $appManager = $this->serverContainer->getAppManager();
- if (!$appManager->isEnabledForUser('sharebymail')) {
+ if (!$this->appManager->isEnabledForUser('sharebymail')) {
return null;
}
- $settingsManager = new SettingsManager($this->serverContainer->getConfig());
-
- $this->shareByMailProvider = new ShareByMailProvider(
- $this->serverContainer->getConfig(),
- $this->serverContainer->getDatabaseConnection(),
- $this->serverContainer->get(ISecureRandom::class),
- $this->serverContainer->getUserManager(),
- $this->serverContainer->get(IRootFolder::class),
- $this->serverContainer->getL10N('sharebymail'),
- $this->serverContainer->get(LoggerInterface::class),
- $this->serverContainer->get(IMailer::class),
- $this->serverContainer->getURLGenerator(),
- $this->serverContainer->getActivityManager(),
- $settingsManager,
- $this->serverContainer->get(Defaults::class),
- $this->serverContainer->get(IHasher::class),
- $this->serverContainer->get(IEventDispatcher::class),
- $this->serverContainer->get(IManager::class)
- );
+ $this->shareByMailProvider = Server::get(ShareByMailProvider::class);
}
return $this->shareByMailProvider;
}
-
- /**
- * Create the circle share provider
- *
- * @return FederatedShareProvider
- *
- * @suppress PhanUndeclaredClassMethod
- */
- protected function getShareByCircleProvider() {
- if ($this->circlesAreNotAvailable) {
- return null;
- }
-
- if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') ||
- !class_exists('\OCA\Circles\ShareByCircleProvider')
- ) {
- $this->circlesAreNotAvailable = true;
- return null;
- }
-
- if ($this->shareByCircleProvider === null) {
- $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider(
- $this->serverContainer->getDatabaseConnection(),
- $this->serverContainer->get(ISecureRandom::class),
- $this->serverContainer->getUserManager(),
- $this->serverContainer->get(IRootFolder::class),
- $this->serverContainer->getL10N('circles'),
- $this->serverContainer->get(LoggerInterface::class),
- $this->serverContainer->getURLGenerator()
- );
- }
-
- return $this->shareByCircleProvider;
- }
-
/**
* Create the room share provider
*
- * @return RoomShareProvider
+ * @psalm-suppress UndefinedDocblockClass
+ * @return ?RoomShareProvider
*/
protected function getRoomShareProvider() {
if ($this->roomShareProvider === null) {
/*
* Check if the app is enabled
*/
- $appManager = $this->serverContainer->getAppManager();
- if (!$appManager->isEnabledForUser('spreed')) {
+ if (!$this->appManager->isEnabledForUser('spreed')) {
return null;
}
@@ -244,9 +112,9 @@ class ProviderFactory implements IProviderFactory {
/**
* @psalm-suppress UndefinedClass
*/
- $this->roomShareProvider = $this->serverContainer->get(RoomShareProvider::class);
+ $this->roomShareProvider = Server::get(RoomShareProvider::class);
} catch (\Throwable $e) {
- $this->serverContainer->get(LoggerInterface::class)->error(
+ $this->logger->error(
$e->getMessage(),
['exception' => $e]
);
@@ -272,8 +140,6 @@ class ProviderFactory implements IProviderFactory {
$provider = $this->federatedShareProvider();
} elseif ($id === 'ocMailShare') {
$provider = $this->getShareByMailProvider();
- } elseif ($id === 'ocCircleShare') {
- $provider = $this->getShareByCircleProvider();
} elseif ($id === 'ocRoomShare') {
$provider = $this->getRoomShareProvider();
}
@@ -281,10 +147,10 @@ class ProviderFactory implements IProviderFactory {
foreach ($this->registeredShareProviders as $shareProvider) {
try {
/** @var IShareProvider $instance */
- $instance = $this->serverContainer->get($shareProvider);
+ $instance = Server::get($shareProvider);
$this->shareProviders[$instance->identifier()] = $instance;
} catch (\Throwable $e) {
- $this->serverContainer->get(LoggerInterface::class)->error(
+ $this->logger->error(
$e->getMessage(),
['exception' => $e]
);
@@ -318,7 +184,7 @@ class ProviderFactory implements IProviderFactory {
} elseif ($shareType === IShare::TYPE_EMAIL) {
$provider = $this->getShareByMailProvider();
} elseif ($shareType === IShare::TYPE_CIRCLE) {
- $provider = $this->getShareByCircleProvider();
+ $provider = $this->getProvider('ocCircleShare');
} elseif ($shareType === IShare::TYPE_ROOM) {
$provider = $this->getRoomShareProvider();
} elseif ($shareType === IShare::TYPE_DECK) {
@@ -341,10 +207,6 @@ class ProviderFactory implements IProviderFactory {
if ($shareByMail !== null) {
$shares[] = $shareByMail;
}
- $shareByCircle = $this->getShareByCircleProvider();
- if ($shareByCircle !== null) {
- $shares[] = $shareByCircle;
- }
$roomShare = $this->getRoomShareProvider();
if ($roomShare !== null) {
$shares[] = $roomShare;
@@ -353,9 +215,9 @@ class ProviderFactory implements IProviderFactory {
foreach ($this->registeredShareProviders as $shareProvider) {
try {
/** @var IShareProvider $instance */
- $instance = $this->serverContainer->get($shareProvider);
+ $instance = Server::get($shareProvider);
} catch (\Throwable $e) {
- $this->serverContainer->get(LoggerInterface::class)->error(
+ $this->logger->error(
$e->getMessage(),
['exception' => $e]
);
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php
index 715265f6a39..501169019d4 100644
--- a/lib/private/User/LazyUser.php
+++ b/lib/private/User/LazyUser.php
@@ -160,6 +160,10 @@ class LazyUser implements IUser {
return $this->getUser()->getQuota();
}
+ public function getQuotaBytes(): int|float {
+ return $this->getUser()->getQuotaBytes();
+ }
+
public function setQuota($quota) {
$this->getUser()->setQuota($quota);
}
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index 8e01a15695c..88ed0d44387 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -558,6 +558,19 @@ class User implements IUser {
return $quota;
}
+ public function getQuotaBytes(): int|float {
+ $quota = $this->getQuota();
+ if ($quota === 'none') {
+ return \OCP\Files\FileInfo::SPACE_UNLIMITED;
+ }
+
+ $bytes = \OCP\Util::computerFileSize($quota);
+ if ($bytes === false) {
+ return \OCP\Files\FileInfo::SPACE_UNKNOWN;
+ }
+ return $bytes;
+ }
+
/**
* set the users' quota
*
diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php
index a06b15573cb..4388f775623 100644
--- a/lib/private/legacy/OC_Helper.php
+++ b/lib/private/legacy/OC_Helper.php
@@ -199,7 +199,7 @@ class OC_Helper {
/**
* Try to find a program
- * @deprecated 25.0.0 Use \OC\BinaryFinder directly
+ * @deprecated 25.0.0 Use \OCP\IBinaryFinder directly
*/
public static function findBinaryPath(string $program): ?string {
$result = Server::get(IBinaryFinder::class)->findBinaryPath($program);
@@ -272,7 +272,7 @@ class OC_Helper {
} else {
$user = \OC::$server->getUserSession()->getUser();
}
- $quota = OC_Util::getUserQuota($user);
+ $quota = $user?->getQuotaBytes() ?? \OCP\Files\FileInfo::SPACE_UNKNOWN;
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
// always get free space / total space from root + mount points
return self::getGlobalStorageInfo($quota, $user, $mount);
@@ -415,6 +415,7 @@ class OC_Helper {
/**
* Returns whether the config file is set manually to read-only
* @return bool
+ * @deprecated 32.0.0 use the `config_is_read_only` system config directly
*/
public static function isReadOnlyConfigEnabled() {
return \OC::$server->getConfig()->getSystemValueBool('config_is_read_only', false);
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 895cfba35c5..87447af8adc 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -98,6 +98,7 @@ class OC_Util {
*
* @param IUser|null $user
* @return int|\OCP\Files\FileInfo::SPACE_UNLIMITED|false|float Quota bytes
+ * @deprecated 9.0.0 - Use \OCP\IUser::getQuota or \OCP\IUser::getQuotaBytes
*/
public static function getUserQuota(?IUser $user) {
if (is_null($user)) {
@@ -331,7 +332,7 @@ class OC_Util {
}
// Check if config folder is writable.
- if (!OC_Helper::isReadOnlyConfigEnabled()) {
+ if (!(bool)$config->getValue('config_is_read_only', false)) {
if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
$errors[] = [
'error' => $l->t('Cannot write into "config" directory.'),