Skip to content

Commit 1fce582

Browse files
committed
fix: Properly work with non-numeric version ids
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent 7335b9d commit 1fce582

File tree

7 files changed

+91
-16
lines changed

7 files changed

+91
-16
lines changed

lib/Command/ConvertToBigInt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function configure() {
3232

3333
protected function getColumnsByTable() {
3434
return [
35-
'richdocuments_wopi' => ['id', 'fileid', 'version', 'template_id', 'template_destination', 'expiry'],
35+
'richdocuments_wopi' => ['id', 'fileid', 'template_id', 'template_destination', 'expiry'],
3636
'richdocuments_direct' => ['id', 'fileid', 'template_id', 'template_destination', 'timestamp'],
3737
'richdocuments_assets' => ['id', 'fileid', 'timestamp'],
3838
];

lib/Controller/DocumentController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,7 @@ private function getFileForShare(IShare $share, ?int $fileId, ?string $path = nu
495495
throw new NotFoundException();
496496
}
497497

498-
private function getToken(File $file, ?IShare $share = null, ?int $version = null, bool $isGuest = false): Wopi {
499-
// Pass through $version
498+
private function getToken(File $file, ?IShare $share = null, ?string $version = null, bool $isGuest = false): Wopi {
500499
$templateFile = $this->templateManager->getTemplateSource($file->getId());
501500
if ($templateFile) {
502501
$owneruid = $share?->getShareOwner() ?? $file->getOwner()->getUID();
@@ -518,7 +517,7 @@ private function getToken(File $file, ?IShare $share = null, ?int $version = nul
518517
return $this->tokenManager->generateWopiToken($this->getWopiFileId($file->getId(), $version), $share?->getToken(), $this->userId);
519518
}
520519

521-
private function getWopiFileId(int $fileId, ?int $version = null): string {
520+
private function getWopiFileId(int $fileId, ?string $version = null): string {
522521
return $fileId . '_' . $this->config->getSystemValue('instanceid') . ($version ? '_' . $version : '');
523522
}
524523
}

lib/Db/Wopi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* @method string getEditorUid()
1818
* @method void setFileid(int $fileid)
1919
* @method int getFileid()
20-
* @method void setVersion(int $version)
21-
* @method int getVersion()
20+
* @method void setVersion(string $version)
21+
* @method string getVersion()
2222
* @method void setCanwrite(bool $canwrite)
2323
* @method bool getCanwrite()
2424
* @method void setServerHost(string $host)
@@ -82,7 +82,7 @@ class Wopi extends Entity implements \JsonSerializable {
8282
/** @var int */
8383
protected $fileid;
8484

85-
/** @var int */
85+
/** @var string */
8686
protected $version;
8787

8888
/** @var bool */
@@ -128,7 +128,7 @@ public function __construct() {
128128
$this->addType('ownerUid', Types::STRING);
129129
$this->addType('editorUid', Types::STRING);
130130
$this->addType('fileid', Types::INTEGER);
131-
$this->addType('version', Types::INTEGER);
131+
$this->addType('version', Types::STRING);
132132
$this->addType('canwrite', Types::BOOLEAN);
133133
$this->addType('serverHost', Types::STRING);
134134
$this->addType('token', Types::STRING);

lib/Db/WopiMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
* @param int $fileId
3232
* @param string $owner
3333
* @param string $editor
34-
* @param int $version
34+
* @param string $version
3535
* @param bool $updatable
3636
* @param string $serverHost
3737
* @param string $guestDisplayname
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Richdocuments\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
use Override;
17+
18+
/**
19+
* Update version column in richdocuments_wopi table to support alphanumeric versions
20+
*/
21+
class Version10000Date20251217143558 extends SimpleMigrationStep {
22+
23+
/**
24+
* @param IOutput $output
25+
* @param Closure(): ISchemaWrapper $schemaClosure
26+
* @param array $options
27+
*/
28+
#[Override]
29+
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
30+
}
31+
32+
/**
33+
* @param IOutput $output
34+
* @param Closure(): ISchemaWrapper $schemaClosure
35+
* @param array $options
36+
* @return null|ISchemaWrapper
37+
*/
38+
#[Override]
39+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
40+
/** @var ISchemaWrapper $schema */
41+
$schema = $schemaClosure();
42+
43+
if (!$schema->hasTable('richdocuments_wopi')) {
44+
return null;
45+
}
46+
47+
$table = $schema->getTable('richdocuments_wopi');
48+
49+
if (!$table->hasColumn('version')) {
50+
return null;
51+
}
52+
53+
$column = $table->getColumn('version');
54+
55+
if ($column->getType()->getName() === 'string') {
56+
return null;
57+
}
58+
59+
$table->changeColumn('version', [
60+
'type' => 'string',
61+
'notnull' => false,
62+
'length' => 1024,
63+
'default' => '0',
64+
]);
65+
66+
return $schema;
67+
}
68+
69+
/**
70+
* @param IOutput $output
71+
* @param Closure(): ISchemaWrapper $schemaClosure
72+
* @param array $options
73+
*/
74+
#[Override]
75+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
76+
}
77+
}

lib/Migration/Version2060Date20200302131958.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
7474
'notnull' => true,
7575
'length' => 20,
7676
]);
77-
$table->addColumn('version', 'bigint', [
78-
//'notnull' => true,
77+
$table->addColumn('version', 'string', [
7978
'notnull' => false,
80-
'length' => 20,
81-
'default' => 0,
79+
'length' => 1024,
80+
'default' => '0',
8281
]);
8382
$table->addColumn('canwrite', 'boolean', [
8483
//'notnull' => true,

src/view/Office.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export default {
315315
methods: {
316316
async load() {
317317
const fileid = this.fileid ?? basename(dirname(this.source))
318-
const version = this.fileid ? 0 : basename(this.source)
318+
const version = this.fileid ? '0' : basename(this.source)
319319
320320
enableScrollLock()
321321
@@ -339,8 +339,8 @@ export default {
339339
340340
// Generate form and submit to the iframe
341341
const action = getWopiUrl({
342-
fileId: fileid + '_' + loadState('richdocuments', 'instanceId', 'instanceid') + (version > 0 ? '_' + version : ''),
343-
readOnly: forceReadOnly || version > 0,
342+
fileId: fileid + '_' + loadState('richdocuments', 'instanceId', 'instanceid') + (version && version !== '0' ? '_' + version : ''),
343+
readOnly: forceReadOnly || (version && version !== '0'),
344344
revisionHistory: !this.isPublic,
345345
closeButton: !Config.get('hideCloseButton') && !this.isEmbedded,
346346
startPresentation: Config.get('startPresentation'),

0 commit comments

Comments
 (0)