Skip to content

Commit 42c2873

Browse files
authored
v0.3.7 maintenance update (#192)
Signed-off-by: Andrey Borysenko <[email protected]>
1 parent f499c6b commit 42c2873

22 files changed

+13903
-12042
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.3.7 - 2023-10-08]
6+
7+
Maintenance update.
8+
[`cloud_py_api`](https://github.com/cloud-py-api/cloud_py_api) is **required** to be installed
9+
(or updated) and enabled first.
10+
11+
### Added
12+
13+
- Added optional task name (https://github.com/cloud-py-api/mediadc/issues/182)
14+
- Added option to unmark all resolved items (https://github.com/cloud-py-api/mediadc/issues/189)
15+
16+
### Updated
17+
18+
- Updated packages
19+
- Updated l10n
20+
521
## [0.3.6 - 2023-06-19]
622

723
[`cloud_py_api`](https://github.com/cloud-py-api/cloud_py_api) is **required** to be installed

appinfo/info.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This app allows to find duplicate or similar 📸📹 photos and videos
2020
Quick start guide and further information in our [Wiki](https://github.com/cloud-py-api/mediadc/wiki).
2121
]]>
2222
</description>
23-
<version>0.3.6</version>
23+
<version>0.3.7</version>
2424
<licence>agpl</licence>
2525
<author mail="[email protected]" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
2626
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
@@ -72,7 +72,6 @@ Quick start guide and further information in our [Wiki](https://github.com/cloud
7272
<navigation>
7373
<name>MediaDC</name>
7474
<route>mediadc.page.index</route>
75-
<order>1</order>
7675
</navigation>
7776
</navigations>
7877
</info>

appinfo/routes.php

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
// COLLECTOR RESOLVED API
6161
['name' => 'collector#resolved', 'url' => '/api/v1/resolved', 'verb' => 'GET'],
6262
['name' => 'collector#markResolved', 'url' => '/api/v1/resolved/mark/{fileId}', 'verb' => 'POST'],
63+
['name' => 'collector#cleanupResolved', 'url' => '/api/v1/resolved/{type}/cleanup', 'verb' => 'POST'],
6364

6465
// BATCH ACTIONS API
6566
['name' => 'collector#removeTaskDetailGroups', 'url' => '/api/v1/tasks/{taskId}/details/remove', 'verb' => 'POST'],

lib/Controller/CollectorController.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,34 @@ public function markResolved(string $type, int $fileId, bool $resolved = true):
8989
return new JSONResponse($this->service->markResolved($type, $fileId, $resolved), Http::STATUS_OK);
9090
}
9191

92+
/**
93+
* @NoAdminRequired
94+
* @NoCSRFRequired
95+
*
96+
* @param string $type
97+
*
98+
* @return JSONResponse
99+
*/
100+
public function cleanupResolved(string $type): JSONResponse {
101+
return new JSONResponse($this->service->cleanupResolved($type), Http::STATUS_OK);
102+
}
103+
92104
/**
93105
* @NoAdminRequired
94106
* @NoCSRFRequired
95107
*
96108
* @param string $targetDirectoryIds
97109
* @param string $excludeList
98110
* @param string $collectorSettings
111+
* @param string $name
99112
*/
100-
public function runTask($targetDirectoryIds, $excludeList, $collectorSettings): JSONResponse {
113+
public function runTask($targetDirectoryIds, $excludeList, $collectorSettings, $name): JSONResponse {
101114
if ($targetDirectoryIds !== null && $excludeList !== null && $collectorSettings !== null) {
102115
$params = [
103116
'targetDirectoryIds' => json_decode($targetDirectoryIds),
104117
'excludeList' => $excludeList,
105-
'collectorSettings' => $collectorSettings
118+
'collectorSettings' => $collectorSettings,
119+
'name' => $name,
106120
];
107121
return new JSONResponse($this->service->runTask($params), Http::STATUS_OK);
108122
} else {
@@ -121,8 +135,9 @@ public function runTask($targetDirectoryIds, $excludeList, $collectorSettings):
121135
* @param string $targetDirectoryIds
122136
* @param string $excludeList
123137
* @param string $collectorSettings
138+
* @param string $name
124139
*/
125-
public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collectorSettings): JSONResponse {
140+
public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collectorSettings, $name): JSONResponse {
126141
if (
127142
$taskId !== null && $targetDirectoryIds !== null
128143
&& $excludeList !== null && $collectorSettings !== null
@@ -131,7 +146,8 @@ public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collect
131146
'taskId' => $taskId,
132147
'targetDirectoryIds' => json_decode($targetDirectoryIds),
133148
'excludeList' => $excludeList,
134-
'collectorSettings' => $collectorSettings
149+
'collectorSettings' => $collectorSettings,
150+
'name' => $name,
135151
];
136152
return new JSONResponse($this->service->restartTask($params), Http::STATUS_OK);
137153
} else {

lib/Db/CollectorTask.php

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* @method int getDeletedFilesSize()
5252
* @method int getPyPid()
5353
* @method array getErrors()
54+
* @method string getName()
5455
* @method void setType(string $type)
5556
* @method void setOwner(string $taskOwner)
5657
* @method void setTargetDirectoryIds(string $targetDirectoryIds)
@@ -66,6 +67,7 @@
6667
* @method void setUpdatedTime(int $updatedTime)
6768
* @method void setPyPid(int $pyPid)
6869
* @method void setErrors(string $errors)
70+
* @method void setName(string $name)
6971
*/
7072
class CollectorTask extends Entity implements JsonSerializable {
7173
protected $type;
@@ -83,6 +85,7 @@ class CollectorTask extends Entity implements JsonSerializable {
8385
protected $updatedTime;
8486
protected $pyPid;
8587
protected $errors;
88+
protected $name;
8689

8790

8891
public function __construct(array $params = []) {
@@ -134,6 +137,9 @@ public function __construct(array $params = []) {
134137
if (isset($params['errors'])) {
135138
$this->setErrors($params['errors']);
136139
}
140+
if (isset($params['name'])) {
141+
$this->setName($params['name']);
142+
}
137143
}
138144

139145
public function jsonSerialize(): array {
@@ -154,6 +160,7 @@ public function jsonSerialize(): array {
154160
'updated_time' => $this->getUpdatedTime(),
155161
'py_pid' => $this->getPyPid(),
156162
'errors' => $this->getErrors(),
163+
'name' => $this->getName(),
157164
];
158165
}
159166
}

lib/Db/PhotoMapper.php

+11
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,15 @@ public function findAllResolvedByUser(string $userId, int $limit = null, int $of
134134
->setFirstResult($offset);
135135
return $qb->executeQuery()->fetchAll();
136136
}
137+
138+
public function cleanupResolved(array $fileIds): int {
139+
$qb = $this->db->getQueryBuilder();
140+
$qb->update($this->tableName)
141+
->set('skipped', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
142+
->where(
143+
$qb->expr()->gte('skipped', $qb->createNamedParameter(100, IQueryBuilder::PARAM_INT)),
144+
$qb->expr()->in('fileid', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
145+
);
146+
return $qb->executeStatement();
147+
}
137148
}

lib/Db/VideoMapper.php

+11
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,15 @@ public function findAllResolvedByUser(string $userId, int $limit = null, int $of
129129
->setFirstResult($offset);
130130
return $qb->executeQuery()->fetchAll();
131131
}
132+
133+
public function cleanupResolved(array $fileIds): int {
134+
$qb = $this->db->getQueryBuilder();
135+
$qb->update($this->tableName)
136+
->set('skipped', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
137+
->where(
138+
$qb->expr()->gte('skipped', $qb->createNamedParameter(100, IQueryBuilder::PARAM_INT)),
139+
$qb->expr()->in('fileid', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
140+
);
141+
return $qb->executeStatement();
142+
}
132143
}

lib/Migration/AppDataInitializationStep.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function run(IOutput $output) {
9393
}
9494
}
9595

96-
$output->advance(1, 'Checking for inital data changes and syncing with database');
96+
$output->advance(1, 'Checking for initial data changes and syncing with database');
9797
$this->utils->checkForSettingsUpdates($app_data);
9898

9999
$output->advance(1, 'Creating app data folders');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Andrey Borysenko <[email protected]>
7+
*
8+
* @copyright Copyright (c) 2023 Alexander Piskun <[email protected]>
9+
*
10+
* @author 2023 Andrey Borysenko <[email protected]>
11+
*
12+
* @license AGPL-3.0-or-later
13+
*
14+
* This program is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU Affero General Public License as
16+
* published by the Free Software Foundation, either version 3 of the
17+
* License, or (at your option) any later version.
18+
*
19+
* This program is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU Affero General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Affero General Public License
25+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
*/
28+
29+
namespace OCA\MediaDC\Migration;
30+
31+
use OCP\DB\ISchemaWrapper;
32+
use OCP\Migration\SimpleMigrationStep;
33+
use OCP\Migration\IOutput;
34+
35+
class Version0003Date20230710162020 extends SimpleMigrationStep {
36+
/**
37+
* @param IOutput $output
38+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39+
* @param array $options
40+
* @return null|ISchemaWrapper
41+
*/
42+
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
43+
/** @var ISchemaWrapper $schema */
44+
$schema = $schemaClosure();
45+
46+
// Add task name column
47+
$tasksTable = $schema->getTable('mediadc_tasks');
48+
$tasksTable->addColumn('name', 'string', [
49+
'notnull' => false,
50+
'length' => 255,
51+
'default' => '',
52+
]);
53+
54+
return $schema;
55+
}
56+
}

lib/Service/CollectorService.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public function restartTask(array $params = []) {
240240
$collectorTask->setDeletedFilesCount(0);
241241
$collectorTask->setDeletedFilesSize(0);
242242
$collectorTask->setErrors('');
243+
$collectorTask->setName($params['name']);
243244
} else {
244245
$empty = true;
245246
}
@@ -421,7 +422,8 @@ public function createCollectorTask(array $params = [], bool $queued = false): ?
421422
'createdTime' => time(),
422423
'finishedTime' => 0,
423424
'pyPid' => 0,
424-
'errors' => ''
425+
'errors' => '',
426+
'name' => $params['name'] ?? '',
425427
]);
426428

427429
if ($task->getFilesTotal() > 0) {
@@ -1052,6 +1054,15 @@ public function markResolvedVideo(int $fileid, bool $resolved = true): array {
10521054
return ['success' => $result === 1];
10531055
}
10541056

1057+
public function cleanupResolved(string $type): array {
1058+
if ($type === 'photos') {
1059+
$result = $this->photosService->cleanupResolved($this->userId);
1060+
} elseif ($type === 'videos') {
1061+
$result = $this->videosService->cleanupResolved($this->userId);
1062+
}
1063+
return ['success' => $result > 0];
1064+
}
1065+
10551066
/**
10561067
* @param array $targetDirectoryIds
10571068
* @param int $targetMtype

lib/Service/PhotosService.php

+7
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,11 @@ public function getResolvedPhotos(string $userId = '', int $limit = null, int $o
151151
}
152152
return ['data' => $result];
153153
}
154+
155+
public function cleanupResolved(string $userId): int {
156+
$resolvedFileIdsByUser = array_map(function (array $filecache_data) {
157+
return $filecache_data['fileid'];
158+
}, $this->mapper->findAllResolvedByUser($userId));
159+
return $this->mapper->cleanupResolved($resolvedFileIdsByUser);
160+
}
154161
}

lib/Service/VideosService.php

+7
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,11 @@ public function getResolvedVideos(string $userId = '', int $limit = null, int $o
150150
}
151151
return ['data' => $result];
152152
}
153+
154+
public function cleanupResolved(string $userId): int {
155+
$resolvedFileIdsByUser = array_map(function (array $filecache_data) {
156+
return $filecache_data['fileid'];
157+
}, $this->mapper->findAllResolvedByUser($userId));
158+
return $this->mapper->cleanupResolved($resolvedFileIdsByUser);
159+
}
153160
}

0 commit comments

Comments
 (0)