Skip to content

Commit 9d9d300

Browse files
committed
store remote share id
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 3f686b6 commit 9d9d300

File tree

5 files changed

+96
-21
lines changed

5 files changed

+96
-21
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Those groups of people can then be used by any other app for sharing purpose.
1313
]]>
1414
</description>
15-
<version>32.0.0-dev.0</version>
15+
<version>32.0.0-dev.1</version>
1616
<licence>agpl</licence>
1717
<author>Maxence Lange</author>
1818
<types>

lib/Db/CoreRequestBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ class CoreRequestBuilder {
118118
'token',
119119
'parent',
120120
'mountpoint',
121-
'mountpoint_hash'
121+
'mountpoint_hash',
122+
'remote',
123+
'remote_id',
122124
],
123125
self::TABLE_MOUNTPOINT => [],
124126
self::TABLE_SHARE_LOCK => [],

lib/Db/MountRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Circles\IFederatedUser;
1616
use OCA\Circles\Model\Mount;
1717
use OCA\Circles\Tools\Traits\TStringTools;
18+
use OCP\DB\QueryBuilder\IQueryBuilder;
1819

1920
/**
2021
* Class MountRequest
@@ -36,7 +37,9 @@ public function save(Mount $mount): void {
3637
->setValue('token', $qb->createNamedParameter($mount->getToken()))
3738
->setValue('parent', $qb->createNamedParameter($mount->getParent()))
3839
->setValue('mountpoint', $qb->createNamedParameter($mount->getOriginalMountPoint()))
39-
->setValue('mountpoint_hash', $qb->createNamedParameter(md5($mount->getOriginalMountPoint())));
40+
->setValue('mountpoint_hash', $qb->createNamedParameter(md5($mount->getOriginalMountPoint())))
41+
->setValue('remote', $qb->createNamedParameter($mount->getRemote()))
42+
->setValue('remote_id', $qb->createNamedParameter($mount->getRemoteShareId(), IQueryBuilder::PARAM_INT));
4043

4144
$qb->execute();
4245
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
8+
* SPDX-License-Identifier: AGPL-3.0-or-later
9+
*/
10+
11+
12+
namespace OCA\Circles\Migration;
13+
14+
use Closure;
15+
use Doctrine\DBAL\Schema\SchemaException;
16+
use OCP\DB\ISchemaWrapper;
17+
use OCP\Migration\Attributes\AddColumn;
18+
use OCP\Migration\Attributes\ColumnType;
19+
use OCP\Migration\IOutput;
20+
use OCP\Migration\SimpleMigrationStep;
21+
use Psr\Log\LoggerInterface;
22+
23+
#[AddColumn('circles_mount', 'remote', ColumnType::STRING, 'store remote instance for quicker identification')]
24+
#[AddColumn('circles_mount', 'remote_id', ColumnType::INTEGER, 'store remote share id for quicker identification')]
25+
class Version0032Date20250623120204 extends SimpleMigrationStep {
26+
public function __construct(
27+
private LoggerInterface $logger,
28+
) {
29+
}
30+
31+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
32+
/** @var ISchemaWrapper $schema */
33+
$schema = $schemaClosure();
34+
35+
try {
36+
$table = $schema->getTable('circles_mount');
37+
if (!$table->hasColumn('remote')) {
38+
$table->addColumn(
39+
'remote', 'string',
40+
[
41+
'length' => 255,
42+
'notnull' => false,
43+
'default' => '',
44+
]
45+
);
46+
}
47+
if (!$table->hasColumn('remote_id')) {
48+
$table->addColumn(
49+
'remote_id', 'integer',
50+
[
51+
'length' => 20,
52+
'unsigned' => true,
53+
'notnull' => true,
54+
'default' => 0,
55+
]
56+
);
57+
}
58+
59+
if (!$table->hasIndex('m_sid_rmt_rid')) {
60+
$table->addIndex(['circle_id', 'remote', 'remote_id'], 'm_sid_rmt_rid');
61+
}
62+
} catch (SchemaException $e) {
63+
$this->logger->warning('Could not find circles_mount', ['exception' => $e]);
64+
return null;
65+
}
66+
67+
return $schema;
68+
}
69+
}

lib/Model/Mount.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Mount extends ManagedModel implements IDeserializable, IQueryRow, JsonSeri
4343
private ICloudIdManager $cloudIdManager;
4444
private IClientService $httpClientService;
4545
private CircleMountManager $mountManager;
46+
private string $remote = '';
47+
private int $remoteShareId = 0;
4648

4749

4850
/**
@@ -323,26 +325,21 @@ public function getMountManager(): CircleMountManager {
323325
return $this->mountManager;
324326
}
325327

328+
public function setRemote(string $remote): void {
329+
$this->remote = $remote;
330+
}
326331

327-
//
328-
// /**
329-
// * @param string $storage
330-
// *
331-
// * @return Mount
332-
// */
333-
// public function setStorage(string $storage): self {
334-
// $this->storage = $storage;
335-
//
336-
// return $this;
337-
// }
338-
//
339-
// /**
340-
// * @return string
341-
// */
342-
// public function getStorage(): string {
343-
// return $this->storage;
344-
// }
332+
public function getRemote(): string {
333+
return $this->remote;
334+
}
345335

336+
public function setRemoteShareId(int $remoteShareId): void {
337+
$this->remoteShareId = $remoteShareId;
338+
}
339+
340+
public function getRemoteShareId(): int {
341+
return $this->remoteShareId;
342+
}
346343

347344
/**
348345
* @return array
@@ -384,6 +381,8 @@ public function fromShare(ShareWrapper $wrappedShare) {
384381
$this->setParent(-1);
385382
$this->setOriginalMountPoint($wrappedShare->getFileTarget());
386383
$this->setOriginalMountPointHash(md5($wrappedShare->getFileTarget()));
384+
$this->setRemote($wrappedShare->getOwner()->getInstance());
385+
$this->setRemoteShareId((int)$wrappedShare->getId());
387386
}
388387

389388

@@ -411,6 +410,8 @@ public function importFromDatabase(array $data, string $prefix = ''): IQueryRow
411410
$this->setOriginalMountPoint($this->get('mountpoint', $data));
412411
$this->setOriginalMountPointHash($this->get('mountpoint_hash', $data));
413412
$this->setMountId($this->get('mount_id', $data));
413+
$this->setRemote($this->get('remote', $data));
414+
$this->setRemoteShareId($this->getInt('remote_id', $data));
414415

415416
$this->getManager()->manageImportFromDatabase($this, $data, $prefix);
416417

0 commit comments

Comments
 (0)