Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Migration/Version14000Date20220330141646.php40
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/Migration/Version14000Date20220330141646.php b/lib/Migration/Version14000Date20220330141646.php
index 4277b878d..2f0e82654 100644
--- a/lib/Migration/Version14000Date20220330141646.php
+++ b/lib/Migration/Version14000Date20220330141646.php
@@ -97,8 +97,6 @@ class Version14000Date20220330141646 extends SimpleMigrationStep {
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
- // FIXME need to loop over all chat messages :(
-
$insert = $this->connection->getQueryBuilder();
$insert->insert('talk_attachments')
->setValue('room_id', $insert->createParameter('room_id'))
@@ -129,7 +127,7 @@ class Version14000Date20220330141646 extends SimpleMigrationStep {
protected function chunkedWriting(IQueryBuilder $insert, IQueryBuilder $select, int $offset): int {
$select->setParameter('offset', $offset);
- $attachments = [];
+ $attachments = $sharesWithoutMimetype = [];
$result = $select->executeQuery();
while ($row = $result->fetch()) {
$attachment = [
@@ -166,11 +164,14 @@ class Version14000Date20220330141646 extends SimpleMigrationStep {
} elseif (str_starts_with($mimetype, 'image/') || str_starts_with($mimetype, 'video/')) {
$attachment['object_type'] = Attachment::TYPE_MEDIA;
} else {
+ if ($mimetype === '' && isset($parameters['share'])) {
+ $sharesWithoutMimetype[(int) $parameters['share']] = (int) $row['id'];
+ }
$attachment['object_type'] = Attachment::TYPE_FILE;
}
}
- $attachments[] = $attachment;
+ $attachments[(int) $row['id']] = $attachment;
}
$result->closeCursor();
@@ -178,6 +179,19 @@ class Version14000Date20220330141646 extends SimpleMigrationStep {
return 0;
}
+ $mimetypes = $this->getMimetypeFromFileCache(array_keys($sharesWithoutMimetype));
+ foreach ($mimetypes as $shareId => $mimetype) {
+ if (!isset($attachments[$sharesWithoutMimetype[$shareId]])) {
+ continue;
+ }
+
+ if (str_starts_with($mimetype, 'audio/')) {
+ $attachments[$sharesWithoutMimetype[$shareId]]['object_type'] = Attachment::TYPE_AUDIO;
+ } elseif (str_starts_with($mimetype, 'image/') || str_starts_with($mimetype, 'video/')) {
+ $attachments[$sharesWithoutMimetype[$shareId]]['object_type'] = Attachment::TYPE_MEDIA;
+ }
+ }
+
$this->connection->beginTransaction();
foreach ($attachments as $attachment) {
$insert
@@ -195,4 +209,22 @@ class Version14000Date20220330141646 extends SimpleMigrationStep {
return end($attachments)['message_id'];
}
+
+ protected function getMimetypeFromFileCache(array $shareIds): array {
+ $mimetype = [];
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('s.id', 'm.mimetype')
+ ->from('share', 's')
+ ->leftJoin('s', 'filecache', 'f', $query->expr()->eq('s.item_source', 'f.fileid'))
+ ->leftJoin('f', 'mimetypes', 'm', $query->expr()->eq('f.mimetype', 'm.id'))
+ ->where($query->expr()->in('s.id', $query->createNamedParameter($shareIds, IQueryBuilder::PARAM_INT_ARRAY)));
+ $result = $query->executeQuery();
+ while ($row = $result->fetch()) {
+ $mimetype[$row['id']] = $row['mimetype'];
+ }
+ $result->closeCursor();
+
+ return $mimetype;
+ }
}