diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 12 | ||||
-rw-r--r-- | lib/private/Federation/CloudId.php | 10 | ||||
-rw-r--r-- | lib/private/Federation/CloudIdManager.php | 49 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/Azure.php | 4 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 64 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/S3ObjectTrait.php | 4 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/StorageObjectStore.php | 4 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/Swift.php | 12 | ||||
-rw-r--r-- | lib/private/Server.php | 8 | ||||
-rw-r--r-- | lib/private/SubAdmin.php | 4 | ||||
-rw-r--r-- | lib/private/Template/JSConfigHelper.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/OC_DB.php | 4 |
12 files changed, 146 insertions, 31 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 68e2701de27..12fca23c51f 100644 --- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php +++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php @@ -264,7 +264,7 @@ class RegistrationContext { * @param App[] $apps */ public function delegateCapabilityRegistrations(array $apps): void { - while (($registration = array_pop($this->capabilities)) !== null) { + while (($registration = array_shift($this->capabilities)) !== null) { try { $apps[$registration['appId']] ->getContainer() @@ -283,7 +283,7 @@ class RegistrationContext { * @param App[] $apps */ public function delegateCrashReporterRegistrations(array $apps, Registry $registry): void { - while (($registration = array_pop($this->crashReporters)) !== null) { + while (($registration = array_shift($this->crashReporters)) !== null) { try { $registry->registerLazy($registration['class']); } catch (Throwable $e) { @@ -300,7 +300,7 @@ class RegistrationContext { * @param App[] $apps */ public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { - while (($panel = array_pop($this->dashboardPanels)) !== null) { + while (($panel = array_shift($this->dashboardPanels)) !== null) { try { $dashboardManager->lazyRegisterWidget($panel['class']); } catch (Throwable $e) { @@ -314,7 +314,7 @@ class RegistrationContext { } public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void { - while (($registration = array_pop($this->eventListeners)) !== null) { + while (($registration = array_shift($this->eventListeners)) !== null) { try { if (isset($registration['priority'])) { $eventDispatcher->addServiceListener( @@ -342,7 +342,7 @@ class RegistrationContext { * @param App[] $apps */ public function delegateContainerRegistrations(array $apps): void { - while (($registration = array_pop($this->services)) !== null) { + while (($registration = array_shift($this->services)) !== null) { try { /** * Register the service and convert the callable into a \Closure if necessary @@ -402,7 +402,7 @@ class RegistrationContext { * @param App[] $apps */ public function delegateMiddlewareRegistrations(array $apps): void { - while (($middleware = array_pop($this->middlewares)) !== null) { + while (($middleware = array_shift($this->middlewares)) !== null) { try { $apps[$middleware['appId']] ->getContainer() diff --git a/lib/private/Federation/CloudId.php b/lib/private/Federation/CloudId.php index 80e174589b0..c917a9d5816 100644 --- a/lib/private/Federation/CloudId.php +++ b/lib/private/Federation/CloudId.php @@ -36,6 +36,8 @@ class CloudId implements ICloudId { private $user; /** @var string */ private $remote; + /** @var string|null */ + private $displayName; /** * CloudId constructor. @@ -44,10 +46,11 @@ class CloudId implements ICloudId { * @param string $user * @param string $remote */ - public function __construct(string $id, string $user, string $remote) { + public function __construct(string $id, string $user, string $remote, ?string $displayName = null) { $this->id = $id; $this->user = $user; $this->remote = $remote; + $this->displayName = $displayName; } /** @@ -60,6 +63,11 @@ class CloudId implements ICloudId { } public function getDisplayId(): string { + if ($this->displayName) { + $atPos = strrpos($this->getId(), '@'); + $atHost = substr($this->getId(), $atPos); + return $this->displayName . $atHost; + } return str_replace('https://', '', str_replace('http://', '', $this->getId())); } diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index a5ebc98c1fd..d99fc350520 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -29,10 +29,18 @@ declare(strict_types=1); namespace OC\Federation; +use OCP\Contacts\IManager; use OCP\Federation\ICloudId; use OCP\Federation\ICloudIdManager; class CloudIdManager implements ICloudIdManager { + /** @var IManager */ + private $contactsManager; + + public function __construct(IManager $contactsManager) { + $this->contactsManager = $contactsManager; + } + /** * @param string $cloudId * @return ICloudId @@ -60,23 +68,32 @@ class CloudIdManager implements ICloudIdManager { $invalidPos = min($posSlash, $posColon); } - // Find the last @ before $invalidPos - $pos = $lastAtPos = 0; - while ($lastAtPos !== false && $lastAtPos <= $invalidPos) { - $pos = $lastAtPos; - $lastAtPos = strpos($id, '@', $pos + 1); - } + $lastValidAtPos = strrpos($id, '@', $invalidPos - strlen($id)); - if ($pos !== false) { - $user = substr($id, 0, $pos); - $remote = substr($id, $pos + 1); + if ($lastValidAtPos !== false) { + $user = substr($id, 0, $lastValidAtPos); + $remote = substr($id, $lastValidAtPos + 1); if (!empty($user) && !empty($remote)) { - return new CloudId($id, $user, $remote); + return new CloudId($id, $user, $remote, $this->getDisplayNameFromContact($id)); } } throw new \InvalidArgumentException('Invalid cloud id'); } + protected function getDisplayNameFromContact(string $cloudId): ?string { + $addressBookEntries = $this->contactsManager->search($cloudId, ['CLOUD']); + foreach ($addressBookEntries as $entry) { + if (isset($entry['CLOUD'])) { + foreach ($entry['CLOUD'] as $cloudID) { + if ($cloudID === $cloudId) { + return $entry['FN']; + } + } + } + } + return null; + } + /** * @param string $user * @param string $remote @@ -84,7 +101,17 @@ class CloudIdManager implements ICloudIdManager { */ public function getCloudId(string $user, string $remote): ICloudId { // TODO check what the correct url is for remote (asking the remote) - return new CloudId($user. '@' . $remote, $user, $remote); + $fixedRemote = $this->fixRemoteURL($remote); + if (strpos($fixedRemote, 'http://') === 0) { + $host = substr($fixedRemote, strlen('http://')); + } elseif (strpos($fixedRemote, 'https://') === 0) { + $host = substr($fixedRemote, strlen('https://')); + } else { + $host = $fixedRemote; + } + $id = $user . '@' . $remote; + $displayName = $this->getDisplayNameFromContact($user . '@' . $host); + return new CloudId($id, $user, $fixedRemote, $displayName); } /** diff --git a/lib/private/Files/ObjectStore/Azure.php b/lib/private/Files/ObjectStore/Azure.php index 0b65a6b80e5..2ef13d60c56 100644 --- a/lib/private/Files/ObjectStore/Azure.php +++ b/lib/private/Files/ObjectStore/Azure.php @@ -130,4 +130,8 @@ class Azure implements IObjectStore { } } } + + public function copyObject($from, $to) { + $this->getBlobClient()->copyBlob($this->containerName, $to, $this->containerName, $from); + } } diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index e675064eb1f..e855c166612 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -33,10 +33,15 @@ use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CountWrapper; use Icewind\Streams\IteratorDirectory; use OC\Files\Cache\CacheEntry; +use OC\Files\Storage\PolyFill\CopyDirectory; +use OCP\Files\Cache\ICacheEntry; +use OCP\Files\FileInfo; use OCP\Files\NotFoundException; use OCP\Files\ObjectStore\IObjectStore; class ObjectStoreStorage extends \OC\Files\Storage\Common { + use CopyDirectory; + /** * @var \OCP\Files\ObjectStore\IObjectStore $objectStore */ @@ -319,7 +324,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { } else { return false; } - // no break + // no break case 'w': case 'wb': case 'w+': @@ -474,7 +479,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { if ($size === null) { $countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) { $this->getCache()->update($fileId, [ - 'size' => $writtenSize + 'size' => $writtenSize, ]); $size = $writtenSize; }); @@ -523,4 +528,59 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common { public function getObjectStore(): IObjectStore { return $this->objectStore; } + + public function copy($path1, $path2) { + $path1 = $this->normalizePath($path1); + $path2 = $this->normalizePath($path2); + + $cache = $this->getCache(); + $sourceEntry = $cache->get($path1); + if (!$sourceEntry) { + throw new NotFoundException('Source object not found'); + } + + $this->copyInner($sourceEntry, $path2); + + return true; + } + + private function copyInner(ICacheEntry $sourceEntry, string $to) { + $cache = $this->getCache(); + + if ($sourceEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) { + if ($cache->inCache($to)) { + $cache->remove($to); + } + $this->mkdir($to); + + foreach ($cache->getFolderContentsById($sourceEntry->getId()) as $child) { + $this->copyInner($child, $to . '/' . $child->getName()); + } + } else { + $this->copyFile($sourceEntry, $to); + } + } + + private function copyFile(ICacheEntry $sourceEntry, string $to) { + $cache = $this->getCache(); + + $sourceUrn = $this->getURN($sourceEntry->getId()); + + $cache->copyFromCache($cache, $sourceEntry, $to); + $targetEntry = $cache->get($to); + + if (!$targetEntry) { + throw new \Exception('Target not in cache after copy'); + } + + $targetUrn = $this->getURN($targetEntry->getId()); + + try { + $this->objectStore->copyObject($sourceUrn, $targetUrn); + } catch (\Exception $e) { + $cache->remove($to); + + throw $e; + } + } } diff --git a/lib/private/Files/ObjectStore/S3ObjectTrait.php b/lib/private/Files/ObjectStore/S3ObjectTrait.php index a390c6b4c7d..80b8a6f132d 100644 --- a/lib/private/Files/ObjectStore/S3ObjectTrait.php +++ b/lib/private/Files/ObjectStore/S3ObjectTrait.php @@ -124,4 +124,8 @@ trait S3ObjectTrait { public function objectExists($urn) { return $this->getConnection()->doesObjectExist($this->bucket, $urn); } + + public function copyObject($from, $to) { + $this->getConnection()->copy($this->getBucket(), $from, $this->getBucket(), $to); + } } diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php index a7551385b34..acf46758956 100644 --- a/lib/private/Files/ObjectStore/StorageObjectStore.php +++ b/lib/private/Files/ObjectStore/StorageObjectStore.php @@ -93,4 +93,8 @@ class StorageObjectStore implements IObjectStore { public function objectExists($urn) { return $this->storage->file_exists($urn); } + + public function copyObject($from, $to) { + $this->storage->copy($from, $to); + } } diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php index 5ee924c9de6..1b0888b0700 100644 --- a/lib/private/Files/ObjectStore/Swift.php +++ b/lib/private/Files/ObjectStore/Swift.php @@ -87,13 +87,13 @@ class Swift implements IObjectStore { if (filesize($tmpFile) < SWIFT_SEGMENT_SIZE) { $this->getContainer()->createObject([ 'name' => $urn, - 'stream' => stream_for($handle) + 'stream' => stream_for($handle), ]); } else { $this->getContainer()->createLargeObject([ 'name' => $urn, 'stream' => stream_for($handle), - 'segmentSize' => SWIFT_SEGMENT_SIZE + 'segmentSize' => SWIFT_SEGMENT_SIZE, ]); } } @@ -114,7 +114,7 @@ class Swift implements IObjectStore { 'stream' => true, 'headers' => [ 'X-Auth-Token' => $tokenId, - 'Cache-Control' => 'no-cache' + 'Cache-Control' => 'no-cache', ], ] ); @@ -149,4 +149,10 @@ class Swift implements IObjectStore { public function objectExists($urn) { return $this->getContainer()->objectExists($urn); } + + public function copyObject($from, $to) { + $this->getContainer()->getObject($from)->copy([ + 'destination' => $this->getContainer()->name . '/' . $to + ]); + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 275caf306e2..b426c9c454d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -117,6 +117,7 @@ use OC\Preview\GeneratorHelper; use OC\Remote\Api\ApiFactory; use OC\Remote\InstanceFactory; use OC\RichObjectStrings\Validator; +use OC\Route\Router; use OC\Security\Bruteforce\Throttler; use OC\Security\CertificateManager; use OC\Security\CredentialsManager; @@ -751,7 +752,7 @@ class Server extends ServerContainer implements IServerContainer { /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('JobList', IJobList::class); - $this->registerService(IRouter::class, function (Server $c) { + $this->registerService(Router::class, function (Server $c) { $cacheFactory = $c->get(ICacheFactory::class); $logger = $c->get(ILogger::class); if ($cacheFactory->isLocalCacheAvailable()) { @@ -761,6 +762,7 @@ class Server extends ServerContainer implements IServerContainer { } return $router; }); + $this->registerAlias(IRouter::class, Router::class); /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('Router', IRouter::class); @@ -1247,7 +1249,7 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { - return new CloudIdManager(); + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); }); $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); @@ -2275,7 +2277,7 @@ class Server extends ServerContainer implements IServerContainer { try { /** @var ILogger $logger */ $logger = $container->get(ILogger::class); - $logger->debug('The requested alias "' . $alias . '" is depreacted. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); } catch (ContainerExceptionInterface $e) { // Could not get logger. Continue } diff --git a/lib/private/SubAdmin.php b/lib/private/SubAdmin.php index 3239fb27af8..a8769f28023 100644 --- a/lib/private/SubAdmin.php +++ b/lib/private/SubAdmin.php @@ -93,7 +93,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin { ]) ->execute(); - /** @depreacted 21.0.0 - use type SubAdminAddedEvent instead */ + /** @deprecated 21.0.0 - use type SubAdminAddedEvent instead */ $this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]); $event = new SubAdminAddedEvent($group, $user); $this->eventDispatcher->dispatchTyped($event); @@ -112,7 +112,7 @@ class SubAdmin extends PublicEmitter implements ISubAdmin { ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) ->execute(); - /** @depreacted 21.0.0 - use type SubAdminRemovedEvent instead */ + /** @deprecated 21.0.0 - use type SubAdminRemovedEvent instead */ $this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]); $event = new SubAdminRemovedEvent($group, $user); $this->eventDispatcher->dispatchTyped($event); diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index e18081f3a8d..ebe799bf4f8 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -160,7 +160,7 @@ class JSConfigHelper { $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null; if ($defaultInternalExpireDateEnabled) { $defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); - $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_internal_enforce_expire_date', 'no') === 'yes'; + $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; } $countOfDataLocation = 0; diff --git a/lib/private/legacy/OC_DB.php b/lib/private/legacy/OC_DB.php index 0853661c090..b92fd5e8112 100644 --- a/lib/private/legacy/OC_DB.php +++ b/lib/private/legacy/OC_DB.php @@ -55,7 +55,7 @@ class OC_DB { * @param bool|null $isManipulation * @throws \OC\DatabaseException * @return OC_DB_StatementWrapper prepared SQL query - * @depreacted 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead + * @deprecated 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead * * SQL query via Doctrine prepare(), needs to be execute()'d! */ @@ -117,7 +117,7 @@ class OC_DB { * @param array $parameters * @return OC_DB_StatementWrapper * @throws \OC\DatabaseException - * @depreacted 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead + * @deprecated 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead */ public static function executeAudited($stmt, array $parameters = []) { if (is_string($stmt)) { |