Completed
Push — 1.9 ( 66be26...482137 )
by
unknown
62:03
created

NewsletterSubscriberInitialWriter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B write() 0 21 5
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\ImportExport\Writer;
4
5
use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport;
6
use OroCRM\Bundle\MagentoBundle\Entity\NewsletterSubscriber;
7
8
class NewsletterSubscriberInitialWriter extends ProxyEntityWriter
9
{
10
    /**
11
     * @param NewsletterSubscriber[] $items
12
     */
13
    public function write(array $items)
14
    {
15
        parent::write($items);
16
17
        $count = count($items);
18
        if (!$count) {
19
            return;
20
        }
21
        // Save minimum originId received by initial sync for further filtering in case of failure
22
        $lastSubscriber = $items[$count - 1];
23
        $transport = $lastSubscriber->getChannel()->getTransport();
24
        if ($transport instanceof MagentoSoapTransport) {
25
            /** @var MagentoSoapTransport $transport */
26
            $transport = $this->databaseHelper->getEntityReference($transport);
27
            $syncedToId = $transport->getNewsletterSubscriberSyncedToId();
28
            if (!$syncedToId || $syncedToId > $lastSubscriber->getOriginId()) {
29
                $transport->setNewsletterSubscriberSyncedToId($lastSubscriber->getOriginId());
30
                $this->writer->write([$transport]);
31
            }
32
        }
33
    }
34
}
35