Skip to content

Commit

Permalink
Merge #414
Browse files Browse the repository at this point in the history
414: Changes related to the next Meilisearch release (v0.30.0) r=brunoocasali a=meili-bot

Related to this issue: meilisearch/integration-guides#221

This PR:
- gathers the changes related to the next Meilisearch release (v0.30.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases).
- might eventually contain test failures until the Meilisearch v0.30.0 is out.

⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.30.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._


Co-authored-by: meili-bot <[email protected]>
Co-authored-by: Bruno Casali <[email protected]>
  • Loading branch information
3 people authored Nov 28, 2022
2 parents 29dffba + 029ac51 commit 235b932
Show file tree
Hide file tree
Showing 17 changed files with 494 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ $index->search(

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0).

## 💡 Learn more

Expand Down
12 changes: 12 additions & 0 deletions src/Contracts/CancelTasksQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Contracts;

use MeiliSearch\Delegates\TasksQueryTrait;

class CancelTasksQuery
{
use TasksQueryTrait;
}
12 changes: 12 additions & 0 deletions src/Contracts/DeleteTasksQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Contracts;

use MeiliSearch\Delegates\TasksQueryTrait;

class DeleteTasksQuery
{
use TasksQueryTrait;
}
55 changes: 15 additions & 40 deletions src/Contracts/TasksQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace MeiliSearch\Contracts;

use MeiliSearch\Delegates\TasksQueryTrait;

class TasksQuery
{
use TasksQueryTrait;

private int $from;
private int $limit;
private int $next;
private array $type;
private array $status;
private array $indexUid;

public function setFrom(int $from): TasksQuery
{
Expand All @@ -27,48 +27,23 @@ public function setLimit(int $limit): TasksQuery
return $this;
}

public function setNext(int $next): TasksQuery
{
$this->next = $next;

return $this;
}

public function setTypes(array $types): TasksQuery
{
$this->type = $types;

return $this;
}

public function setStatus(array $status): TasksQuery
{
$this->status = $status;

return $this;
}

public function setUid(array $indexUid): TasksQuery
{
$this->indexUid = $indexUid;

return $this;
}

public function getUid(): array
{
return $this->indexUid ?? [];
}

public function toArray(): array
{
return array_filter([
'from' => $this->from ?? null,
'limit' => $this->limit ?? null,
'next' => $this->next ?? null,
'status' => isset($this->status) ? implode(',', $this->status) : null,
'type' => isset($this->type) ? implode(',', $this->type) : null,
'indexUid' => isset($this->indexUid) ? implode(',', $this->indexUid) : null,
'beforeEnqueuedAt' => $this->formatDate($this->beforeEnqueuedAt ?? null),
'afterEnqueuedAt' => $this->formatDate($this->afterEnqueuedAt ?? null),
'beforeStartedAt' => $this->formatDate($this->beforeStartedAt ?? null),
'afterStartedAt' => $this->formatDate($this->afterStartedAt ?? null),
'beforeFinishedAt' => $this->formatDate($this->beforeFinishedAt ?? null),
'afterFinishedAt' => $this->formatDate($this->afterFinishedAt ?? null),
'statuses' => $this->formatArray($this->statuses ?? null),
'uids' => $this->formatArray($this->uids ?? null),
'canceledBy' => $this->formatArray($this->canceledBy ?? null),
'types' => $this->formatArray($this->types ?? null),
'indexUids' => $this->formatArray($this->indexUids ?? null),
], function ($item) { return null != $item || is_numeric($item); });
}
}
7 changes: 7 additions & 0 deletions src/Delegates/HandlesSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ public function generateTenantToken(string $apiKeyUid, $searchRules, ?array $opt
{
return $this->tenantToken->generateTenantToken($apiKeyUid, $searchRules, $options);
}

public function swapIndexes(array $indexes)
{
$options = array_map(function ($data) { return ['indexes' => $data]; }, $indexes);

return $this->index->swapIndexes($options);
}
}
138 changes: 138 additions & 0 deletions src/Delegates/TasksQueryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Delegates;

