Skip to content

Commit 4c2dc00

Browse files
committed
Created extractor for the different versions
1 parent c53edf1 commit 4c2dc00

14 files changed

+276
-31
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "php-etl/magento-v2-flow",
33
"autoload": {
44
"psr-4": {
5-
"Kiboko\\Magento\\V2\\Extractor\\": "src/"
5+
"Kiboko\\Magento\\v2_3\\Extractor\\": "src/v2_3"
66
}
77
},
88
"autoload-dev": {
@@ -20,7 +20,7 @@
2020
"php": "^8.1",
2121
"php-etl/pipeline-contracts": "^0.3.3",
2222
"psr/log": "^1.0",
23-
"php-etl/magento-v2-api-client": "0.1.x-dev",
23+
"php-etl/magento-v2-api-client": "^0.1.0",
2424
"nyholm/psr7": "^1.5",
2525
"php-etl/bucket": "^0.2.0",
2626
"php-http/guzzle7-adapter": "^1.0"

composer.lock

Lines changed: 22 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Kiboko\Magento\V2\Extractor;
5+
namespace Kiboko\Magento\v2_1\Extractor;
6+
7+
use Kiboko\Magento\v2_1\Client;
68

79
final class CustomersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
810
{
9-
public function __construct(private \Psr\Log\LoggerInterface $logger, private \Kiboko\Magento\V2\Client $client)
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
1012
{
1113
}
1214

@@ -16,7 +18,7 @@ public function extract(): iterable
1618
$response = $this->client->customerCustomerRepositoryV1GetListGet(queryParameters: [
1719
'searchCriteria[currentPage]' => 1,
1820
'searchCriteria[pageSize]' => 100,
19-
], fetch: \Kiboko\Magento\V2\Client::FETCH_RESPONSE);
21+
], fetch: Client::FETCH_RESPONSE);
2022

2123
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
2224
if ($response->getStatusCode() !== 200) {
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Kiboko\Magento\V2\Extractor;
5+
namespace Kiboko\Magento\v2_1\Extractor;
6+
7+
use Kiboko\Magento\v2_1\Client;
68

79
final class OrdersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
810
{
9-
public function __construct(private \Psr\Log\LoggerInterface $logger, private \Kiboko\Magento\V2\Client $client)
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
1012
{
1113
}
1214

@@ -16,7 +18,7 @@ public function extract(): iterable
1618
$response = $this->client->salesOrderRepositoryV1GetListGet(queryParameters: [
1719
'searchCriteria[currentPage]' => 1,
1820
'searchCriteria[pageSize]' => 100,
19-
], fetch: \Kiboko\Magento\V2\Client::FETCH_RESPONSE);
21+
], fetch: Client::FETCH_RESPONSE);
2022

2123
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
2224
if ($response->getStatusCode() !== 200) {
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Kiboko\Magento\V2\Extractor;
5+
namespace Kiboko\Magento\v2_1\Extractor;
6+
7+
use Kiboko\Magento\v2_1\Client;
68

79
final class ProductsExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
810
{
9-
public function __construct(private \Psr\Log\LoggerInterface $logger, private \Kiboko\Magento\V2\Client $client)
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
1012
{
1113
}
1214

@@ -16,7 +18,7 @@ public function extract(): iterable
1618
$response = $this->client->catalogProductRepositoryV1GetListGet(queryParameters: [
1719
'searchCriteria[currentPage]' => 1,
1820
'searchCriteria[pageSize]' => 100,
19-
], fetch: \Kiboko\Magento\V2\Client::FETCH_RESPONSE);
21+
], fetch: Client::FETCH_RESPONSE);
2022

2123
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
2224
if ($response->getStatusCode() !== 200) {

src/v2_3/CustomersExtractor.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Magento\v2_3\Extractor;
6+
7+
use Kiboko\Magento\v2_3\Client;
8+
9+
final class CustomersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
10+
{
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
12+
{
13+
}
14+
15+
public function extract(): iterable
16+
{
17+
try {
18+
$response = $this->client->customerCustomerRepositoryV1GetListGet(queryParameters: [
19+
'searchCriteria[currentPage]' => 1,
20+
'searchCriteria[pageSize]' => 100,
21+
], fetch: Client::FETCH_RESPONSE);
22+
23+
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
24+
if ($response->getStatusCode() !== 200) {
25+
throw new \RuntimeException($response->getReasonPhrase());
26+
}
27+
28+
$results = json_decode($response->getBody()->getContents(), true)['items'];
29+
30+
foreach ($results as $item) {
31+
(yield new \Kiboko\Component\Bucket\AcceptanceResultBucket($item));
32+
}
33+
}
34+
} catch (\Exception $exception) {
35+
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
36+
}
37+
}
38+
}

