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

[stable30] reset collection endpoint #888

Open
wants to merge 1 commit into
base: stable30
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
return [
'ocs' => [
/** @see OCA\FullTextSearch\Controller\CollectionController */
['name' => 'Collection#resetCollection', 'url' => '/collection/{collection}/index', 'verb' => 'DELETE'],
['name' => 'Collection#getQueue', 'url' => '/collection/{collection}/index', 'verb' => 'GET'],
[
'name' => 'Collection#indexDocument',
Expand Down
23 changes: 22 additions & 1 deletion lib/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,33 @@ public function getQueue(string $collection, int $length = 0): DataResponse {

return new DataResponse($this->collectionService->getQueue($collection, $length));
} catch (\Exception $e) {
// $this->e($e, ['circleId' => $circleId]);
throw new OCSException($e->getMessage(), $e->getCode());
}
}


/**
* @NoAdminRequired
*
* @param string $collection
* @param int $length
*
* @return DataResponse
* @throws OCSException
*/
public function resetCollection(string $collection): DataResponse {
try {
$this->collectionService->confirmCollection($collection);
$this->confirmAccess($collection);

$this->collectionService->resetCollection($collection);

return new DataResponse(['done']);
} catch (\Exception $e) {
throw new OCSException($e->getMessage(), $e->getCode());
}
}

/**
* @NoAdminRequired
*
Expand Down
17 changes: 16 additions & 1 deletion lib/Db/IndexesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ public function updateStatuses(string $collection, string $providerId, array $in
$qb->execute();
}

/**
* @param string $collection
* @param string $providerId
* @param array $indexes
* @param int $status
*/
public function resetCollection(string $collection) {
$collection = ($collection === '') ? $this->configService->getInternalCollection() : $collection;

$qb = $this->getIndexesUpdateSql();
$qb->set('status', $qb->createNamedParameter(IIndex::INDEX_FULL));
$this->limitToCollection($qb, $collection);

$qb->execute();
}

/**
* @param IIndex $index
Expand All @@ -215,7 +230,7 @@ public function deleteIndex(IIndex $index) {


/**
* @param string $collection \
* @param string $collection
*/
public function deleteCollection(string $collection): void {
$qb = $this->getIndexesDeleteSql();
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ function (Index $index): array {
);
}

public function resetCollection(string $collection): void {
$this->indexesRequest->resetCollection($collection);
}

/**
* @param string $collection
Expand Down