Completed
Push — master ( 9b3686...89ef78 )
by Bernhard
07:29
created

ClearMagic360Observer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 50
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 2
A deleteMagic360Gallery() 0 4 1
A deleteMagic360Columns() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Observers\ClearMagic360Observer
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
 * @author    Bernhard Wick <[email protected]>
16
 * @copyright 2017 TechDivision GmbH <[email protected]>
17
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
 * @link      https://github.com/techdivision/import-product-magic360
19
 * @link      http://www.techdivision.com
20
 */
21
22
namespace TechDivision\Import\Product\Magic360\Observers;
23
24
use TechDivision\Import\Product\Magic360\Utils\ColumnKeys;
25
use TechDivision\Import\Product\Magic360\Utils\SqlStatements;
26
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
27
28
/**
29
 * Observer that removes the product with the SKU found in the CSV file.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @author    Bernhard Wick <[email protected]>
33
 * @copyright 2017 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-product-magic360
36
 * @link      http://www.techdivision.com
37
 */
38
class ClearMagic360Observer extends AbstractProductImportObserver
39
{
40
41
    /**
42
     * Process the observer's business logic.
43
     *
44
     * @return array The processed row
45
     */
46
    protected function process()
47
    {
48
49
        // query whether or not, we've found a new SKU => means we've found a new product
50
        if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) {
51
            return;
52
        }
53
54
        // get the mapping to product ID based on the preload entity IDs
55
        $productId = $this->getSubject()->mapSkuToPreloadEntityId($sku);
56
57
        // FIRST delete the data related with the product with the passed SKU
58
        $this->deleteMagic360Gallery(array(ColumnKeys::PRODUCT_ID => $productId), SqlStatements::DELETE_MAGIC360_GALLERY);
59
        $this->deleteMagic360Columns(array(ColumnKeys::PRODUCT_ID => $productId), SqlStatements::DELETE_MAGIC360_COLUMNS);
60
    }
61
62
    /**
63
     * Deletes the gallery entity with the passed attributes.
64
     *
65
     * @param array       $row  The attributes of the entity to delete
66
     * @param string|null $name The name of the prepared statement that has to be executed
67
     *
68
     * @return void
69
     */
70
    public function deleteMagic360Gallery($row, $name = null)
71
    {
72
        $this->getSubject()->deleteMagic360Gallery($row, $name);
73
    }
74
75
    /**
76
     * Deletes the column entity with the passed attributes.
77
     *
78
     * @param array       $row  The attributes of the entity to delete
79
     * @param string|null $name The name of the prepared statement that has to be executed
80
     *
81
     * @return void
82
     */
83
    public function deleteMagic360Columns($row, $name = null)
84
    {
85
        $this->getSubject()->deleteMagic360Columns($row, $name);
86
    }
87
}
88