Skip to content
Closed
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
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"symfony/css-selector": "7.3.*",
"symfony/console": "7.3.*",
"symfony/phpunit-bridge": "^7.3",
"symfony/test-pack": "1.1.0"
"symfony/test-pack": "1.1.0",
"symfony/uid": "7.3.*"
},
"suggest": {
"symfony/uid": "Provides an object-oriented API to generate and represent UIDs"
},
"prefer-stable": true,
"autoload": {
Expand Down
8 changes: 7 additions & 1 deletion src/DataProvider/CurrentDataTrackerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
use Locastic\Loggastic\Model\Output\CurrentDataTracker;
use Locastic\Loggastic\Model\Output\CurrentDataTrackerInterface;
use Symfony\Component\Uid\Uuid;

final class CurrentDataTrackerProvider implements CurrentDataTrackerProviderInterface
{
Expand All @@ -17,8 +18,13 @@ public function getCurrentDataTrackerByClassAndId(string $className, $objectId):
{
$elasticContext = $this->elasticsearchContextFactory->create($className);

$queryTerm = 'term';
if (class_exists(Uuid::class) && $objectId instanceof Uuid) {
$queryTerm = 'match_phrase';
}

$body = [
'query' => ['term' => ['objectId' => $objectId]],
'query' => [$queryTerm => ['objectId' => $objectId]],
];

//todo move class to config
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/app/Model/DummyBlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class DummyBlogPost
#[Groups(['dummy_blog_post_log'])]
private Collection $photos;

/** @Groups({"dummy_blog_post_log"}) */
private Collection $comments;

public function __construct()
{
$this->photos = new ArrayCollection();
Expand Down Expand Up @@ -104,4 +107,14 @@ public function setPhotos(Collection $photos): void
{
$this->photos = $photos;
}

public function getComments(): Collection
{
return $this->comments;
}

public function setComments(Collection $comments): void
{
$this->comments = $comments;
}
}
35 changes: 35 additions & 0 deletions tests/Fixtures/app/Model/DummyComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Locastic\Loggastic\Tests\Fixtures\App\Model;

use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;

class DummyComment
{
#[Groups(groups: ['dummy_photo_log', 'dummy_blog_post_log'])]
private Uuid $id;

#[Groups(groups: ['dummy_photo_log', 'dummy_blog_post_log'])]
private ?string $content = null;

public function getId(): Uuid
{
return $this->id;
}

public function setId(Uuid $id): void
{
$this->id = $id;
}

public function getContent(): ?string
{
return $this->content;
}

public function setContent(?string $content): void
{
$this->content = $content;
}
}
23 changes: 21 additions & 2 deletions tests/FunctionalTests/ActivityLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use Locastic\Loggastic\Logger\ActivityLoggerInterface;
use Locastic\Loggastic\Model\Output\ActivityLogInterface;
use Locastic\Loggastic\Tests\Fixtures\App\Model\DummyBlogPost;
use Locastic\Loggastic\Tests\Fixtures\App\Model\DummyComment;
use Locastic\Loggastic\Tests\Fixtures\App\Model\DummyPhoto;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Uid\Uuid;

class ActivityLogTest extends KernelTestCase
{
Expand Down Expand Up @@ -112,6 +114,7 @@ public function testLogEdit(): void
$this->blogPost->setTags(['#php', '#locastic', '#elasticSearch']);
$this->blogPost->setEnabled(true);
$this->blogPost->getPhotos()->first()->setPath('https://locastic.com/blog');
$this->blogPost->getComments()->first()->setContent('comment 1 edited');

$this->activityLogger->logUpdatedItem($this->blogPost);

Expand All @@ -132,15 +135,21 @@ public function testLogEdit(): void
'enabled' => false,
'photos' => [
1950 => ['path' => 'https://locastic.com'],
]
],
'comments' => [
'019777b9-346a-7eb9-b289-1a7327b54dc1' => ['content' => 'comment 1'],
],
],
'currentValues' => [
'title' => 'Activity Logs using Elasticsearch',
'tags' => [1 => '#locastic', 2 => '#elasticSearch'],
'enabled' => true,
'photos' => [
1950 => ['path' => 'https://locastic.com/blog'],
]
],
'comments' => [
'019777b9-346a-7eb9-b289-1a7327b54dc1' => ['content' => 'comment 1 edited'],
],
],
], $editedLog->getDataChanges());
}
Expand Down Expand Up @@ -232,6 +241,16 @@ private function createDummyBlogPost(): DummyBlogPost

$blogPost->setPhotos(new ArrayCollection([$photo1, $photo2]));

$comment1 = new DummyComment();
$comment1->setId(Uuid::fromString('019777b9-346a-7eb9-b289-1a7327b54dc1'));
$comment1->setContent('comment 1');

$comment2 = new DummyComment();
$comment2->setId(Uuid::fromString('019777b9-346a-7eb9-b289-1a7327fad6fb'));
$comment2->setContent('comment 2');

$blogPost->setComments(new ArrayCollection([$comment1, $comment2]));

return $blogPost;
}
}