trait TasksQueryTrait
{
private int $next;
private array $types;
private array $statuses;
private array $indexUids;
private array $uids;
private array $canceledBy;
private \DateTime $beforeEnqueuedAt;
private \DateTime $afterEnqueuedAt;
private \DateTime $beforeStartedAt;
private \DateTime $afterStartedAt;
private \DateTime $beforeFinishedAt;
private \DateTime $afterFinishedAt;

public function setNext(int $next)
{
$this->next = $next;

return $this;
}

public function setTypes(array $types)
{
$this->types = $types;

return $this;
}

public function setStatuses(array $statuses)
{
$this->statuses = $statuses;

return $this;
}

public function setIndexUids(array $indexUids)
{
$this->indexUids = $indexUids;

return $this;
}

public function getIndexUids(): array
{
return $this->indexUids ?? [];
}

public function setUids(array $uids)
{
$this->uids = $uids;

return $this;
}

public function setCanceledBy(array $canceledBy)
{
$this->canceledBy = $canceledBy;

return $this;
}

public function setBeforeEnqueuedAt(\DateTime $date)
{
$this->beforeEnqueuedAt = $date;

return $this;
}

public function setAfterEnqueuedAt(\DateTime $date)
{
$this->afterEnqueuedAt = $date;

return $this;
}

public function setBeforeStartedAt(\DateTime $date)
{
$this->beforeStartedAt = $date;

return $this;
}

public function setAfterStartedAt(\DateTime $date)
{
$this->afterStartedAt = $date;

return $this;
}

public function setBeforeFinishedAt(\DateTime $date)
{
$this->beforeFinishedAt = $date;

return $this;
}

public function setAfterFinishedAt(\DateTime $date)
{
$this->afterFinishedAt = $date;

return $this;
}

public function toArray(): array
{
return array_filter([
'next' => $this->next ?? null,
'beforeEnqueuedAt' => $this->formatDate($this->beforeEnqueuedAt ?? null),
'afterEnqueuedAt' => $this->formatDate($this->afterEnqueuedAt ?? null),
'beforeStartedAt' => $this->formatDate($this->beforeStartedAt ?? null),
'afterStartedAt' => $this->formatDate($this->afterStartedAt ?? null),
'beforeFinishedAt' => $this->formatDate($this->beforeFinishedAt ?? null),
'afterFinishedAt' => $this->formatDate($this->afterFinishedAt ?? null),
'statuses' => $this->formatArray($this->statuses ?? null),
'uids' => $this->formatArray($this->uids ?? null),
'canceledBy' => $this->formatArray($this->canceledBy ?? null),
'types' => $this->formatArray($this->types ?? null),
'indexUids' => $this->formatArray($this->indexUids ?? null),
], function ($item) { return null != $item || is_numeric($item); });
}

private function formatDate(?\DateTime $date)
{
return isset($date) ? $date->format(\DateTime::RFC3339) : null;
}

private function formatArray(?array $arr)
{
return isset($arr) ? implode(',', $arr) : null;
}
}
12 changes: 12 additions & 0 deletions src/Endpoints/Delegates/HandlesTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace MeiliSearch\Endpoints\Delegates;

use MeiliSearch\Contracts\CancelTasksQuery;
use MeiliSearch\Contracts\DeleteTasksQuery;
use MeiliSearch\Contracts\TasksQuery;
use MeiliSearch\Contracts\TasksResults;

Expand All @@ -23,6 +25,16 @@ public function getTasks(TasksQuery $options = null): TasksResults
return new TasksResults($response);
}

public function deleteTasks(DeleteTasksQuery $options = null): array
{
return $this->tasks->deleteTasks($options);
}

public function cancelTasks(CancelTasksQuery $options = null): array
{
return $this->tasks->cancelTasks($options);
}

public function waitForTask($uid, int $timeoutInMs = 5000, int $intervalInMs = 50): array
{
return $this->tasks->waitTask($uid, $timeoutInMs, $intervalInMs);
Expand Down
14 changes: 11 additions & 3 deletions src/Endpoints/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public function delete(): array
return $this->http->delete(self::PATH.'/'.$this->uid) ?? [];
}

/**
* @param array<array{indexes: mixed}> $indexes
*/
public function swapIndexes(array $indexes): array
{
return $this->http->post('/swap-indexes', $indexes);
}

// Tasks

public function getTask($uid): array
Expand All @@ -164,10 +172,10 @@ public function getTasks(TasksQuery $options = null): TasksResults
{
$options = $options ?? new TasksQuery();

if (0 == \count($options->getUid())) {
$options->setUid(array_merge([$this->uid], $options->getUid()));
if (0 == \count($options->getIndexUids())) {
$options->setIndexUids(array_merge([$this->uid], $options->getIndexUids()));
} else {
$options->setUid([$this->uid]);
$options->setIndexUids([$this->uid]);
}

$response = $this->http->get('/tasks', $options->toArray());
Expand Down
18 changes: 18 additions & 0 deletions src/Endpoints/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace MeiliSearch\Endpoints;

use MeiliSearch\Contracts\CancelTasksQuery;
use MeiliSearch\Contracts\DeleteTasksQuery;
use MeiliSearch\Contracts\Endpoint;
use MeiliSearch\Exceptions\TimeOutException;

Expand All @@ -21,6 +23,22 @@ public function all(array $query = []): array
return $this->http->get(self::PATH.'/', $query);
}

public function cancelTasks(?CancelTasksQuery $options): array
{
$options = $options ?? new CancelTasksQuery();
$response = $this->http->post('/tasks/cancel', null, $options->toArray());

return $response;
}

public function deleteTasks(?DeleteTasksQuery $options): array
{
$options = $options ?? new DeleteTasksQuery();
$response = $this->http->delete(self::PATH, $options->toArray());

return $response;
}

/**
* @throws TimeOutException
*/
Expand Down
Loading

0 comments on commit 235b932

Please sign in to comment.