@@ 11-65 (lines=55) @@ | ||
8 | use Symfony\Component\EventDispatcher\EventDispatcher; |
|
9 | use Akeneo\Bundle\BatchBundle\Event\EventInterface; |
|
10 | ||
11 | class AttributeWriter extends DrupalItemStep implements ItemWriterInterface |
|
12 | { |
|
13 | protected $eventDispatcher; |
|
14 | ||
15 | public function __construct(EventDispatcher $eventDispatcher) |
|
16 | { |
|
17 | $this->eventDispatcher = $eventDispatcher; |
|
18 | } |
|
19 | ||
20 | /** |
|
21 | * @param array $items |
|
22 | */ |
|
23 | public function write(array $items) |
|
24 | { |
|
25 | //file_put_contents('attribute.json', json_encode($items)); |
|
26 | foreach ($items as $item) { |
|
27 | try { |
|
28 | $this->webservice->sendAttribute($item); |
|
29 | } catch (\Exception $e) { |
|
30 | $event = new InvalidItemEvent( |
|
31 | __CLASS__, |
|
32 | $e->getMessage(), |
|
33 | array(), |
|
34 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
35 | ); |
|
36 | // Logging file |
|
37 | $this->eventDispatcher->dispatch( |
|
38 | EventInterface::INVALID_ITEM, |
|
39 | $event |
|
40 | ); |
|
41 | ||
42 | ||
43 | // Loggin Interface |
|
44 | $this->stepExecution->addWarning( |
|
45 | __CLASS__, |
|
46 | $e->getMessage(), |
|
47 | array(), |
|
48 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
49 | ); |
|
50 | ||
51 | /** @var ClientErrorResponseException $e */ |
|
52 | if ($e->getResponse()->getStatusCode() <= 404) { |
|
53 | $e = new \Exception($e->getResponse()->getReasonPhrase()); |
|
54 | $this->stepExecution->addFailureException($e); |
|
55 | $exitStatus = new ExitStatus(ExitStatus::FAILED); |
|
56 | $this->stepExecution->setExitStatus($exitStatus); |
|
57 | } |
|
58 | // Handle next element. |
|
59 | } |
|
60 | $this->stepExecution->incrementWriteCount(); |
|
61 | $this->stepExecution->incrementSummaryInfo('write'); |
|
62 | ||
63 | } |
|
64 | } |
|
65 | } |
|
66 |
@@ 11-63 (lines=53) @@ | ||
8 | use Symfony\Component\EventDispatcher\EventDispatcher; |
|
9 | use Akeneo\Bundle\BatchBundle\Event\EventInterface; |
|
10 | ||
11 | class CategoryWriter extends DrupalItemStep implements ItemWriterInterface |
|
12 | { |
|
13 | ||
14 | protected $eventDispatcher; |
|
15 | ||
16 | public function __construct(EventDispatcher $eventDispatcher) |
|
17 | { |
|
18 | $this->eventDispatcher = $eventDispatcher; |
|
19 | } |
|
20 | ||
21 | public function write(array $items) |
|
22 | { |
|
23 | //file_put_contents('categories.json', json_encode($items)); |
|
24 | foreach ($items[0] as $item) { |
|
25 | try { |
|
26 | $this->webservice->sendCategory($item); |
|
27 | } catch (\Exception $e) { |
|
28 | $event = new InvalidItemEvent( |
|
29 | __CLASS__, |
|
30 | $e->getMessage(), |
|
31 | array(), |
|
32 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
33 | ); |
|
34 | // Logging file |
|
35 | $this->eventDispatcher->dispatch( |
|
36 | EventInterface::INVALID_ITEM, |
|
37 | $event |
|
38 | ); |
|
39 | ||
40 | ||
41 | // Loggin Interface |
|
42 | $this->stepExecution->addWarning( |
|
43 | __CLASS__, |
|
44 | $e->getMessage(), |
|
45 | array(), |
|
46 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
47 | ); |
|
48 | ||
49 | /** @var ClientErrorResponseException $e */ |
|
50 | if ($e->getResponse()->getStatusCode() <= 404) { |
|
51 | $e = new \Exception($e->getResponse()->getReasonPhrase()); |
|
52 | $this->stepExecution->addFailureException($e); |
|
53 | $exitStatus = new ExitStatus(ExitStatus::FAILED); |
|
54 | $this->stepExecution->setExitStatus($exitStatus); |
|
55 | } |
|
56 | // Handle next element. |
|
57 | } |
|
58 | $this->stepExecution->incrementSummaryInfo('write'); |
|
59 | $this->stepExecution->incrementWriteCount(); |
|
60 | ||
61 | } |
|
62 | } |
|
63 | } |
|
64 |
@@ 13-69 (lines=57) @@ | ||
10 | use Guzzle\Http\Exception\ClientErrorResponseException; |
|
11 | ||
12 | ||
13 | class FamilyWriter extends DrupalItemStep implements ItemWriterInterface |
|
14 | { |
|
15 | ||
16 | protected $eventDispatcher; |
|
17 | ||
18 | public function __construct(EventDispatcher $eventDispatcher) |
|
19 | { |
|
20 | $this->eventDispatcher = $eventDispatcher; |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * @param array $items |
|
25 | */ |
|
26 | public function write(array $items) |
|
27 | { |
|
28 | ||
29 | //file_put_contents('families.json', json_encode($items)); |
|
30 | foreach ($items as $item) { |
|
31 | try { |
|
32 | $this->webservice->sendFamily($item); |
|
33 | } catch (\Exception $e) { |
|
34 | $event = new InvalidItemEvent( |
|
35 | __CLASS__, |
|
36 | $e->getMessage(), |
|
37 | array(), |
|
38 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
39 | ); |
|
40 | // Logging file |
|
41 | $this->eventDispatcher->dispatch( |
|
42 | EventInterface::INVALID_ITEM, |
|
43 | $event |
|
44 | ); |
|
45 | ||
46 | ||
47 | // Loggin Interface |
|
48 | $this->stepExecution->addWarning( |
|
49 | __CLASS__, |
|
50 | $e->getMessage(), |
|
51 | array(), |
|
52 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
53 | ); |
|
54 | ||
55 | /** @var ClientErrorResponseException $e */ |
|
56 | if ($e->getResponse()->getStatusCode() <= 404) { |
|
57 | $e = new \Exception($e->getResponse()->getReasonPhrase()); |
|
58 | $this->stepExecution->addFailureException($e); |
|
59 | $exitStatus = new ExitStatus(ExitStatus::FAILED); |
|
60 | $this->stepExecution->setExitStatus($exitStatus); |
|
61 | } |
|
62 | // Handle next element. |
|
63 | } |
|
64 | $this->stepExecution->incrementSummaryInfo('write'); |
|
65 | $this->stepExecution->incrementWriteCount(); |
|
66 | ||
67 | } |
|
68 | } |
|
69 | } |
|
70 |
@@ 12-66 (lines=55) @@ | ||
9 | use Akeneo\Bundle\BatchBundle\Event\EventInterface; |
|
10 | use Guzzle\Http\Exception\ClientErrorResponseException; |
|
11 | ||
12 | class GroupWriter extends DrupalItemStep implements ItemWriterInterface |
|
13 | { |
|
14 | protected $eventDispatcher; |
|
15 | ||
16 | public function __construct(EventDispatcher $eventDispatcher) |
|
17 | { |
|
18 | $this->eventDispatcher = $eventDispatcher; |
|
19 | } |
|
20 | ||
21 | /** |
|
22 | * @param array $items |
|
23 | */ |
|
24 | public function write(array $items) |
|
25 | { |
|
26 | //file_put_contents('group.json', json_encode($items)); |
|
27 | foreach ($items as $item) { |
|
28 | try { |
|
29 | $this->webservice->sendGroup($item); |
|
30 | } catch (\Exception $e) { |
|
31 | $event = new InvalidItemEvent( |
|
32 | __CLASS__, |
|
33 | $e->getMessage(), |
|
34 | array(), |
|
35 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
36 | ); |
|
37 | // Logging file |
|
38 | $this->eventDispatcher->dispatch( |
|
39 | EventInterface::INVALID_ITEM, |
|
40 | $event |
|
41 | ); |
|
42 | ||
43 | ||
44 | // Loggin Interface |
|
45 | $this->stepExecution->addWarning( |
|
46 | __CLASS__, |
|
47 | $e->getMessage(), |
|
48 | array(), |
|
49 | ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL'] |
|
50 | ); |
|
51 | ||
52 | /** @var ClientErrorResponseException $e */ |
|
53 | if ($e->getResponse()->getStatusCode() <= 404) { |
|
54 | $e = new \Exception($e->getResponse()->getReasonPhrase()); |
|
55 | $this->stepExecution->addFailureException($e); |
|
56 | $exitStatus = new ExitStatus(ExitStatus::FAILED); |
|
57 | $this->stepExecution->setExitStatus($exitStatus); |
|
58 | } |
|
59 | // Handle next element. |
|
60 | } |
|
61 | $this->stepExecution->incrementSummaryInfo('write'); |
|
62 | $this->stepExecution->incrementWriteCount(); |
|
63 | ||
64 | } |
|
65 | } |
|
66 | } |
|
67 |
@@ 18-83 (lines=66) @@ | ||
15 | * |
|
16 | * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Writer |
|
17 | */ |
|
18 | class ProductWriter extends DrupalItemStep implements ItemWriterInterface |
|
19 | { |
|
20 | ||
21 | public function __construct(EventDispatcher $eventDispatcher) |
|
22 | { |
|
23 | $this->eventDispatcher = $eventDispatcher; |
|
24 | $this->productandler = $eventDispatcher; |
|
25 | } |
|
26 | ||
27 | /**x |
|
28 | * |
|
29 | * @return array |
|
30 | */ |
|
31 | public function getConfigurationFields() |
|
32 | { |
|
33 | return parent::getConfigurationFields(); |
|
34 | } |
|
35 | ||
36 | /** |
|
37 | * @param array $items |
|
38 | */ |
|
39 | public function write(array $items) |
|
40 | { |
|
41 | foreach ($items as $item) { |
|
42 | try { |
|
43 | //file_put_contents('product.json', json_encode($item)); |
|
44 | $this->webservice->sendProduct($item); |
|
45 | } catch (\Exception $e) { |
|
46 | $event = new InvalidItemEvent( |
|
47 | __CLASS__, |
|
48 | $e->getMessage(), |
|
49 | array(), |
|
50 | ['sku' => array_key_exists('sku', $item) ? $item['sku'] : 'NULL'] |
|
51 | ); |
|
52 | // Logging file |
|
53 | $this->eventDispatcher->dispatch( |
|
54 | EventInterface::INVALID_ITEM, |
|
55 | $event |
|
56 | ); |
|
57 | ||
58 | ||
59 | // Loggin Interface |
|
60 | $this->stepExecution->addWarning( |
|
61 | __CLASS__, |
|
62 | $e->getMessage(), |
|
63 | array(), |
|
64 | ['sku' => array_key_exists('sku', $item) ? $item['sku'] : 'NULL'] |
|
65 | ); |
|
66 | ||
67 | /** @var ClientErrorResponseException $e */ |
|
68 | if ($e->getResponse()->getStatusCode() <= 404) { |
|
69 | $e = new \Exception($e->getResponse()->getReasonPhrase()); |
|
70 | $this->stepExecution->addFailureException($e); |
|
71 | $exitStatus = new ExitStatus(ExitStatus::FAILED); |
|
72 | $this->stepExecution->setExitStatus($exitStatus); |
|
73 | } |
|
74 | // Handle next element. |
|
75 | } |
|
76 | $this->stepExecution->incrementSummaryInfo('write'); |
|
77 | $this->stepExecution->incrementWriteCount(); |
|
78 | ||
79 | } |
|
80 | } |
|
81 | ||
82 | ||
83 | } |
|
84 |