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
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2022-04-21 17:17:41 +0300
committerGitHub <noreply@github.com>2022-04-21 17:17:41 +0300
commit5b0e1f50f0bd2e0200b51abe078f2effe4f58b6d (patch)
treede1fd5d9a3c2dc1b7f567cb24ed5999fd2aac58f /lib
parent53a143fee22402a608d09cbcf9d8a9118e7bcad0 (diff)
parent9674891fdd411cd38a9e5bc7b781356817003e8a (diff)
Merge pull request #7180 from nextcloud/bugfix/7179/fix-migration-of-attachments
Fix migration of attachment types for media
Diffstat (limited to 'lib')
-rw-r--r--lib/Migration/Version14000Date20220330141647.php (renamed from lib/Migration/Version14000Date20220330141646.php)44
1 files changed, 40 insertions, 4 deletions
diff --git a/lib/Migration/Version14000Date20220330141646.php b/lib/Migration/Version14000Date20220330141647.php
index 4277b878d..2ac604f44 100644
--- a/lib/Migration/Version14000Date20220330141646.php
+++ b/lib/Migration/Version14000Date20220330141647.php
@@ -34,7 +34,7 @@ use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
-class Version14000Date20220330141646 extends SimpleMigrationStep {
+class Version14000Date20220330141647 extends SimpleMigrationStep {
protected IDBConnection $connection;
public function __construct(IDBConnection $connection) {
@@ -97,7 +97,9 @@ 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 :(
+ $sql = $this->connection->getDatabasePlatform()
+ ->getTruncateTableSQL('`*PREFIX*talk_attachments`');
+ $this->connection->executeQuery($sql);
$insert = $this->connection->getQueryBuilder();
$insert->insert('talk_attachments')
@@ -129,7 +131,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 +168,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 +183,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 +213,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;
+ }
}