Skip to content

Commit

Permalink
v0.3.7 maintenance update (#192)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
  • Loading branch information
andrey18106 authored Oct 8, 2023
1 parent f499c6b commit 42c2873
Show file tree
Hide file tree
Showing 22 changed files with 13,903 additions and 12,042 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

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

## [0.3.7 - 2023-10-08]

Maintenance update.
[`cloud_py_api`](https://github.com/cloud-py-api/cloud_py_api) is **required** to be installed
(or updated) and enabled first.

### Added

- Added optional task name (https://github.com/cloud-py-api/mediadc/issues/182)
- Added option to unmark all resolved items (https://github.com/cloud-py-api/mediadc/issues/189)

### Updated

- Updated packages
- Updated l10n

## [0.3.6 - 2023-06-19]

[`cloud_py_api`](https://github.com/cloud-py-api/cloud_py_api) is **required** to be installed
Expand Down
3 changes: 1 addition & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This app allows to find duplicate or similar 📸📹 photos and videos
Quick start guide and further information in our [Wiki](https://github.com/cloud-py-api/mediadc/wiki).
]]>
</description>
<version>0.3.6</version>
<version>0.3.7</version>
<licence>agpl</licence>
<author mail="andrey18106x@gmail.com" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="bigcat88@icloud.com" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand Down Expand Up @@ -72,7 +72,6 @@ Quick start guide and further information in our [Wiki](https://github.com/cloud
<navigation>
<name>MediaDC</name>
<route>mediadc.page.index</route>
<order>1</order>
</navigation>
</navigations>
</info>
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
// COLLECTOR RESOLVED API
['name' => 'collector#resolved', 'url' => '/api/v1/resolved', 'verb' => 'GET'],
['name' => 'collector#markResolved', 'url' => '/api/v1/resolved/mark/{fileId}', 'verb' => 'POST'],
['name' => 'collector#cleanupResolved', 'url' => '/api/v1/resolved/{type}/cleanup', 'verb' => 'POST'],

// BATCH ACTIONS API
['name' => 'collector#removeTaskDetailGroups', 'url' => '/api/v1/tasks/{taskId}/details/remove', 'verb' => 'POST'],
Expand Down
24 changes: 20 additions & 4 deletions lib/Controller/CollectorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,34 @@ public function markResolved(string $type, int $fileId, bool $resolved = true):
return new JSONResponse($this->service->markResolved($type, $fileId, $resolved), Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $type
*
* @return JSONResponse
*/
public function cleanupResolved(string $type): JSONResponse {
return new JSONResponse($this->service->cleanupResolved($type), Http::STATUS_OK);
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $targetDirectoryIds
* @param string $excludeList
* @param string $collectorSettings
* @param string $name
*/
public function runTask($targetDirectoryIds, $excludeList, $collectorSettings): JSONResponse {
public function runTask($targetDirectoryIds, $excludeList, $collectorSettings, $name): JSONResponse {
if ($targetDirectoryIds !== null && $excludeList !== null && $collectorSettings !== null) {
$params = [
'targetDirectoryIds' => json_decode($targetDirectoryIds),
'excludeList' => $excludeList,
'collectorSettings' => $collectorSettings
'collectorSettings' => $collectorSettings,
'name' => $name,
];
return new JSONResponse($this->service->runTask($params), Http::STATUS_OK);
} else {
Expand All @@ -121,8 +135,9 @@ public function runTask($targetDirectoryIds, $excludeList, $collectorSettings):
* @param string $targetDirectoryIds
* @param string $excludeList
* @param string $collectorSettings
* @param string $name
*/
public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collectorSettings): JSONResponse {
public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collectorSettings, $name): JSONResponse {
if (
$taskId !== null && $targetDirectoryIds !== null
&& $excludeList !== null && $collectorSettings !== null
Expand All @@ -131,7 +146,8 @@ public function restartTask($taskId, $targetDirectoryIds, $excludeList, $collect
'taskId' => $taskId,
'targetDirectoryIds' => json_decode($targetDirectoryIds),
'excludeList' => $excludeList,
'collectorSettings' => $collectorSettings
'collectorSettings' => $collectorSettings,
'name' => $name,
];
return new JSONResponse($this->service->restartTask($params), Http::STATUS_OK);
} else {
Expand Down
7 changes: 7 additions & 0 deletions lib/Db/CollectorTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @method int getDeletedFilesSize()
* @method int getPyPid()
* @method array getErrors()
* @method string getName()
* @method void setType(string $type)
* @method void setOwner(string $taskOwner)
* @method void setTargetDirectoryIds(string $targetDirectoryIds)
Expand All @@ -66,6 +67,7 @@
* @method void setUpdatedTime(int $updatedTime)
* @method void setPyPid(int $pyPid)
* @method void setErrors(string $errors)
* @method void setName(string $name)
*/
class CollectorTask extends Entity implements JsonSerializable {
protected $type;
Expand All @@ -83,6 +85,7 @@ class CollectorTask extends Entity implements JsonSerializable {
protected $updatedTime;
protected $pyPid;
protected $errors;
protected $name;


public function __construct(array $params = []) {
Expand Down Expand Up @@ -134,6 +137,9 @@ public function __construct(array $params = []) {
if (isset($params['errors'])) {
$this->setErrors($params['errors']);
}
if (isset($params['name'])) {
$this->setName($params['name']);
}
}

public function jsonSerialize(): array {
Expand All @@ -154,6 +160,7 @@ public function jsonSerialize(): array {
'updated_time' => $this->getUpdatedTime(),
'py_pid' => $this->getPyPid(),
'errors' => $this->getErrors(),
'name' => $this->getName(),
];
}
}
11 changes: 11 additions & 0 deletions lib/Db/PhotoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,15 @@ public function findAllResolvedByUser(string $userId, int $limit = null, int $of
->setFirstResult($offset);
return $qb->executeQuery()->fetchAll();
}

public function cleanupResolved(array $fileIds): int {
$qb = $this->db->getQueryBuilder();
$qb->update($this->tableName)
->set('skipped', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->where(
$qb->expr()->gte('skipped', $qb->createNamedParameter(100, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('fileid', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
);
return $qb->executeStatement();
}
}
11 changes: 11 additions & 0 deletions lib/Db/VideoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ public function findAllResolvedByUser(string $userId, int $limit = null, int $of
->setFirstResult($offset);
return $qb->executeQuery()->fetchAll();
}

public function cleanupResolved(array $fileIds): int {
$qb = $this->db->getQueryBuilder();
$qb->update($this->tableName)
->set('skipped', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->where(
$qb->expr()->gte('skipped', $qb->createNamedParameter(100, IQueryBuilder::PARAM_INT)),
$qb->expr()->in('fileid', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
);
return $qb->executeStatement();
}
}
2 changes: 1 addition & 1 deletion lib/Migration/AppDataInitializationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function run(IOutput $output) {
}
}

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

$output->advance(1, 'Creating app data folders');
Expand Down
56 changes: 56 additions & 0 deletions lib/Migration/Version0003Date20230710162020.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Andrey Borysenko <andrey18106x@gmail.com>
*
* @copyright Copyright (c) 2023 Alexander Piskun <bigcat88@icloud.com>
*
* @author 2023 Andrey Borysenko <andrey18106x@gmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\MediaDC\Migration;

use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;

class Version0003Date20230710162020 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

// Add task name column
$tasksTable = $schema->getTable('mediadc_tasks');
$tasksTable->addColumn('name', 'string', [
'notnull' => false,
'length' => 255,
'default' => '',
]);

return $schema;
}
}
13 changes: 12 additions & 1 deletion lib/Service/CollectorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function restartTask(array $params = []) {
$collectorTask->setDeletedFilesCount(0);
$collectorTask->setDeletedFilesSize(0);
$collectorTask->setErrors('');
$collectorTask->setName($params['name']);
} else {
$empty = true;
}
Expand Down Expand Up @@ -421,7 +422,8 @@ public function createCollectorTask(array $params = [], bool $queued = false): ?
'createdTime' => time(),
'finishedTime' => 0,
'pyPid' => 0,
'errors' => ''
'errors' => '',
'name' => $params['name'] ?? '',
]);

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

public function cleanupResolved(string $type): array {
if ($type === 'photos') {
$result = $this->photosService->cleanupResolved($this->userId);
} elseif ($type === 'videos') {
$result = $this->videosService->cleanupResolved($this->userId);
}
return ['success' => $result > 0];
}

/**
* @param array $targetDirectoryIds
* @param int $targetMtype
Expand Down
7 changes: 7 additions & 0 deletions lib/Service/PhotosService.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@ public function getResolvedPhotos(string $userId = '', int $limit = null, int $o
}
return ['data' => $result];
}

public function cleanupResolved(string $userId): int {
$resolvedFileIdsByUser = array_map(function (array $filecache_data) {
return $filecache_data['fileid'];
}, $this->mapper->findAllResolvedByUser($userId));
return $this->mapper->cleanupResolved($resolvedFileIdsByUser);
}
}
7 changes: 7 additions & 0 deletions lib/Service/VideosService.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,11 @@ public function getResolvedVideos(string $userId = '', int $limit = null, int $o
}
return ['data' => $result];
}

public function cleanupResolved(string $userId): int {
$resolvedFileIdsByUser = array_map(function (array $filecache_data) {
return $filecache_data['fileid'];
}, $this->mapper->findAllResolvedByUser($userId));
return $this->mapper->cleanupResolved($resolvedFileIdsByUser);
}
}
Loading

0 comments on commit 42c2873

Please sign in to comment.