Skip to content
Merged
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
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"autoload-dev": {
"psr-4": {
"SpameriTests\\": "tests/SpameriTests"
}
},
"classmap": [
"tests/SpameriTests/Elastic/Migration/migrations"
]
}
}
54 changes: 54 additions & 0 deletions src/Commands/InitializeSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Commands;

class InitializeSettings extends \Symfony\Component\Console\Command\Command
{

/**
* @var \Spameri\Elastic\Settings\IndexConfigInterface[]
*/
private $indexConfig;


public function __construct(
\Spameri\Elastic\Settings\IndexConfigInterface ... $indexConfig
)
{
parent::__construct(NULL);
$this->indexConfig = $indexConfig;
}

public function configure(): void
{
$this
->setName('spameri:elastic:initialize-settings')
->setDescription('Creates index and puts mapping and settings for entity/ies.')
;
}


public function execute(
\Symfony\Component\Console\Input\InputInterface $input,
\Symfony\Component\Console\Output\OutputInterface $output
)
{
$output->writeln();
foreach ($this->indexConfig as $indexConfig) {
$output->writeln();
$this->settinsCreator->create($indexConfig->provide());
$output->writeln();
}


$output->writeln();
// foreach neon configs
$output->writeln();


$output->writeln();
// foreach annotation configs
$output->writeln();
}

}
38 changes: 38 additions & 0 deletions src/Commands/Migrate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Commands;


class Migrate extends \Symfony\Component\Console\Command\Command
{

/**
* @example spameri:elastic:load-dump
*/
protected function configure() : void
{
$this
->setName('spameri:elastic:migrate')
->setDescription('Runs migrations from files.')
->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::OPTIONAL)
;
}


protected function execute(
\Symfony\Component\Console\Input\InputInterface $input
, \Symfony\Component\Console\Output\OutputInterface $output
)
{
$output->writeln('Starting');

// 1. Get folder
// 2. Iterate folder
// 3. Run each file in folder
// 3a. Check if file was executed - skip
// 3b. Check if file was changed - skip and report
// 4. Save executed files to ES
// 5. Done

}
}
27 changes: 24 additions & 3 deletions src/Config/Elastic.neon
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ services:
indicesCreate:
class: Spameri\Elastic\Model\Indices\Create

indicesDelete:
class: Spameri\Elastic\Model\Indices\Delete

serviceLocator:
class: Spameri\Elastic\Model\ServiceLocator

Expand All @@ -75,7 +78,7 @@ services:
class: Spameri\Elastic\ClientProvider

elasticPanelLogger:
class: Spameri\Elastic\Diagnostics\PanelLogger(@elasticSearch.nullLogger)
class: Spameri\Elastic\Diagnostics\PanelLogger(@spameriElasticSearch.nullLogger)

nullLogger:
class: Psr\Log\NullLogger
Expand Down Expand Up @@ -173,10 +176,28 @@ services:
clientBuilder:
class: Elasticsearch\ClientBuilder
setup:
- setLogger(@elasticSearch.elasticPanelLogger)
- setLogger(@spameriElasticSearch.elasticPanelLogger)

dateTimeProvider:
class: Spameri\Elastic\Provider\DateTimeProvider(@elasticSearch.dateTime)
class: Spameri\Elastic\Provider\DateTimeProvider(@spameriElasticSearch.dateTime)

dateTime:
class: \DateTimeImmutable

nullOutput:
class: Symfony\Component\Console\Output\NullOutput

consoleOutput:
class: Symfony\Component\Console\Output\ConsoleOutput

nullLoggerHandler:
class: Spameri\Elastic\Import\Run\NullLoggerHandler

nullLock:
class: Spameri\Elastic\Import\Lock\NullLock

nullHandler:
class: Spameri\Elastic\Import\RunHandler\NullHandler

nullAfterImport:
class: Spameri\Elastic\Import\AfterImport\NullAfterImport
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Spameri\Elastic\DI;


class ElasticSearchExtension extends \Nette\DI\CompilerExtension
class SpameriElasticSearchExtension extends \Nette\DI\CompilerExtension
{

public $defaults = [
Expand Down Expand Up @@ -100,7 +100,7 @@ public function loadConfiguration() : void
$config = \Nette\DI\Config\Helpers::merge($this->getConfig(), $this->defaults);

$config = $this->toggleSynonymAnalyzer($config);
$this->compiler->getContainerBuilder()->parameters['elasticSearch'] = $config;
$this->compiler->getContainerBuilder()->parameters['spameriElasticSearch'] = $config;

$services = $this->loadFromFile(__DIR__ . '/../Config/Elastic.neon');

Expand Down
2 changes: 2 additions & 0 deletions src/Diagnostics/PanelLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ private function logQuery(
) : void
{
if (isset($context['method'], $context['uri'])) {
$path = \explode('9200', $context['uri']);
$context['uri'] = $path[1] ?? $context['uri'];
$this->queries[] = $context;
}
}
Expand Down
59 changes: 59 additions & 0 deletions src/Entity/AbstractImport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Entity;

abstract class AbstractImport implements \Spameri\Elastic\Entity\Import\ValidationObjectInterface
{

/**
* @var int|string
*/
private $key;


public function __construct(
$key
)
{
$this->key = $key;
}


public function key()
{
return $this->key;
}


public function entityVariables(): array
{
$vars = \get_object_vars($this);
unset($vars['key']);
return $vars;
}


public function toArray(): array
{
$array = [];

foreach ($this->entityVariables() as $key => $variable) {
if ($variable instanceof \Spameri\Elastic\Entity\Import\NoValue) {
continue;
}

if ($variable instanceof \Spameri\Elastic\Entity\Import\ValidationPropertyInterface) {
$array[$variable->key()] = $variable->getValue();

} elseif ($variable instanceof \Spameri\Elastic\Entity\Import\ValidationObjectInterface) {
$array[$variable->key()] = $variable->toArray();

} else {
$array[$key] = $variable;
}
}

return $array;
}

}
40 changes: 40 additions & 0 deletions src/Entity/Import/ArrayValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Entity\Import;

class ArrayValue implements ValidationPropertyInterface
{

/**
* @var array
*/
private $array;

/**
* @var string
*/
private $key;


public function __construct(
array $array,
string $key
)
{
$this->array = $array;
$this->key = $key;
}


public function key(): string
{
return $this->key;
}


public function getValue(): array
{
return $this->array;
}

}
41 changes: 41 additions & 0 deletions src/Entity/Import/BoolValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Entity\Import;


class BoolValue implements ValidationPropertyInterface
{

/**
* @var bool
*/
private $value;

/**
* @var string
*/
private $key;


public function __construct(
bool $value,
string $key
)
{
$this->value = $value;
$this->key = $key;
}


public function key(): string
{
return $this->key;
}


public function getValue(): bool
{
return $this->value;
}

}
48 changes: 48 additions & 0 deletions src/Entity/Import/DateValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types = 1);

namespace Spameri\Elastic\Entity\Import;


class DateValue implements ValidationPropertyInterface
{

/**
* @var \DateTime
*/
private $value;

/**
* @var string
*/
private $key;

/**
* @var string
*/
private $format;


public function __construct(
\DateTime $value,
string $key,
string $format = 'Y-m-d H:i:s'
)
{
$this->value = $value;
$this->key = $key;
$this->format = $format;
}


public function key(): string
{
return $this->key;
}


public function getValue(): string
{
return $this->value->format($this->format);
}

}
Loading