diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Http/Client/ClientService.php | 21 | ||||
-rw-r--r-- | lib/private/Metadata/FileMetadataMapper.php | 30 | ||||
-rw-r--r-- | lib/private/Metadata/Provider/ExifProvider.php | 8 | ||||
-rw-r--r-- | lib/private/User/User.php | 2 | ||||
-rw-r--r-- | lib/public/UserMigration/ISizeEstimationMigrator.php | 3 |
5 files changed, 54 insertions, 10 deletions
diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php index bbc2330176f..d0640680124 100644 --- a/lib/private/Http/Client/ClientService.php +++ b/lib/private/Http/Client/ClientService.php @@ -29,11 +29,14 @@ namespace OC\Http\Client; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\CurlHandler; +use GuzzleHttp\Middleware; +use OCP\Diagnostics\IEventLogger; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\ICertificateManager; use OCP\IConfig; use OCP\Security\IRemoteHostValidator; +use Psr\Http\Message\RequestInterface; /** * Class ClientService @@ -48,15 +51,20 @@ class ClientService implements IClientService { /** @var DnsPinMiddleware */ private $dnsPinMiddleware; private IRemoteHostValidator $remoteHostValidator; + private IEventLogger $eventLogger; - public function __construct(IConfig $config, - ICertificateManager $certificateManager, - DnsPinMiddleware $dnsPinMiddleware, - IRemoteHostValidator $remoteHostValidator) { + public function __construct( + IConfig $config, + ICertificateManager $certificateManager, + DnsPinMiddleware $dnsPinMiddleware, + IRemoteHostValidator $remoteHostValidator, + IEventLogger $eventLogger, + ) { $this->config = $config; $this->certificateManager = $certificateManager; $this->dnsPinMiddleware = $dnsPinMiddleware; $this->remoteHostValidator = $remoteHostValidator; + $this->eventLogger = $eventLogger; } /** @@ -66,6 +74,11 @@ class ClientService implements IClientService { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); $stack->push($this->dnsPinMiddleware->addDnsPinning()); + $stack->push(Middleware::tap(function (RequestInterface $request) { + $this->eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget()); + }, function () { + $this->eventLogger->end('http:request'); + }), 'event logger'); $client = new GuzzleClient(['handler' => $stack]); diff --git a/lib/private/Metadata/FileMetadataMapper.php b/lib/private/Metadata/FileMetadataMapper.php index 594ac5eafba..003ab13126e 100644 --- a/lib/private/Metadata/FileMetadataMapper.php +++ b/lib/private/Metadata/FileMetadataMapper.php @@ -60,7 +60,7 @@ class FileMetadataMapper extends QBMapper { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT_ARRAY))) + ->where($qb->expr()->eq('id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('group_name', $qb->createNamedParameter($groupName, IQueryBuilder::PARAM_STR))); return $this->findEntity($qb); @@ -111,7 +111,7 @@ class FileMetadataMapper extends QBMapper { /** * Updates an entry in the db from an entity * - * @param Entity $entity the entity that should be created + * @param FileMetadata $entity the entity that should be created * @return FileMetadata the saved entity with the set id * @throws Exception * @throws \InvalidArgumentException if entity has no id @@ -148,4 +148,30 @@ class FileMetadataMapper extends QBMapper { return $entity; } + + /** + * Override the insertOrUpdate as we could be in a transaction in which case we can not afford on error. + * + * @param FileMetadata $entity the entity that should be created/updated + * @return FileMetadata the saved entity with the (new) id + * @throws Exception + * @throws \InvalidArgumentException if entity has no id + */ + public function insertOrUpdate(Entity $entity): FileMetadata { + try { + $existingEntity = $this->findForGroupForFile($entity->getId(), $entity->getGroupName()); + } catch (\Throwable) { + $existingEntity = null; + } + + if ($existingEntity !== null) { + if ($entity->getValue() !== $existingEntity->getValue()) { + return $this->update($entity); + } else { + return $existingEntity; + } + } else { + return parent::insertOrUpdate($entity); + } + } } diff --git a/lib/private/Metadata/Provider/ExifProvider.php b/lib/private/Metadata/Provider/ExifProvider.php index 4e211e7b6c4..b1598abbbc8 100644 --- a/lib/private/Metadata/Provider/ExifProvider.php +++ b/lib/private/Metadata/Provider/ExifProvider.php @@ -44,11 +44,15 @@ class ExifProvider implements IMetadataProvider { return extension_loaded('exif'); } - /** @return array{'gps': FileMetadata, 'size': FileMetadata} */ + /** @return array{'gps'?: FileMetadata, 'size'?: FileMetadata} */ public function execute(File $file): array { $exifData = []; $fileDescriptor = $file->fopen('rb'); + if ($fileDescriptor === false) { + return []; + } + $data = null; try { // Needed to make reading exif data reliable. @@ -107,7 +111,7 @@ class ExifProvider implements IMetadataProvider { } public static function getMimetypesSupported(): string { - return '/image\/.*/'; + return '/image\/(png|jpeg|heif|webp|tiff)/'; } /** diff --git a/lib/private/User/User.php b/lib/private/User/User.php index c3d8af6f358..ff357a3badb 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -416,7 +416,7 @@ class User implements IUser { * @return bool */ public function canChangeDisplayName() { - if (!$this->config->getSystemValueBool('allow_user_to_change_display_name')) { + if (!$this->config->getSystemValueBool('allow_user_to_change_display_name', true)) { return false; } return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); diff --git a/lib/public/UserMigration/ISizeEstimationMigrator.php b/lib/public/UserMigration/ISizeEstimationMigrator.php index 05abe48ea8f..46664bd7390 100644 --- a/lib/public/UserMigration/ISizeEstimationMigrator.php +++ b/lib/public/UserMigration/ISizeEstimationMigrator.php @@ -38,6 +38,7 @@ interface ISizeEstimationMigrator { * Should be fast, favor performance over accuracy. * * @since 25.0.0 + * @since 27.0.0 return value may overflow from int to float */ - public function getEstimatedExportSize(IUser $user): int; + public function getEstimatedExportSize(IUser $user): int|float; } |