Completed
Push — master ( 4e986c...7c30c4 )
by Tim
19s queued 12s
created

CleanUpObserver::setLastIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Observers\CleanUpObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2018 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Customer\Address\Observers;
22
23
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface;
24
use TechDivision\Import\Customer\Address\Utils\ColumnKeys;
25
26
/**
27
 * An observer implementation that handles the process to import customer address bunches.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2018 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-product
33
 * @link      http://www.techdivision.com
34
 */
35
class CleanUpObserver extends AbstractCustomerAddressImportObserver
36
{
37
38
    /**
39
     * The customer address bunch processor instance.
40
     *
41
     * @var \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface
42
     */
43
    protected $customerAddressBunchProcessor;
44
45
    /**
46
     * Initialize the observer with the passed customer bunch processor instance.
47
     *
48
     * @param \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor The customer address bunch processor instance
49
     */
50
    public function __construct(CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor)
51
    {
52
        $this->customerAddressBunchProcessor = $customerAddressBunchProcessor;
53
    }
54
55
    /**
56
     * Return's the customer address bunch processor instance.
57
     *
58
     * @return \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface The customer address bunch processor instance
59
     */
60
    protected function getCustomerAddressBunchProcessor()
61
    {
62
        return $this->customerAddressBunchProcessor;
63
    }
64
65
    /**
66
     * Process the observer's business logic.
67
     *
68
     * @return array The processed row
69
     */
70
    protected function process()
71
    {
72
73
        // clean-up the repositories etc. to free memory
74
        $this->getCustomerAddressBunchProcessor()->cleanUp();
75
76
        // temporary persist the last customer address entity ID
77
        $this->setLastEntityId($this->getValue(ColumnKeys::ENTITY_ID));
78
    }
79
80
    /**
81
     * Add the passed mail address/website code => entity ID mapping.
82
     *
83
     * @param string $email       The mail address of the customer
84
     * @param string $websiteCode The website code the customer is bound to
85
     *
86
     * @return void
87
     */
88
    protected function addCustomerIdentifierEntityIdMapping($email, $website)
89
    {
90
        $this->getSubject()->addCustomerIdentifierEntityIdMapping($email, $website);
91
    }
92
93
    /**
94
     * Set's the ID of the customer address that has been created recently.
95
     *
96
     * @param string $lastEntityId The entity ID
97
     *
98
     * @return void
99
     */
100
    protected function setLastEntityId($lastEntityId)
101
    {
102
        $this->getSubject()->setLastEntityId($lastEntityId);
103
    }
104
}
105