Skip to content

Commit dcfeb50

Browse files
authored
Merge pull request #6 from Spameri/data-to-elastic
Data to Elastic
2 parents b09bfe3 + 6cfa999 commit dcfeb50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1557
-20
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
"autoload-dev": {
5555
"psr-4": {
5656
"SpameriTests\\": "tests/SpameriTests"
57-
}
57+
},
58+
"classmap": [
59+
"tests/SpameriTests/Elastic/Migration/migrations"
60+
]
5861
}
5962
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Commands;
4+
5+
class InitializeSettings extends \Symfony\Component\Console\Command\Command
6+
{
7+
8+
/**
9+
* @var \Spameri\Elastic\Settings\IndexConfigInterface[]
10+
*/
11+
private $indexConfig;
12+
13+
14+
public function __construct(
15+
\Spameri\Elastic\Settings\IndexConfigInterface ... $indexConfig
16+
)
17+
{
18+
parent::__construct(NULL);
19+
$this->indexConfig = $indexConfig;
20+
}
21+
22+
public function configure(): void
23+
{
24+
$this
25+
->setName('spameri:elastic:initialize-settings')
26+
->setDescription('Creates index and puts mapping and settings for entity/ies.')
27+
;
28+
}
29+
30+
31+
public function execute(
32+
\Symfony\Component\Console\Input\InputInterface $input,
33+
\Symfony\Component\Console\Output\OutputInterface $output
34+
)
35+
{
36+
$output->writeln();
37+
foreach ($this->indexConfig as $indexConfig) {
38+
$output->writeln();
39+
$this->settinsCreator->create($indexConfig->provide());
40+
$output->writeln();
41+
}
42+
43+
44+
$output->writeln();
45+
// foreach neon configs
46+
$output->writeln();
47+
48+
49+
$output->writeln();
50+
// foreach annotation configs
51+
$output->writeln();
52+
}
53+
54+
}

src/Commands/Migrate.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Commands;
4+
5+
6+
class Migrate extends \Symfony\Component\Console\Command\Command
7+
{
8+
9+
/**
10+
* @example spameri:elastic:load-dump
11+
*/
12+
protected function configure() : void
13+
{
14+
$this
15+
->setName('spameri:elastic:migrate')
16+
->setDescription('Runs migrations from files.')
17+
->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::OPTIONAL)
18+
;
19+
}
20+
21+
22+
protected function execute(
23+
\Symfony\Component\Console\Input\InputInterface $input
24+
, \Symfony\Component\Console\Output\OutputInterface $output
25+
)
26+
{
27+
$output->writeln('Starting');
28+
29+
// 1. Get folder
30+
// 2. Iterate folder
31+
// 3. Run each file in folder
32+
// 3a. Check if file was executed - skip
33+
// 3b. Check if file was changed - skip and report
34+
// 4. Save executed files to ES
35+
// 5. Done
36+
37+
}
38+
}

src/Config/Elastic.neon

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ services:
5959
indicesCreate:
6060
class: Spameri\Elastic\Model\Indices\Create
6161

62+
indicesDelete:
63+
class: Spameri\Elastic\Model\Indices\Delete
64+
6265
serviceLocator:
6366
class: Spameri\Elastic\Model\ServiceLocator
6467

@@ -75,7 +78,7 @@ services:
7578
class: Spameri\Elastic\ClientProvider
7679

7780
elasticPanelLogger:
78-
class: Spameri\Elastic\Diagnostics\PanelLogger(@elasticSearch.nullLogger)
81+
class: Spameri\Elastic\Diagnostics\PanelLogger(@spameriElasticSearch.nullLogger)
7982

8083
nullLogger:
8184
class: Psr\Log\NullLogger
@@ -173,10 +176,28 @@ services:
173176
clientBuilder:
174177
class: Elasticsearch\ClientBuilder
175178
setup:
176-
- setLogger(@elasticSearch.elasticPanelLogger)
179+
- setLogger(@spameriElasticSearch.elasticPanelLogger)
177180

178181
dateTimeProvider:
179-
class: Spameri\Elastic\Provider\DateTimeProvider(@elasticSearch.dateTime)
182+
class: Spameri\Elastic\Provider\DateTimeProvider(@spameriElasticSearch.dateTime)
180183

181184
dateTime:
182185
class: \DateTimeImmutable
186+
187+
nullOutput:
188+
class: Symfony\Component\Console\Output\NullOutput
189+
190+
consoleOutput:
191+
class: Symfony\Component\Console\Output\ConsoleOutput
192+
193+
nullLoggerHandler:
194+
class: Spameri\Elastic\Import\Run\NullLoggerHandler
195+
196+
nullLock:
197+
class: Spameri\Elastic\Import\Lock\NullLock
198+
199+
nullHandler:
200+
class: Spameri\Elastic\Import\RunHandler\NullHandler
201+
202+
nullAfterImport:
203+
class: Spameri\Elastic\Import\AfterImport\NullAfterImport
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Spameri\Elastic\DI;
44