src/v2_3/OrdersExtractor.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Magento\v2_3\Extractor;
6+
7+
use Kiboko\Magento\v2_3\Client;
8+
9+
final class OrdersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
10+
{
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
12+
{
13+
}
14+
15+
public function extract(): iterable
16+
{
17+
try {
18+
$response = $this->client->salesOrderRepositoryV1GetListGet(queryParameters: [
19+
'searchCriteria[currentPage]' => 1,
20+
'searchCriteria[pageSize]' => 100,
21+
], fetch: Client::FETCH_RESPONSE);
22+
23+
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
24+
if ($response->getStatusCode() !== 200) {
25+
throw new \RuntimeException($response->getReasonPhrase());
26+
}
27+
28+
$results = json_decode($response->getBody()->getContents(), true)['items'];
29+
30+
foreach ($results as $item) {
31+
(yield new \Kiboko\Component\Bucket\AcceptanceResultBucket($item));
32+
}
33+
}
34+
} catch (\Exception $exception) {
35+
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
36+
}
37+
}
38+
}

src/v2_3/ProductsExtractor.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Magento\v2_3\Extractor;
6+
7+
use Kiboko\Magento\v2_3\Client;
8+
9+
final class ProductsExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
10+
{
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
12+
{
13+
}
14+
15+
public function extract(): iterable
16+
{
17+
try {
18+
$response = $this->client->catalogProductRepositoryV1GetListGet(queryParameters: [
19+
'searchCriteria[currentPage]' => 1,
20+
'searchCriteria[pageSize]' => 100,
21+
], fetch: Client::FETCH_RESPONSE);
22+
23+
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
24+
if ($response->getStatusCode() !== 200) {
25+
throw new \RuntimeException($response->getReasonPhrase());
26+
}
27+
28+
$results = json_decode($response->getBody()->getContents(), true)['items'];
29+
30+
foreach ($results as $item) {
31+
(yield new \Kiboko\Component\Bucket\AcceptanceResultBucket($item));
32+
}
33+
}
34+
} catch (\Exception $exception) {
35+
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
36+
}
37+
}
38+
}

src/v2_4/CustomersExtractor.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Magento\v2_4\Extractor;
6+
7+
use Kiboko\Magento\v2_4\Client;
8+
9+
final class CustomersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
10+
{
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
12+
{
13+
}
14+
15+
public function extract(): iterable
16+
{
17+
try {
18+
$response = $this->client->customerCustomerRepositoryV1GetListGet(queryParameters: [
19+
'searchCriteria[currentPage]' => 1,
20+
'searchCriteria[pageSize]' => 100,
21+
], fetch: Client::FETCH_RESPONSE);
22+
23+
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
24+
if ($response->getStatusCode() !== 200) {
25+
throw new \RuntimeException($response->getReasonPhrase());
26+
}
27+
28+
$results = json_decode($response->getBody()->getContents(), true)['items'];
29+
30+
foreach ($results as $item) {
31+
(yield new \Kiboko\Component\Bucket\AcceptanceResultBucket($item));
32+
}
33+
}
34+
} catch (\Exception $exception) {
35+
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
36+
}
37+
}
38+
}

src/v2_4/OrdersExtractor.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Magento\v2_4\Extractor;
6+
7+
use Kiboko\Magento\v2_4\Client;
8+
9+
final class OrdersExtractor implements \Kiboko\Contract\Pipeline\ExtractorInterface
10+
{
11+
public function __construct(private \Psr\Log\LoggerInterface $logger, private Client $client)
12+
{
13+
}
14+
15+
public function extract(): iterable
16+
{
17+
try {
18+
$response = $this->client->salesOrderRepositoryV1GetListGet(queryParameters: [
19+
'searchCriteria[currentPage]' => 1,
20+
'searchCriteria[pageSize]' => 100,
21+
], fetch: Client::FETCH_RESPONSE);
22+
23+
if ($response instanceof \Psr\Http\Message\ResponseInterface) {
24+
if ($response->getStatusCode() !== 200) {
25+
throw new \RuntimeException($response->getReasonPhrase());
26+
}
27+
28+
$results = json_decode($response->getBody()->getContents(), true)['items'];
29+
30+
foreach ($results as $item) {
31+
(yield new \Kiboko\Component\Bucket\AcceptanceResultBucket($item));
32+
}
33+
}
34+
} catch (\Exception $exception) {
35+
$this->logger->alert($exception->getMessage(), ['exception' => $exception]);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)