Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] Fixed type error with adding new retention rule #183

Merged
merged 5 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"autoload-dev": {
"psr-4": {
"OCP\\": "vendor/christophwurst/nextcloud/OCP",
"OCA\\Notifications\\": "lib/"
"OCA\\Files_Retention\\": "lib/"
}
},
"name": "nextcloud/files_retention",
Expand All @@ -27,7 +27,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"nextcloud/coding-standard": "^1.0.0",
"christophwurst/nextcloud": "dev-master",
"christophwurst/nextcloud": "dev-stable24",
"vimeo/psalm": "^4.22.0"
}
}
19 changes: 9 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/BackgroundJob/RetentionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function run($argument): void {
// Validate if tag still exists
$tag = $argument['tag'];
try {
$this->tagManager->getTagsByIds($tag);
$this->tagManager->getTagsByIds((string) $tag);
} catch (\InvalidArgumentException $e) {
// tag is invalid remove backgroundjob and exit
$this->jobList->remove($this, $argument);
Expand Down Expand Up @@ -137,7 +137,7 @@ public function run($argument): void {
$offset = '';
$limit = 1000;
while ($offset !== null) {
$fileIds = $this->tagMapper->getObjectIdsForTags($tag, 'files', $limit, $offset);
$fileIds = $this->tagMapper->getObjectIdsForTags((string) $tag, 'files', $limit, $offset);
$this->logger->debug('Checking retention for ' . count($fileIds) . ' files in this chunk');

foreach ($fileIds as $fileId) {
Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function getRetentions(): JSONResponse {
return new JSONResponse($result);
}

public function addRetention(string $tagid, int $timeunit, int $timeamount, int $timeafter = Constants::CTIME): Response {
public function addRetention(int $tagid, int $timeunit, int $timeamount, int $timeafter = Constants::CTIME): Response {
$response = new Response();

try {
$this->tagManager->getTagsByIds($tagid);
$this->tagManager->getTagsByIds((string) $tagid);
} catch (\InvalidArgumentException $e) {
$response->setStatus(Http::STATUS_BAD_REQUEST);
return $response;
Expand All @@ -105,7 +105,7 @@ public function addRetention(string $tagid, int $timeunit, int $timeamount, int
$id = $qb->getLastInsertId();

//Insert cronjob
$this->joblist->add(RetentionJob::class, ['tag' => (int)$tagid]);
$this->joblist->add(RetentionJob::class, ['tag' => $tagid]);

return new JSONResponse([
'id' => $id,
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/Contoller/APIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ public function testAddRetentionInvalidTag() {
->with('42')
->will($this->throwException(new \InvalidArgumentException()));

$response = $this->api->addRetention('42', Constants::WEEK, 1);
$response = $this->api->addRetention(42, Constants::WEEK, 1);

$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
}

public function testAddRetentionInvalidTimeUnit() {
$response = $this->api->addRetention('42', -1, 1);
$response = $this->api->addRetention(42, -1, 1);
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());

$response = $this->api->addRetention('42', 4, 1);
$response = $this->api->addRetention(42, 4, 1);
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
}

Expand All @@ -122,7 +122,7 @@ public function testAddRetention() {

$expected = [
'id' => (int)$data['id'],
'tagid' => '42',
'tagid' => 42,
'timeunit' => Constants::MONTH,
'timeamount' => 1,
'timeafter' => 0,
Expand Down