Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

Commit 073dab8

Browse files
author
Ruben Schmidmeister
committed
Merge branch 'bugfix/archive-post'
2 parents fa5811c + 6b4030b commit 073dab8

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

API/src/Commands/Posts/ArchivePostCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
*/
1010
namespace Timetabio\API\Commands\Posts
1111
{
12-
use Timetabio\API\DataStore\DataStoreWriter;
1312
use Timetabio\API\Services\PostService;
13+
use Timetabio\Framework\Backends\ElasticBackend;
14+
use Timetabio\Framework\ValueObjects\StringDateTime;
1415

1516
class ArchivePostCommand
1617
{
@@ -20,21 +21,23 @@ class ArchivePostCommand
2021
private $postService;
2122

2223
/**
23-
* @var DataStoreWriter
24+
* @var ElasticBackend
2425
*/
25-
private $dataStoreWriter;
26+
private $elasticBackend;
2627

27-
public function __construct(PostService $postService, DataStoreWriter $dataStoreWriter)
28+
public function __construct(PostService $postService, ElasticBackend $elasticBackend)
2829
{
2930
$this->postService = $postService;
30-
$this->dataStoreWriter = $dataStoreWriter;
31+
$this->elasticBackend = $elasticBackend;
3132
}
3233

3334
public function execute(string $postId): string
3435
{
3536
$archived = $this->postService->archivePost($postId);
3637

37-
$this->dataStoreWriter->queueTask(new \Timetabio\Library\Tasks\IndexPostTask($postId));
38+
$this->elasticBackend->updateDocument('post', $postId, [
39+
'archived' => (new StringDateTime($archived))->getTimestamp()
40+
]);
3841

3942
return $archived;
4043
}

API/src/Commands/Posts/RestorePostCommand.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010
namespace Timetabio\API\Commands\Posts
1111
{
12-
use Timetabio\API\DataStore\DataStoreWriter;
1312
use Timetabio\API\Services\PostService;
13+
use Timetabio\Framework\Backends\ElasticBackend;
1414

1515
class RestorePostCommand
1616
{
@@ -20,20 +20,23 @@ class RestorePostCommand
2020
private $postService;
2121

2222
/**
23-
* @var DataStoreWriter
23+
* @var ElasticBackend
2424
*/
25-
private $dataStoreWriter;
25+
private $elasticBackend;
2626

27-
public function __construct(PostService $postService, DataStoreWriter $dataStoreWriter)
27+
public function __construct(PostService $postService, ElasticBackend $elasticBackend)
2828
{
2929
$this->postService = $postService;
30-
$this->dataStoreWriter = $dataStoreWriter;
30+
$this->elasticBackend = $elasticBackend;
3131
}
3232

3333
public function execute(string $postId): void
3434
{
3535
$this->postService->restorePost($postId);
36-
$this->dataStoreWriter->queueTask(new \Timetabio\Library\Tasks\IndexPostTask($postId));
36+
37+
$this->elasticBackend->updateDocument('post', $postId, [
38+
'archived' => null
39+
]);
3740
}
3841
}
3942
}

API/src/Factories/CommandFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ public function createArchivePostCommand(): \Timetabio\API\Commands\Posts\Archiv
214214
{
215215
return new \Timetabio\API\Commands\Posts\ArchivePostCommand(
216216
$this->getMasterFactory()->createPostService(),
217-
$this->getMasterFactory()->createDataStoreWriter()
217+
$this->getMasterFactory()->createElasticBackend()
218218
);
219219
}
220220

221221
public function createRestorePostCommand(): \Timetabio\API\Commands\Posts\RestorePostCommand
222222
{
223223
return new \Timetabio\API\Commands\Posts\RestorePostCommand(
224224
$this->getMasterFactory()->createPostService(),
225-
$this->getMasterFactory()->createDataStoreWriter()
225+
$this->getMasterFactory()->createElasticBackend()
226226
);
227227
}
228228
}

Framework/src/Backends/ElasticBackend.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ public function indexChildDocument(string $type, string $id, string $parent, arr
6161
]);
6262
}
6363

64+
public function updateDocument(string $type, string $id, array $updates): array
65+
{
66+
return $this->client->update([
67+
'index' => $this->index,
68+
'type' => $type,
69+
'id' => $id,
70+
'body' => [
71+
'doc' => $updates
72+
]
73+
]);
74+
}
75+
6476
public function deleteDocument(string $type, string $id): array
6577
{
6678
return $this->client->delete([

0 commit comments

Comments
 (0)