Completed
Pull Request — master (#7)
by Tim
03:11
created

EeMediaSubject::loadProductMediaGalleryValueToEntityByValueIdAndRowId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Ee\Subjects\EeMediaSubject
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 2016 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-media-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Ee\Subjects;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Product\Media\Subjects\MediaSubject;
25
26
/**
27
 * A subject that handles the process to import product media.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 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-media-ee
33
 * @link      http://www.techdivision.com
34
 */
35
class EeMediaSubject extends MediaSubject
36
{
37
38
    /**
39
     * The mapping for the SKUs to the created entity IDs.
40
     *
41
     * @var array
42
     */
43
    protected $skuRowIdMapping = array();
44
45
    /**
46
     * Intializes the previously loaded global data for exactly one variants.
47
     *
48
     * @param string $serial The serial of the actual import
49
     *
50
     * @return void
51
     * @see \Importer\Csv\Actions\ProductImportAction::prepare()
52
     */
53 1
    public function setUp($serial)
54
    {
55
56
        // invoke the parent method
57 1
        parent::setUp($serial);
58
59
        // load the entity manager and the registry processor
60 1
        $registryProcessor = $this->getRegistryProcessor();
61
62
        // load the status of the actual import process
63 1
        $status = $registryProcessor->getAttribute($serial);
64
65
        // load the attribute set we've prepared intially
66 1
        $this->skuRowIdMapping = $status[RegistryKeys::SKU_ROW_ID_MAPPING];
67 1
    }
68
69
    /**
70
     * Return the row ID for the passed SKU.
71
     *
72
     * @param string $sku The SKU to return the row ID for
73
     *
74
     * @return integer The mapped row ID
75
     * @throws \Exception Is thrown if the SKU is not mapped yet
76
     */
77 1
    public function mapSkuToRowId($sku)
78
    {
79
80
        // query weather or not the SKU has been mapped
81 1
        if (isset($this->skuRowIdMapping[$sku])) {
82 1
            return $this->skuRowIdMapping[$sku];
83
        }
84
85
        // throw an exception if the SKU has not been mapped yet
86
        throw new \Exception(sprintf('Found not mapped SKU %s', $sku));
87
    }
88
}
89