summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php22
-rw-r--r--lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php3
-rw-r--r--lib/private/Authentication/Token/PublicKeyTokenProvider.php106
-rw-r--r--lib/private/Console/TimestampFormatter.php6
-rw-r--r--lib/private/Files/Cache/Scanner.php14
-rw-r--r--lib/private/Files/Node/Node.php6
-rw-r--r--lib/private/Files/ObjectStore/ObjectStoreStorage.php89
-rw-r--r--lib/private/Files/ObjectStore/S3.php25
-rw-r--r--lib/private/Files/Storage/Common.php3
-rw-r--r--lib/private/Files/Storage/Wrapper/Encryption.php4
-rw-r--r--lib/private/Files/Type/Loader.php59
-rw-r--r--lib/private/Files/Utils/Scanner.php27
-rw-r--r--lib/private/KnownUser/KnownUserMapper.php2
-rw-r--r--lib/private/Metadata/FileMetadataMapper.php7
-rw-r--r--lib/private/Preview/Bundled.php4
-rw-r--r--lib/private/Preview/Generator.php140
-rw-r--r--lib/private/Profile/ProfileManager.php2
-rw-r--r--lib/private/Profiler/Profiler.php18
-rw-r--r--lib/private/Server.php4
-rw-r--r--lib/private/Session/Internal.php1
-rw-r--r--lib/private/Settings/AuthorizedGroupMapper.php3
-rw-r--r--lib/private/SpeechToText/SpeechToTextManager.php124
-rw-r--r--lib/private/SpeechToText/TranscriptionJob.php104
-rw-r--r--lib/private/Tagging/TagMapper.php2
-rw-r--r--lib/private/Updater.php2
-rw-r--r--lib/private/Updater/Changes.php (renamed from lib/private/Updater/ChangesResult.php)4
-rw-r--r--lib/private/Updater/ChangesCheck.php6
-rw-r--r--lib/private/Updater/ChangesMapper.php7
28 files changed, 559 insertions, 235 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 9a6c298419a..8fcafab2d87 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -33,6 +33,7 @@ use Closure;
use OCP\Calendar\Resource\IBackend as IResourceBackend;
use OCP\Calendar\Room\IBackend as IRoomBackend;
use OCP\Collaboration\Reference\IReferenceProvider;
+use OCP\SpeechToText\ISpeechToTextProvider;
use OCP\Talk\ITalkBackend;
use OCP\Translation\ITranslationProvider;
use RuntimeException;
@@ -111,6 +112,9 @@ class RegistrationContext {
/** @var ServiceRegistration<IHandler>[] */
private $wellKnownHandlers = [];
+ /** @var ServiceRegistration<ISpeechToTextProvider>[] */
+ private $speechToTextProviders = [];
+
/** @var ServiceRegistration<ICustomTemplateProvider>[] */
private $templateProviders = [];
@@ -252,6 +256,13 @@ class RegistrationContext {
);
}
+ public function registerSpeechToTextProvider(string $providerClass): void {
+ $this->context->registerSpeechToTextProvider(
+ $this->appId,
+ $providerClass
+ );
+ }
+
public function registerTemplateProvider(string $providerClass): void {
$this->context->registerTemplateProvider(
$this->appId,
@@ -414,6 +425,10 @@ class RegistrationContext {
$this->wellKnownHandlers[] = new ServiceRegistration($appId, $class);
}
+ public function registerSpeechToTextProvider(string $appId, string $class): void {
+ $this->speechToTextProviders[] = new ServiceRegistration($appId, $class);
+ }
+
public function registerTemplateProvider(string $appId, string $class): void {
$this->templateProviders[] = new ServiceRegistration($appId, $class);
}
@@ -686,6 +701,13 @@ class RegistrationContext {
}
/**
+ * @return ServiceRegistration<ISpeechToTextProvider>[]
+ */
+ public function getSpeechToTextProviders(): array {
+ return $this->speechToTextProviders;
+ }
+
+ /**
* @return ServiceRegistration<ICustomTemplateProvider>[]
*/
public function getTemplateProviders(): array {
diff --git a/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php b/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php
index eca03896953..28092331a22 100644
--- a/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php
+++ b/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
index 6e3bcec5c99..f5fcd4dcef2 100644
--- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php
+++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
@@ -327,18 +327,20 @@ class PublicKeyTokenProvider implements IProvider {
throw new InvalidTokenException("Invalid token type");
}
- // When changing passwords all temp tokens are deleted
- $this->mapper->deleteTempToken($token);
-
- // Update the password for all tokens
- $tokens = $this->mapper->getTokenByUser($token->getUID());
- $hashedPassword = $this->hashPassword($password);
- foreach ($tokens as $t) {
- $publicKey = $t->getPublicKey();
- $t->setPassword($this->encryptPassword($password, $publicKey));
- $t->setPasswordHash($hashedPassword);
- $this->updateToken($t);
- }
+ $this->atomic(function () use ($password, $token) {
+ // When changing passwords all temp tokens are deleted
+ $this->mapper->deleteTempToken($token);
+
+ // Update the password for all tokens
+ $tokens = $this->mapper->getTokenByUser($token->getUID());
+ $hashedPassword = $this->hashPassword($password);
+ foreach ($tokens as $t) {
+ $publicKey = $t->getPublicKey();
+ $t->setPassword($this->encryptPassword($password, $publicKey));
+ $t->setPasswordHash($hashedPassword);
+ $this->updateToken($t);
+ }
+ }, $this->db);
}
private function hashPassword(string $password): string {
@@ -489,49 +491,51 @@ class PublicKeyTokenProvider implements IProvider {
return;
}
- // Update the password for all tokens
- $tokens = $this->mapper->getTokenByUser($uid);
- $newPasswordHash = null;
-
- /**
- * - true: The password hash could not be verified anymore
- * and the token needs to be updated with the newly encrypted password
- * - false: The hash could still be verified
- * - missing: The hash needs to be verified
- */
- $hashNeedsUpdate = [];
-
- foreach ($tokens as $t) {
- if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) {
- if ($t->getPasswordHash() === null) {
- $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
- } elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
- $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
- } else {
- $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false;
+ $this->atomic(function () use ($password, $uid) {
+ // Update the password for all tokens
+ $tokens = $this->mapper->getTokenByUser($uid);
+ $newPasswordHash = null;
+
+ /**
+ * - true: The password hash could not be verified anymore
+ * and the token needs to be updated with the newly encrypted password
+ * - false: The hash could still be verified
+ * - missing: The hash needs to be verified
+ */
+ $hashNeedsUpdate = [];
+
+ foreach ($tokens as $t) {
+ if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) {
+ if ($t->getPasswordHash() === null) {
+ $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
+ } elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
+ $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
+ } else {
+ $hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false;
+ }
}
- }
- $needsUpdating = $hashNeedsUpdate[$t->getPasswordHash() ?: ''] ?? true;
-
- if ($needsUpdating) {
- if ($newPasswordHash === null) {
- $newPasswordHash = $this->hashPassword($password);
+ $needsUpdating = $hashNeedsUpdate[$t->getPasswordHash() ?: ''] ?? true;
+
+ if ($needsUpdating) {
+ if ($newPasswordHash === null) {
+ $newPasswordHash = $this->hashPassword($password);
+ }
+
+ $publicKey = $t->getPublicKey();
+ $t->setPassword($this->encryptPassword($password, $publicKey));
+ $t->setPasswordHash($newPasswordHash);
+ $t->setPasswordInvalid(false);
+ $this->updateToken($t);
}
-
- $publicKey = $t->getPublicKey();
- $t->setPassword($this->encryptPassword($password, $publicKey));
- $t->setPasswordHash($newPasswordHash);
- $t->setPasswordInvalid(false);
- $this->updateToken($t);
}
- }
- // If password hashes are different we update them all to be equal so
- // that the next execution only needs to verify once
- if (count($hashNeedsUpdate) > 1) {
- $newPasswordHash = $this->hashPassword($password);
- $this->mapper->updateHashesForUser($uid, $newPasswordHash);
- }
+ // If password hashes are different we update them all to be equal so
+ // that the next execution only needs to verify once
+ if (count($hashNeedsUpdate) > 1) {
+ $newPasswordHash = $this->hashPassword($password);
+ $this->mapper->updateHashesForUser($uid, $newPasswordHash);
+ }
+ }, $this->db);
}
private function logOpensslError() {
diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php
index c25ed578805..8d74c28e94f 100644
--- a/lib/private/Console/TimestampFormatter.php
+++ b/lib/private/Console/TimestampFormatter.php
@@ -94,11 +94,11 @@ class TimestampFormatter implements OutputFormatterInterface {
/**
* Formats a message according to the given styles.
*
- * @param string $message The message to style
- * @return string The styled message, prepended with a timestamp using the
+ * @param string|null $message The message to style
+ * @return string|null The styled message, prepended with a timestamp using the
* log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00"
*/
- public function format($message) {
+ public function format(?string $message): ?string {
if (!$this->formatter->isDecorated()) {
// Don't add anything to the output when we shouldn't
return $this->formatter->format($message);
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
index 05e24287a7d..d390037d0b8 100644
--- a/lib/private/Files/Cache/Scanner.php
+++ b/lib/private/Files/Cache/Scanner.php
@@ -38,6 +38,7 @@ namespace OC\Files\Cache;
use Doctrine\DBAL\Exception;
use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException;
+use OCP\Files\NotFoundException;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\Lock\ILockingProvider;
use OC\Files\Storage\Wrapper\Encoding;
@@ -328,10 +329,15 @@ class Scanner extends BasicEmitter implements IScanner {
}
}
try {
- $data = $this->scanFile($path, $reuse, -1, null, $lock);
- if ($data && $data['mimetype'] === 'httpd/unix-directory') {
- $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock, $data);
- $data['size'] = $size;
+ try {
+ $data = $this->scanFile($path, $reuse, -1, null, $lock);
+ if ($data && $data['mimetype'] === 'httpd/unix-directory') {
+ $size = $this->scanChildren($path, $recursive, $reuse, $data['fileid'], $lock, $data);
+ $data['size'] = $size;
+ }
+ } catch (NotFoundException $e) {
+ $this->removeFromCache($path);
+ return null;
}
} finally {
if ($lock) {
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php
index 2f88cc3a15a..0eef2716141 100644
--- a/lib/private/Files/Node/Node.php
+++ b/lib/private/Files/Node/Node.php
@@ -37,6 +37,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Lock\LockedException;
+use OCP\PreConditionNotMetException;
use Symfony\Component\EventDispatcher\GenericEvent;
// FIXME: this class really should be abstract
@@ -52,7 +53,7 @@ class Node implements \OCP\Files\Node {
protected $root;
/**
- * @var string $path
+ * @var string $path Absolute path to the node (e.g. /admin/files/folder/file)
*/
protected $path;
@@ -72,6 +73,9 @@ class Node implements \OCP\Files\Node {
* @param FileInfo $fileInfo
*/
public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null, bool $infoHasSubMountsIncluded = true) {
+ if (Filesystem::normalizePath($view->getRoot()) !== '/') {
+ throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
+ }
$this->view = $view;
$this->root = $root;
$this->path = $path;
diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
index 4ca00cf6a16..921c50fd958 100644
--- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php
+++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php
@@ -27,6 +27,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OC\Files\ObjectStore;
use Aws\S3\Exception\S3Exception;
@@ -97,6 +98,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
public function mkdir($path) {
$path = $this->normalizePath($path);
if ($this->file_exists($path)) {
+ $this->logger->warning("Tried to create an object store folder that already exists: $path");
return false;
}
@@ -120,10 +122,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
if ($parentType === false) {
if (!$this->mkdir($parent)) {
// something went wrong
+ $this->logger->warning("Parent folder ($parent) doesn't exist and couldn't be created");
return false;
}
} elseif ($parentType === 'file') {
// parent is a file
+ $this->logger->warning("Parent ($parent) is a file");
return false;
}
// finally create the new dir
@@ -177,63 +181,65 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
public function rmdir($path) {
$path = $this->normalizePath($path);
+ $entry = $this->getCache()->get($path);
- if (!$this->is_dir($path)) {
- return false;
- }
-
- if (!$this->rmObjects($path)) {
+ if (!$entry || $entry->getMimeType() !== ICacheEntry::DIRECTORY_MIMETYPE) {
return false;
}
- $this->getCache()->remove($path);
-
- return true;
+ return $this->rmObjects($entry);
}
- private function rmObjects($path) {
- $children = $this->getCache()->getFolderContents($path);
+ private function rmObjects(ICacheEntry $entry): bool {
+ $children = $this->getCache()->getFolderContentsById($entry->getId());
foreach ($children as $child) {
- if ($child['mimetype'] === 'httpd/unix-directory') {
- if (!$this->rmObjects($child['path'])) {
+ if ($child->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
+ if (!$this->rmObjects($child)) {
return false;
}
} else {
- if (!$this->unlink($child['path'])) {
+ if (!$this->rmObject($child)) {
return false;
}
}
}
+ $this->getCache()->remove($entry->getPath());
+
return true;
}
public function unlink($path) {
$path = $this->normalizePath($path);
- $stat = $this->stat($path);
+ $entry = $this->getCache()->get($path);
- if ($stat && isset($stat['fileid'])) {
- if ($stat['mimetype'] === 'httpd/unix-directory') {
- return $this->rmdir($path);
- }
- try {
- $this->objectStore->deleteObject($this->getURN($stat['fileid']));
- } catch (\Exception $ex) {
- if ($ex->getCode() !== 404) {
- $this->logger->logException($ex, [
- 'app' => 'objectstore',
- 'message' => 'Could not delete object ' . $this->getURN($stat['fileid']) . ' for ' . $path,
- ]);
- return false;
- }
- //removing from cache is ok as it does not exist in the objectstore anyway
+ if ($entry instanceof ICacheEntry) {
+ if ($entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) {
+ return $this->rmObjects($entry);
+ } else {
+ return $this->rmObject($entry);
}
- $this->getCache()->remove($path);
- return true;
}
return false;
}
+ public function rmObject(ICacheEntry $entry): bool {
+ try {
+ $this->objectStore->deleteObject($this->getURN($entry->getId()));
+ } catch (\Exception $ex) {
+ if ($ex->getCode() !== 404) {
+ $this->logger->logException($ex, [
+ 'app' => 'objectstore',
+ 'message' => 'Could not delete object ' . $this->getURN($entry->getId()) . ' for ' . $entry->getPath(),
+ ]);
+ return false;
+ }
+ //removing from cache is ok as it does not exist in the objectstore anyway
+ }
+ $this->getCache()->remove($entry->getPath());
+ return true;
+ }
+
public function stat($path) {
$path = $this->normalizePath($path);
$cacheEntry = $this->getCache()->get($path);
@@ -557,7 +563,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
return $this->objectStore;
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
+ public function copyFromStorage(
+ IStorage $sourceStorage,
+ $sourceInternalPath,
+ $targetInternalPath,
+ $preserveMtime = false
+ ) {
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
/** @var ObjectStoreStorage $sourceStorage */
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
@@ -645,7 +656,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
*
* @throws GenericFileException
*/
- public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, $size = null): ?array {
+ public function putChunkedWritePart(
+ string $targetPath,
+ string $writeToken,
+ string $chunkId,
+ $data,
+ $size = null
+ ): ?array {
if (!$this->objectStore instanceof IObjectStoreMultiPartUpload) {
throw new GenericFileException('Object store does not support multipart upload');
}
@@ -656,7 +673,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
$parts[$chunkId] = [
'PartNumber' => $chunkId,
- 'ETag' => trim($result->get('ETag'), '"')
+ 'ETag' => trim($result->get('ETag'), '"'),
];
return $parts[$chunkId];
}
@@ -680,11 +697,11 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
$stat['mimetype'] = $this->getMimeType($targetPath);
$this->getCache()->update($stat['fileid'], $stat);
}
- } catch (S3MultipartUploadException | S3Exception $e) {
+ } catch (S3MultipartUploadException|S3Exception $e) {
$this->objectStore->abortMultipartUpload($urn, $writeToken);
$this->logger->logException($e, [
'app' => 'objectstore',
- 'message' => 'Could not compete multipart upload ' . $urn. ' with uploadId ' . $writeToken
+ 'message' => 'Could not compete multipart upload ' . $urn . ' with uploadId ' . $writeToken,
]);
throw new GenericFileException('Could not write chunked file');
}
diff --git a/lib/private/Files/ObjectStore/S3.php b/lib/private/Files/ObjectStore/S3.php
index ebc8886f12d..76eee2bc962 100644
--- a/lib/private/Files/ObjectStore/S3.php
+++ b/lib/private/Files/ObjectStore/S3.php
@@ -69,13 +69,24 @@ class S3 implements IObjectStore, IObjectStoreMultiPartUpload {
}
public function getMultipartUploads(string $urn, string $uploadId): array {
- $parts = $this->getConnection()->listParts([
- 'Bucket' => $this->bucket,
- 'Key' => $urn,
- 'UploadId' => $uploadId,
- 'MaxParts' => 10000
- ]);
- return $parts->get('Parts') ?? [];
+ $parts = [];
+ $isTruncated = true;
+ $partNumberMarker = 0;
+
+ while ($isTruncated) {
+ $result = $this->getConnection()->listParts([
+ 'Bucket' => $this->bucket,
+ 'Key' => $urn,
+ 'UploadId' => $uploadId,
+ 'MaxParts' => 1000,
+ 'PartNumberMarker' => $partNumberMarker
+ ]);
+ $parts = array_merge($parts, $result->get('Parts') ?? []);
+ $isTruncated = $result->get('IsTruncated');
+ $partNumberMarker = $result->get('NextPartNumberMarker');
+ }
+
+ return $parts;
}
public function completeMultipartUpload(string $urn, string $uploadId, array $result): int {
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php
index b202c70b3ad..abbcf4ea433 100644
--- a/lib/private/Files/Storage/Common.php
+++ b/lib/private/Files/Storage/Common.php
@@ -207,6 +207,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
public function file_put_contents($path, $data) {
$handle = $this->fopen($path, "w");
+ if (!$handle) {
+ return false;
+ }
$this->removeCachedFile($path);
$count = fwrite($handle, $data);
fclose($handle);
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php
index 4d860e623e0..0eba59d2156 100644
--- a/lib/private/Files/Storage/Wrapper/Encryption.php
+++ b/lib/private/Files/Storage/Wrapper/Encryption.php
@@ -137,8 +137,10 @@ class Encryption extends Wrapper {
public function filesize($path): false|int|float {
$fullPath = $this->getFullPath($path);
- /** @var CacheEntry $info */
$info = $this->getCache()->get($path);
+ if ($info === false) {
+ return false;
+ }
if (isset($this->unencryptedSize[$fullPath])) {
$size = $this->unencryptedSize[$fullPath];
// update file cache
diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php
index bf5af36ec6e..32013bc3786 100644
--- a/lib/private/Files/Type/Loader.php
+++ b/lib/private/Files/Type/Loader.php
@@ -24,6 +24,9 @@
*/
namespace OC\Files\Type;
+use OC\DB\Exceptions\DbalException;
+use OCP\AppFramework\Db\TTransactional;
+use OCP\DB\Exception as DBException;
use OCP\Files\IMimeTypeLoader;
use OCP\IDBConnection;
@@ -33,6 +36,8 @@ use OCP\IDBConnection;
* @package OC\Files\Type
*/
class Loader implements IMimeTypeLoader {
+ use TTransactional;
+
/** @var IDBConnection */
private $dbConnection;
@@ -108,31 +113,49 @@ class Loader implements IMimeTypeLoader {
* Store a mimetype in the DB
*
* @param string $mimetype
- * @param int inserted ID
+ * @return int inserted ID
*/
protected function store($mimetype) {
- $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [
- 'mimetype' => $mimetype
- ]);
-
- $fetch = $this->dbConnection->getQueryBuilder();
- $fetch->select('id')
- ->from('mimetypes')
- ->where(
- $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype)
- ));
-
- $result = $fetch->execute();
- $row = $result->fetch();
- $result->closeCursor();
+ $row = $this->atomic(function () use ($mimetype) {
+ try {
+ $insert = $this->dbConnection->getQueryBuilder();
+ $insert->insert('mimetypes')
+ ->values([
+ 'mimetype' => $insert->createNamedParameter($mimetype)
+ ])
+ ->executeStatement();
+ return [
+ 'mimetype' => $mimetype,
+ 'id' => $insert->getLastInsertId(),
+ ];
+ } catch (DbalException $e) {
+ if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
+ throw $e;
+ }
+ $qb = $this->dbConnection->getQueryBuilder();
+ $row = $qb->select('id')
+ ->from('mimetypes')
+ ->where($qb->expr()->eq('mimetype', $qb->createNamedParameter($mimetype)))
+ ->executeQuery()
+ ->fetchOne();
+ if ($row) {
+ return [
+ 'mimetype' => $mimetype,
+ 'id' => $row['id'],
+ ];
+ }
+ throw new \Exception("Database threw an unique constraint on inserting a new mimetype, but couldn't return the ID for this very mimetype");
+ }
+ }, $this->dbConnection);
if (!$row) {
throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it");
}
+ $mimetypeId = (int) $row['id'];
- $this->mimetypes[$row['id']] = $mimetype;
- $this->mimetypeIds[$mimetype] = $row['id'];
- return $row['id'];
+ $this->mimetypes[$mimetypeId] = $mimetype;
+ $this->mimetypeIds[$mimetype] = $mimetypeId;
+ return $mimetypeId;
}
/**
diff --git a/lib/private/Files/Utils/Scanner.php b/lib/private/Files/Utils/Scanner.php
index dc220bc710d..277ce38175f 100644
--- a/lib/private/Files/Utils/Scanner.php
+++ b/lib/private/Files/Utils/Scanner.php
@@ -27,11 +27,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace OC\Files\Utils;
use OC\Files\Cache\Cache;
use OC\Files\Filesystem;
use OC\Files\Storage\FailedStorage;
+use OC\Files\Storage\Home;
use OC\ForbiddenException;
use OC\Hooks\PublicEmitter;
use OC\Lock\DBLockingProvider;
@@ -211,13 +213,24 @@ class Scanner extends PublicEmitter {
}
// if the home storage isn't writable then the scanner is run as the wrong user
- if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and
- (!$storage->isCreatable('') or !$storage->isCreatable('files'))
- ) {
- if ($storage->is_dir('files')) {
- throw new ForbiddenException();
- } else {// if the root exists in neither the cache nor the storage the user isn't setup yet
- break;
+ if ($storage->instanceOfStorage(Home::class)) {
+ /** @var Home $storage */
+ foreach (['', 'files'] as $path) {
+ if (!$storage->isCreatable($path)) {
+ $fullPath = $storage->getSourcePath($path);
+ if (!$storage->is_dir($path) && $storage->getCache()->inCache($path)) {
+ throw new NotFoundException("User folder $fullPath exists in cache but not on disk");
+ } elseif ($storage->is_dir($path)) {
+ $ownerUid = fileowner($fullPath);
+ $owner = posix_getpwuid($ownerUid);
+ $owner = $owner['name'] ?? $ownerUid;
+ $permissions = decoct(fileperms($fullPath));
+ throw new ForbiddenException("User folder $fullPath is not writable, folders is owned by $owner and has mode $permissions");
+ } else {
+ // if the root exists in neither the cache nor the storage the user isn't setup yet
+ break 2;
+ }
+ }
}
}
diff --git a/lib/private/KnownUser/KnownUserMapper.php b/lib/private/KnownUser/KnownUserMapper.php
index ce7dc9ead63..fd8f22cd0aa 100644
--- a/lib/private/KnownUser/KnownUserMapper.php
+++ b/lib/private/KnownUser/KnownUserMapper.php
@@ -30,6 +30,8 @@ use OCP\IDBConnection;
/**
* @method KnownUser mapRowToEntity(array $row)
+ *
+ * @template-extends QBMapper<KnownUser>
*/
class KnownUserMapper extends QBMapper {
/**
diff --git a/lib/private/Metadata/FileMetadataMapper.php b/lib/private/Metadata/FileMetadataMapper.php
index f3120e5e515..594ac5eafba 100644
--- a/lib/private/Metadata/FileMetadataMapper.php
+++ b/lib/private/Metadata/FileMetadataMapper.php
@@ -30,6 +30,9 @@ use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+/**
+ * @template-extends QBMapper<FileMetadata>
+ */
class FileMetadataMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'file_metadata', FileMetadata::class);
@@ -109,11 +112,11 @@ class FileMetadataMapper extends QBMapper {
* Updates an entry in the db from an entity
*
* @param Entity $entity the entity that should be created
- * @return Entity the saved entity with the set id
+ * @return FileMetadata the saved entity with the set id
* @throws Exception
* @throws \InvalidArgumentException if entity has no id
*/
- public function update(Entity $entity): Entity {
+ public function update(Entity $entity): FileMetadata {
if (!($entity instanceof FileMetadata)) {
throw new \Exception("Entity should be a FileMetadata entity");
}
diff --git a/lib/private/Preview/Bundled.php b/lib/private/Preview/Bundled.php
index df7f630dff7..2a408b90c4e 100644
--- a/lib/private/Preview/Bundled.php
+++ b/lib/private/Preview/Bundled.php
@@ -31,6 +31,10 @@ use OCP\IImage;
*/
abstract class Bundled extends ProviderV2 {
protected function extractThumbnail(File $file, string $path): ?IImage {
+ if ($file->getSize() === 0) {
+ return null;
+ }
+
$sourceTmp = \OC::$server->getTempManager()->getTemporaryFile();
$targetTmp = \OC::$server->getTempManager()->getTemporaryFile();
$this->tmpFiles[] = $sourceTmp;
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 47f2952c6e6..ed9474fafb2 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -137,6 +137,8 @@ class Generator {
}
$previewFolder = $this->getPreviewFolder($file);
+ // List every existing preview first instead of trying to find them one by one
+ $previewFiles = $previewFolder->getDirectoryListing();
$previewVersion = '';
if ($file instanceof IVersionedPreviewFile) {
@@ -150,7 +152,7 @@ class Generator {
&& preg_match(Imaginary::supportedMimeTypes(), $mimeType)
&& $this->config->getSystemValueString('preview_imaginary_url', 'invalid') !== 'invalid') {
$crop = $specifications[0]['crop'] ?? false;
- $preview = $this->getSmallImagePreview($previewFolder, $file, $mimeType, $previewVersion, $crop);
+ $preview = $this->getSmallImagePreview($previewFolder, $previewFiles, $file, $mimeType, $previewVersion, $crop);
if ($preview->getSize() === 0) {
$preview->delete();
@@ -161,7 +163,7 @@ class Generator {
}
// Get the max preview and infer the max preview sizes from that
- $maxPreview = $this->getMaxPreview($previewFolder, $file, $mimeType, $previewVersion);
+ $maxPreview = $this->getMaxPreview($previewFolder, $previewFiles, $file, $mimeType, $previewVersion);
$maxPreviewImage = null; // only load the image when we need it
if ($maxPreview->getSize() === 0) {
$maxPreview->delete();
@@ -197,7 +199,7 @@ class Generator {
// Try to get a cached preview. Else generate (and store) one
try {
try {
- $preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
+ $preview = $this->getCachedPreview($previewFiles, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
} catch (NotFoundException $e) {
if (!$this->previewManager->isMimeSupported($mimeType)) {
throw new NotFoundException();
@@ -208,6 +210,8 @@ class Generator {
}
$preview = $this->generatePreview($previewFolder, $maxPreviewImage, $width, $height, $crop, $maxWidth, $maxHeight, $previewVersion);
+ // New file, augment our array
+ $previewFiles[] = $preview;
}
} catch (\InvalidArgumentException $e) {
throw new NotFoundException("", 0, $e);
@@ -233,75 +237,19 @@ class Generator {
* Generate a small image straight away without generating a max preview first
* Preview generated is 256x256
*
+ * @param ISimpleFile[] $previewFiles
+ *
* @throws NotFoundException
*/
- private function getSmallImagePreview(ISimpleFolder $previewFolder, File $file, string $mimeType, string $prefix, bool $crop): ISimpleFile {
- $nodes = $previewFolder->getDirectoryListing();
-
- foreach ($nodes as $node) {
- $name = $node->getName();
- if (($prefix === '' || str_starts_with($name, $prefix))) {
- // Prefix match
- if (str_starts_with($name, $prefix . '256-256-crop') && $crop) {
- // Cropped image
- return $node;
- }
-
- if (str_starts_with($name, $prefix . '256-256.') && !$crop) {
- // Uncropped image
- return $node;
- }
- }
- }
-
- $previewProviders = $this->previewManager->getProviders();
- foreach ($previewProviders as $supportedMimeType => $providers) {
- // Filter out providers that does not support this mime
- if (!preg_match($supportedMimeType, $mimeType)) {
- continue;
- }
-
- foreach ($providers as $providerClosure) {
- $provider = $this->helper->getProvider($providerClosure);
- if (!($provider instanceof IProviderV2)) {
- continue;
- }
-
- if (!$provider->isAvailable($file)) {
- continue;
- }
-
- $preview = $this->helper->getThumbnail($provider, $file, 256, 256, $crop);
-
- if (!($preview instanceof IImage)) {
- continue;
- }
-
- // Try to get the extension.
- try {
- $ext = $this->getExtention($preview->dataMimeType());
- } catch (\InvalidArgumentException $e) {
- // Just continue to the next iteration if this preview doesn't have a valid mimetype
- continue;
- }
-
- $path = $this->generatePath(256, 256, $crop, $preview->dataMimeType(), $prefix);
- try {
- $file = $previewFolder->newFile($path);
- if ($preview instanceof IStreamImage) {
- $file->putContent($preview->resource());
- } else {
- $file->putContent($preview->data());
- }
- } catch (NotPermittedException $e) {
- throw new NotFoundException();
- }
+ private function getSmallImagePreview(ISimpleFolder $previewFolder, array $previewFiles, File $file, string $mimeType, string $prefix, bool $crop): ISimpleFile {
+ $width = 256;
+ $height = 256;
- return $file;
- }
+ try {
+ return $this->getCachedPreview($previewFiles, $width, $height, $crop, $mimeType, $prefix);
+ } catch (NotFoundException $e) {
+ return $this->generateProviderPreview($previewFolder, $file, $width, $height, $crop, false, $mimeType, $prefix);
}
-
- throw new NotFoundException('No provider successfully handled the preview generation');
}
/**
@@ -398,22 +346,30 @@ class Generator {
/**
* @param ISimpleFolder $previewFolder
+ * @param ISimpleFile[] $previewFiles
* @param File $file
* @param string $mimeType
* @param string $prefix
* @return ISimpleFile
* @throws NotFoundException
*/
- private function getMaxPreview(ISimpleFolder $previewFolder, File $file, $mimeType, $prefix) {
- $nodes = $previewFolder->getDirectoryListing();
-
- foreach ($nodes as $node) {
+ private function getMaxPreview(ISimpleFolder $previewFolder, array $previewFiles, File $file, $mimeType, $prefix) {
+ // We don't know the max preview size, so we can't use getCachedPreview.
+ // It might have been generated with a higher resolution than the current value.
+ foreach ($previewFiles as $node) {
$name = $node->getName();
if (($prefix === '' || strpos($name, $prefix) === 0) && strpos($name, 'max')) {
return $node;
}
}
+ $maxWidth = $this->config->getSystemValueInt('preview_max_x', 4096);
+ $maxHeight = $this->config->getSystemValueInt('preview_max_y', 4096);
+
+ return $this->generateProviderPreview($previewFolder, $file, $maxWidth, $maxHeight, false, true, $mimeType, $prefix);
+ }
+
+ private function generateProviderPreview(ISimpleFolder $previewFolder, File $file, int $width, int $height, bool $crop, bool $max, string $mimeType, string $prefix) {
$previewProviders = $this->previewManager->getProviders();
foreach ($previewProviders as $supportedMimeType => $providers) {
// Filter out providers that does not support this mime
@@ -431,13 +387,10 @@ class Generator {
continue;
}
- $maxWidth = $this->config->getSystemValueInt('preview_max_x', 4096);
- $maxHeight = $this->config->getSystemValueInt('preview_max_y', 4096);
-
$previewConcurrency = $this->getNumConcurrentPreviews('preview_concurrency_new');
$sem = self::guardWithSemaphore(self::SEMAPHORE_ID_NEW, $previewConcurrency);
try {
- $preview = $this->helper->getThumbnail($provider, $file, $maxWidth, $maxHeight);
+ $preview = $this->helper->getThumbnail($provider, $file, $width, $height);
} finally {
self::unguardWithSemaphore($sem);
}
@@ -446,15 +399,7 @@ class Generator {
continue;
}
- // Try to get the extention.
- try {
- $ext = $this->getExtention($preview->dataMimeType());
- } catch (\InvalidArgumentException $e) {
- // Just continue to the next iteration if this preview doesn't have a valid mimetype
- continue;
- }
-
- $path = $prefix . (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
+ $path = $this->generatePath($preview->width(), $preview->height(), $crop, $max, $preview->dataMimeType(), $prefix);
try {
$file = $previewFolder->newFile($path);
if ($preview instanceof IStreamImage) {
@@ -470,7 +415,7 @@ class Generator {
}
}
- throw new NotFoundException();
+ throw new NotFoundException('No provider successfully handled the preview generation');
}
/**
@@ -487,15 +432,19 @@ class Generator {
* @param int $width
* @param int $height
* @param bool $crop
+ * @param bool $max
* @param string $mimeType
* @param string $prefix
* @return string
*/
- private function generatePath($width, $height, $crop, $mimeType, $prefix) {
+ private function generatePath($width, $height, $crop, $max, $mimeType, $prefix) {
$path = $prefix . (string)$width . '-' . (string)$height;
if ($crop) {
$path .= '-crop';
}
+ if ($max) {
+ $path .= '-max';
+ }
$ext = $this->getExtention($mimeType);
$path .= '.' . $ext;
@@ -637,7 +586,8 @@ class Generator {
self::unguardWithSemaphore($sem);
}
- $path = $this->generatePath($width, $height, $crop, $preview->dataMimeType(), $prefix);
+
+ $path = $this->generatePath($width, $height, $crop, false, $preview->dataMimeType(), $prefix);
try {
$file = $previewFolder->newFile($path);
$file->putContent($preview->data());
@@ -649,7 +599,7 @@ class Generator {
}
/**
- * @param ISimpleFolder $previewFolder
+ * @param ISimpleFile[] $files Array of FileInfo, as the result of getDirectoryListing()
* @param int $width
* @param int $height
* @param bool $crop
@@ -659,10 +609,14 @@ class Generator {
*
* @throws NotFoundException
*/
- private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop, $mimeType, $prefix) {
- $path = $this->generatePath($width, $height, $crop, $mimeType, $prefix);
-
- return $previewFolder->getFile($path);
+ private function getCachedPreview($files, $width, $height, $crop, $mimeType, $prefix) {
+ $path = $this->generatePath($width, $height, $crop, false, $mimeType, $prefix);
+ foreach ($files as $file) {
+ if ($file->getName() === $path) {
+ return $file;
+ }
+ }
+ throw new NotFoundException();
}
/**
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php
index ddc0670604b..8de48994ff7 100644
--- a/lib/private/Profile/ProfileManager.php
+++ b/lib/private/Profile/ProfileManager.php
@@ -440,7 +440,7 @@ class ProfileManager {
],
IAccountManager::PROPERTY_DISPLAYNAME => [
'appId' => self::CORE_APP_ID,
- 'displayId' => $this->l10nFactory->get('lib')->t('Full name'),
+ 'displayId' => $this->l10nFactory->get('lib')->t('Display name'),
],
IAccountManager::PROPERTY_HEADLINE => [
'appId' => self::CORE_APP_ID,
diff --git a/lib/private/Profiler/Profiler.php b/lib/private/Profiler/Profiler.php
index 9fd5e76d592..40050b7bf43 100644
--- a/lib/private/Profiler/Profiler.php
+++ b/lib/private/Profiler/Profiler.php
@@ -61,11 +61,19 @@ class Profiler implements IProfiler {
}
public function loadProfile(string $token): ?IProfile {
- return $this->storage->read($token);
+ if ($this->storage) {
+ return $this->storage->read($token);
+ } else {
+ return null;
+ }
}
public function saveProfile(IProfile $profile): bool {
- return $this->storage->write($profile);
+ if ($this->storage) {
+ return $this->storage->write($profile);
+ } else {
+ return false;
+ }
}
public function collect(Request $request, Response $response): IProfile {
@@ -88,7 +96,11 @@ class Profiler implements IProfiler {
*/
public function find(?string $url, ?int $limit, ?string $method, ?int $start, ?int $end,
string $statusCode = null): array {
- return $this->storage->find($url, $limit, $method, $start, $end, $statusCode);
+ if ($this->storage) {
+ return $this->storage->find($url, $limit, $method, $start, $end, $statusCode);
+ } else {
+ return [];
+ }
}
public function dataProviders(): array {
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 80e03771888..bb4e217efa3 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -148,6 +148,7 @@ use OC\Security\VerificationToken\VerificationToken;
use OC\Session\CryptoWrapper;
use OC\Share20\ProviderFactory;
use OC\Share20\ShareHelper;
+use OC\SpeechToText\SpeechToTextManager;
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
use OC\Tagging\TagMapper;
use OC\Talk\Broker;
@@ -246,6 +247,7 @@ use OCP\Security\ISecureRandom;
use OCP\Security\ITrustedDomainHelper;
use OCP\Security\VerificationToken\IVerificationToken;
use OCP\Share\IShareHelper;
+use OCP\SpeechToText\ISpeechToTextManager;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\Talk\IBroker;
@@ -1457,6 +1459,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(ITranslationManager::class, TranslationManager::class);
+ $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
+
$this->connectDispatcher();
}
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php
index 87dd5ed6014..cae139018f8 100644
--- a/lib/private/Session/Internal.php
+++ b/lib/private/Session/Internal.php
@@ -107,6 +107,7 @@ class Internal extends Session {
$this->reopen();
$this->invoke('session_unset');
$this->regenerateId();
+ $this->invoke('session_write_close');
$this->startSession(true);
$_SESSION = [];
}
diff --git a/lib/private/Settings/AuthorizedGroupMapper.php b/lib/private/Settings/AuthorizedGroupMapper.php
index 4313ce60580..c7c39cc6758 100644
--- a/lib/private/Settings/AuthorizedGroupMapper.php
+++ b/lib/private/Settings/AuthorizedGroupMapper.php
@@ -32,6 +32,9 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
+/**
+ * @template-extends QBMapper<AuthorizedGroup>
+ */
class AuthorizedGroupMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'authorized_groups', AuthorizedGroup::class);
diff --git a/lib/private/SpeechToText/SpeechToTextManager.php b/lib/private/SpeechToText/SpeechToTextManager.php
new file mode 100644
index 00000000000..757fc02485e
--- /dev/null
+++ b/lib/private/SpeechToText/SpeechToTextManager.php
@@ -0,0 +1,124 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
+ * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ * @author Marcel Klehr <mklehr@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+namespace OC\SpeechToText;
+
+use InvalidArgumentException;
+use OC\AppFramework\Bootstrap\Coordinator;
+use OCP\BackgroundJob\IJobList;
+use OCP\Files\File;
+use OCP\Files\InvalidPathException;
+use OCP\Files\NotFoundException;
+use OCP\IServerContainer;
+use OCP\PreConditionNotMetException;
+use OCP\SpeechToText\ISpeechToTextManager;
+use OCP\SpeechToText\ISpeechToTextProvider;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
+use RuntimeException;
+use Throwable;
+
+class SpeechToTextManager implements ISpeechToTextManager {
+ /** @var ?ISpeechToTextProvider[] */
+ private ?array $providers = null;
+
+ public function __construct(
+ private IServerContainer $serverContainer,
+ private Coordinator $coordinator,
+ private LoggerInterface $logger,
+ private IJobList $jobList,
+ ) {
+ }
+
+ public function getProviders(): array {
+ $context = $this->coordinator->getRegistrationContext();
+ if ($context === null) {
+ return [];
+ }
+
+ if ($this->providers !== null) {
+ return $this->providers;
+ }
+
+ $this->providers = [];
+
+ foreach ($context->getSpeechToTextProviders() as $providerServiceRegistration) {
+ $class = $providerServiceRegistration->getService();
+ try {
+ $this->providers[$class] = $this->serverContainer->get($class);
+ } catch (NotFoundExceptionInterface|ContainerExceptionInterface|Throwable $e) {
+ $this->logger->error('Failed to load SpeechToText provider ' . $class, [
+ 'exception' => $e,
+ ]);
+ }
+ }
+
+ return $this->providers;
+ }
+
+ public function hasProviders(): bool {
+ $context = $this->coordinator->getRegistrationContext();
+ if ($context === null) {
+ return false;
+ }
+ return !empty($context->getSpeechToTextProviders());
+ }
+
+ public function scheduleFileTranscription(File $file, ?string $userId, string $appId): void {
+ if (!$this->hasProviders()) {
+ throw new PreConditionNotMetException('No SpeechToText providers have been registered');
+ }
+ try {
+ $this->jobList->add(TranscriptionJob::class, [
+ 'fileId' => $file->getId(),
+ 'owner' => $file->getOwner()->getUID(),
+ 'userId' => $userId,
+ 'appId' => $appId,
+ ]);
+ } catch (NotFoundException|InvalidPathException $e) {
+ throw new InvalidArgumentException('Invalid file provided for file transcription: ' . $e->getMessage());
+ }
+ }
+
+ public function transcribeFile(File $file): string {
+ if (!$this->hasProviders()) {
+ throw new PreConditionNotMetException('No SpeechToText providers have been registered');
+ }
+
+ foreach ($this->getProviders() as $provider) {
+ try {
+ return $provider->transcribeFile($file);
+ } catch (\Throwable $e) {
+ $this->logger->info('SpeechToText transcription using provider ' . $provider->getName() . ' failed', ['exception' => $e]);
+ }
+ }
+
+ throw new RuntimeException('Could not transcribe file');
+ }
+}
diff --git a/lib/private/SpeechToText/TranscriptionJob.php b/lib/private/SpeechToText/TranscriptionJob.php
new file mode 100644
index 00000000000..d5cc9ed7c38
--- /dev/null
+++ b/lib/private/SpeechToText/TranscriptionJob.php
@@ -0,0 +1,104 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
+ *
+ * @author Marcel Klehr <mklehr@gmx.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+namespace OC\SpeechToText;
+
+use OC\User\NoUserException;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\File;
+use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
+use OCP\PreConditionNotMetException;
+use OCP\SpeechToText\Events\TranscriptionFailedEvent;
+use OCP\SpeechToText\Events\TranscriptionSuccessfulEvent;
+use OCP\SpeechToText\ISpeechToTextManager;
+use Psr\Log\LoggerInterface;
+
+class TranscriptionJob extends QueuedJob {
+ public function __construct(
+ ITimeFactory $timeFactory,
+ private ISpeechToTextManager $speechToTextManager,
+ private IEventDispatcher $eventDispatcher,
+ private IRootFolder $rootFolder,
+ private LoggerInterface $logger,
+ ) {
+ parent::__construct($timeFactory);
+ }
+
+
+ /**
+ * @inheritDoc
+ */
+ protected function run($argument) {
+ $fileId = $argument['fileId'];
+ $owner = $argument['owner'];
+ $userId = $argument['userId'];
+ $appId = $argument['appId'];
+ $file = null;
+ try {
+ \OC_Util::setupFS($owner);
+ $userFolder = $this->rootFolder->getUserFolder($owner);
+ $file = current($userFolder->getById($fileId));
+ if (!($file instanceof File)) {
+ $this->logger->warning('Transcription of file ' . $fileId . ' failed. The file could not be found');
+ $this->eventDispatcher->dispatchTyped(
+ new TranscriptionFailedEvent(
+ $fileId,
+ null,
+ 'File not found',
+ $userId,
+ $appId,
+ )
+ );
+ return;
+ }
+ $result = $this->speechToTextManager->transcribeFile($file);
+ $this->eventDispatcher->dispatchTyped(
+ new TranscriptionSuccessfulEvent(
+ $fileId,
+ $file,
+ $result,
+ $userId,
+ $appId,
+ )
+ );
+ } catch (PreConditionNotMetException|\RuntimeException|\InvalidArgumentException|NotFoundException|NotPermittedException|NoUserException $e) {
+ $this->logger->warning('Transcription of file ' . $fileId . ' failed', ['exception' => $e]);
+ $this->eventDispatcher->dispatchTyped(
+ new TranscriptionFailedEvent(
+ $fileId,
+ $file,
+ $e->getMessage(),
+ $userId,
+ $appId,
+ )
+ );
+ }
+ }
+}
diff --git a/lib/private/Tagging/TagMapper.php b/lib/private/Tagging/TagMapper.php
index 808fce2eeae..1ee9c33acf7 100644
--- a/lib/private/Tagging/TagMapper.php
+++ b/lib/private/Tagging/TagMapper.php
@@ -32,6 +32,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
/**
* Mapper for Tag entity
+ *
+ * @template-extends QBMapper<Tag>
*/
class TagMapper extends QBMapper {
/**
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index 075b2ce339b..56285166322 100644
--- a/lib/private/Updater.php
+++ b/lib/private/Updater.php
@@ -331,7 +331,7 @@ class Updater extends BasicEmitter {
*/
protected function doAppUpgrade(): void {
$apps = \OC_App::getEnabledApps();
- $priorityTypes = ['authentication', 'filesystem', 'logging'];
+ $priorityTypes = ['authentication', 'extended_authentication', 'filesystem', 'logging'];
$pseudoOtherType = 'other';
$stacks = [$pseudoOtherType => []];
diff --git a/lib/private/Updater/ChangesResult.php b/lib/private/Updater/Changes.php
index db2f730aa6a..81a57c0c871 100644
--- a/lib/private/Updater/ChangesResult.php
+++ b/lib/private/Updater/Changes.php
@@ -28,7 +28,7 @@ namespace OC\Updater;
use OCP\AppFramework\Db\Entity;
/**
- * Class ChangesResult
+ * Class Changes
*
* @package OC\Updater
* @method string getVersion()=1
@@ -40,7 +40,7 @@ use OCP\AppFramework\Db\Entity;
* @method string getData()
* @method void setData(string $data)
*/
-class ChangesResult extends Entity {
+class Changes extends Entity {
/** @var string */
protected $version = '';
diff --git a/lib/private/Updater/ChangesCheck.php b/lib/private/Updater/ChangesCheck.php
index e2b66853788..2c1eb321ee0 100644
--- a/lib/private/Updater/ChangesCheck.php
+++ b/lib/private/Updater/ChangesCheck.php
@@ -73,7 +73,7 @@ class ChangesCheck {
return json_decode($changesInfo->getData(), true);
}
} catch (DoesNotExistException $e) {
- $changesInfo = new ChangesResult();
+ $changesInfo = new Changes();
}
$response = $this->queryChangesServer($uri, $changesInfo);
@@ -109,7 +109,7 @@ class ChangesCheck {
return self::RESPONSE_NO_CONTENT;
}
- protected function cacheResult(ChangesResult $entry, string $version) {
+ protected function cacheResult(Changes $entry, string $version) {
if ($entry->getVersion() === $version) {
$this->mapper->update($entry);
} else {
@@ -121,7 +121,7 @@ class ChangesCheck {
/**
* @throws \Exception
*/
- protected function queryChangesServer(string $uri, ChangesResult $entry): IResponse {
+ protected function queryChangesServer(string $uri, Changes $entry): IResponse {
$headers = [];
if ($entry->getEtag() !== '') {
$headers['If-None-Match'] = [$entry->getEtag()];
diff --git a/lib/private/Updater/ChangesMapper.php b/lib/private/Updater/ChangesMapper.php
index 03e1ae3c2c1..33d50f5844f 100644
--- a/lib/private/Updater/ChangesMapper.php
+++ b/lib/private/Updater/ChangesMapper.php
@@ -31,6 +31,9 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+/**
+ * @template-extends QBMapper<Changes>
+ */
class ChangesMapper extends QBMapper {
public const TABLE_NAME = 'whats_new';
@@ -41,7 +44,7 @@ class ChangesMapper extends QBMapper {
/**
* @throws DoesNotExistException
*/
- public function getChanges(string $version): ChangesResult {
+ public function getChanges(string $version): Changes {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
@@ -54,6 +57,6 @@ class ChangesMapper extends QBMapper {
if ($data === false) {
throw new DoesNotExistException('Changes info is not present');
}
- return ChangesResult::fromRow($data);
+ return Changes::fromRow($data);
}
}