Skip to content

Commit

Permalink
identifier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
paullla committed Aug 3, 2023
1 parent 0b1f169 commit cd51a44
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
36 changes: 3 additions & 33 deletions src/Bridge/Elasticsearch/ElasticsearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function __construct(private readonly ElasticsearchClient $elasticsearchC
{
}

public function createItem($item, string $index, array $groups = [])
public function createItem($item, string $index, array $groups = []): void
{
$body = $this->normalizer->normalize($item, 'array', $this->getNormalizationContext(['groups' => $groups]));
$body['id'] = $item->getId();

$request = [
'index' => $index,
Expand All @@ -38,7 +37,6 @@ public function bulkCreate(array $items, string $index, array $groups = []): voi
}

$normalizedItem = $this->normalizer->normalize($item, 'array', $this->getNormalizationContext(['groups' => $groups]));
$normalizedItem['id'] = $item->getId();

$params[] = [
'index' => [
Expand All @@ -57,7 +55,7 @@ public function bulkCreate(array $items, string $index, array $groups = []): voi
$this->elasticsearchClient->getClient()->bulk($request);
}

public function getItemById($id, string $index, string $denormalizeToClass)
public function getItemById($id, string $index, string $denormalizeToClass): mixed
{
$documents = $this->elasticsearchClient->getClient()->search([
'index' => $index,
Expand All @@ -74,7 +72,7 @@ public function getItemById($id, string $index, string $denormalizeToClass)
return $this->denormalizer->denormalize($data, $denormalizeToClass);
}

public function getItemByQuery(string $index, string $denormalizeToClass, array $body = [])
public function getItemByQuery(string $index, string $denormalizeToClass, array $body = []): mixed
{
$documents = $this->elasticsearchClient->getClient()->search([
'index' => $index,
Expand Down Expand Up @@ -106,34 +104,6 @@ public function updateItem($id, $item, string $index, array $groups = []): void
$this->elasticsearchClient->getClient()->update($request);
}

public function bulkUpdate(array $items, string $index, array $groups = []): void
{
$params = [];
foreach ($items as $i => $item) {
if (0 === $i % 2) {
echo '.';
}

$normalizedItem = $this->normalizer->normalize($item, 'array', $this->getNormalizationContext(['groups' => $groups]));
$normalizedItem['id'] = $item->getId();

$params[] = [
'update' => [
'_index' => $index,
'_id' => $item->getId(),
],
];
$params[] = ['doc' => $normalizedItem];
}

$request = [
'index' => $index,
'body' => $params,
];

$this->elasticsearchClient->getClient()->bulk($request);
}

public function getCollection(string $index, ?string $denormalizeToClass = null, array $body = [], $limit = 20, $offset = 0): array
{
$documents = $this->elasticsearchClient->getClient()->search([
Expand Down
1 change: 0 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function getConfigTreeBuilder(): TreeBuilder
private function getActivityLogProperties(): array
{
return [
'id' => ['type' => 'keyword'],
'action' => ['type' => 'text'],
'loggedAt' => ['type' => 'date'],
'objectId' => ['type' => 'text'],
Expand Down
4 changes: 4 additions & 0 deletions src/Model/ActivityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function setDataChangesFromArray(?array $dataChanges = null): void

public function getDataChangesArray(): ?array
{
if(null === $this->dataChanges) {
return null;
}

return json_decode($this->dataChanges, true, 512, JSON_THROW_ON_ERROR);
}

Expand Down
1 change: 1 addition & 0 deletions src/Model/CurrentDataTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class CurrentDataTracker implements CurrentDataTrackerInterface
{
#[Groups(["current_data_tracker"])]
protected $id;

#[Groups(["current_data_tracker"])]
Expand Down
35 changes: 28 additions & 7 deletions src/Util/RecursiveClassIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,42 @@

namespace Locastic\Loggastic\Util;

use Symfony\Component\Finder\Finder;

class RecursiveClassIterator
{
public static function getReflectionClasses(array $paths): \Generator
{
$finder = Finder::create();
$finder->files()->name('*.php');
foreach ($paths as $path) {
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
),
'/^.+\.php$/i',
\RecursiveRegexIterator::GET_MATCH
);

foreach ($iterator as $file) {
$sourceFile = $file[0];

if (!preg_match('(^phar:)i', $sourceFile)) {
$sourceFile = realpath($sourceFile);
}

$files = iterator_to_array($finder->in($paths)->getIterator());
try {
require_once $sourceFile;
} catch (\Throwable $t) {
continue;
}

$includedFiles[$sourceFile] = true;
}
}

foreach (get_declared_classes() as $className) {
$declared = array_merge(get_declared_classes(), get_declared_interfaces());
foreach ($declared as $className) {
$reflectionClass = new \ReflectionClass($className);
$sourceFile = $reflectionClass->getFileName();
if (isset($files[$sourceFile])) {
if (isset($includedFiles[$sourceFile])) {
yield $className => $reflectionClass;
}
}
Expand Down

0 comments on commit cd51a44

Please sign in to comment.