55

6-
class ElasticSearchExtension extends \Nette\DI\CompilerExtension
6+
class SpameriElasticSearchExtension extends \Nette\DI\CompilerExtension
77
{
88

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

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

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

src/Diagnostics/PanelLogger.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ private function logQuery(
148148
) : void
149149
{
150150
if (isset($context['method'], $context['uri'])) {
151+
$path = \explode('9200', $context['uri']);
152+
$context['uri'] = $path[1] ?? $context['uri'];
151153
$this->queries[] = $context;
152154
}
153155
}

src/Entity/AbstractImport.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Entity;
4+
5+
abstract class AbstractImport implements \Spameri\Elastic\Entity\Import\ValidationObjectInterface
6+
{
7+
8+
/**
9+
* @var int|string
10+
*/
11+
private $key;
12+
13+
14+
public function __construct(
15+
$key
16+
)
17+
{
18+
$this->key = $key;
19+
}
20+
21+
22+
public function key()
23+
{
24+
return $this->key;
25+
}
26+
27+
28+
public function entityVariables(): array
29+
{
30+
$vars = \get_object_vars($this);
31+
unset($vars['key']);
32+
return $vars;
33+
}
34+
35+
36+
public function toArray(): array
37+
{
38+
$array = [];
39+
40+
foreach ($this->entityVariables() as $key => $variable) {
41+
if ($variable instanceof \Spameri\Elastic\Entity\Import\NoValue) {
42+
continue;
43+
}
44+
45+
if ($variable instanceof \Spameri\Elastic\Entity\Import\ValidationPropertyInterface) {
46+
$array[$variable->key()] = $variable->getValue();
47+
48+
} elseif ($variable instanceof \Spameri\Elastic\Entity\Import\ValidationObjectInterface) {
49+
$array[$variable->key()] = $variable->toArray();
50+
51+
} else {
52+
$array[$key] = $variable;
53+
}
54+
}
55+
56+
return $array;
57+
}
58+
59+
}

src/Entity/Import/ArrayValue.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Entity\Import;
4+
5+
class ArrayValue implements ValidationPropertyInterface
6+
{
7+
8+
/**
9+
* @var array
10+
*/
11+
private $array;
12+
13+
/**
14+
* @var string
15+
*/
16+
private $key;
17+
18+
19+
public function __construct(
20+
array $array,
21+
string $key
22+
)
23+
{
24+
$this->array = $array;
25+
$this->key = $key;
26+
}
27+
28+
29+
public function key(): string
30+
{
31+
return $this->key;
32+
}
33+
34+
35+
public function getValue(): array
36+
{
37+
return $this->array;
38+
}
39+
40+
}

src/Entity/Import/BoolValue.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Entity\Import;
4+
5+
6+
class BoolValue implements ValidationPropertyInterface
7+
{
8+
9+
/**
10+
* @var bool
11+
*/
12+
private $value;
13+
14+
/**
15+
* @var string
16+
*/
17+
private $key;
18+
19+
20+
public function __construct(
21+
bool $value,
22+
string $key
23+
)
24+
{
25+
$this->value = $value;
26+
$this->key = $key;
27+
}
28+
29+
30+
public function key(): string
31+
{
32+
return $this->key;
33+
}
34+
35+
36+
public function getValue(): bool
37+
{
38+
return $this->value;
39+
}
40+
41+
}

src/Entity/Import/DateValue.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Entity\Import;
4+
5+
6+
class DateValue implements ValidationPropertyInterface
7+
{
8+
9+
/**
10+
* @var \DateTime
11+
*/
12+
private $value;
13+
14+
/**
15+
* @var string
16+
*/
17+
private $key;
18+
19+
/**
20+
* @var string
21+
*/
22+
private $format;
23+
24+
25+
public function __construct(
26+
\DateTime $value,
27+
string $key,
28+
string $format = 'Y-m-d H:i:s'
29+
)
30+
{
31+
$this->value = $value;
32+
$this->key = $key;
33+
$this->format = $format;
34+
}
35+
36+
37+
public function key(): string
38+
{
39+
return $this->key;
40+
}
41+
42+
43+
public function getValue(): string
44+
{
45+
return $this->value->format($this->format);
46+
}
47+
48+
}

0 commit comments

Comments
 (0)