Skip to content

Commit 00562f9

Browse files
authored
Fix/copy swarm file (#145)
* refactor(model): remove unused extra fileid * fix(mapper): change find by file id to find by id - update: mapper find method - update: usages in service and storage - fix: copy function to check for id value * chore: fix code style --------- Co-authored-by: mahiarirani <[email protected]>
1 parent bc4069a commit 00562f9

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

lib/Db/SwarmFile.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
use OCP\AppFramework\Db\Entity;
2727

2828
/**
29-
* @method void setFileId(int $fileId)
30-
* @method int getFileId()
3129
* @method void setName(string $name)
3230
* @method string getName()
3331
* @method void setSwarmReference(string $swarmReference)
@@ -50,9 +48,6 @@
5048
* @method int getToken()
5149
*/
5250
class SwarmFile extends Entity {
53-
/** @var null|int */
54-
protected $fileId;
55-
5651
/** @var string */
5752
protected $name;
5853

@@ -84,7 +79,6 @@ class SwarmFile extends Entity {
8479
protected $token;
8580

8681
public function __construct() {
87-
$this->addType('fileId', 'int');
8882
$this->addType('name', 'string');
8983
$this->addType('swarmReference', 'string');
9084
$this->addType('swarmTag', 'string');

lib/Db/SwarmFileMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public function __construct(IDBConnection $db) {
4444
/**
4545
* @throws Exception
4646
*/
47-
public function findByFileId(string $fileId): ?SwarmFile {
47+
public function findById(string $id): ?SwarmFile {
4848
$qb = $this->db->getQueryBuilder();
4949

5050
$select = $qb
5151
->select('*')
5252
->from($this->getTableName())
53-
->where($qb->expr()->eq('fileId', $qb->createNamedParameter($fileId)))
53+
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
5454
;
5555

5656
return $this->findEntities($select)[0] ?? null;

lib/Service/EthswarmService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function setVisibility(string $fileName, int $storageId, int $visibility)
7474
return $this->fileMapper->update($swarmFile);
7575
}
7676

77-
public function getToken(string $fileId): string {
78-
$swarmFile = $this->fileMapper->findByFileId($fileId);
77+
public function getToken(string $id): string {
78+
$swarmFile = $this->fileMapper->findById($id);
7979
if (!$swarmFile) {
8080
throw new StorageNotAvailableException($this->l10n->t('No token found'));
8181
}

lib/Storage/BeeSwarm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function copy($source, $target): bool {
158158
try {
159159
// Get the source file from the mapper
160160
$sourceFile = $this->fileMapper->find($source, $this->storageId);
161-
if (!$sourceFile->getFileId()) {
161+
if (!$sourceFile->getId()) {
162162
$this->logger->error(
163163
'copy failed: source file not found in mapper '.$source,
164164
['app' => Application::NAME]
@@ -177,11 +177,12 @@ public function copy($source, $target): bool {
177177
$copyData['storage_mtime'] = time();
178178
$copyData['storage'] = $this->storageId;
179179
$copyData['token'] = $this->token;
180+
$copyData['visibility'] = $sourceFile->getVisibility();
180181

181182
// Create the new file entry in the mapper
182183
$newFile = $this->fileMapper->createFile($copyData);
183184

184-
if (!$newFile->getFileId()) {
185+
if (!$newFile->getId()) {
185186
$this->logger->error(
186187
'copy failed: failed to create new file in mapper '.$target,
187188
['app' => Application::NAME]

vendor-bin/sentry/composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)