Completed
Push — master ( 8a8ced...010f71 )
by Tim
10s
created

Magic360Subject::loadMagic360Gallery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Subjects\Magic360Subject
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\Subjects;
23
24
use League\Flysystem\Adapter\Local;
25
use League\Flysystem\Filesystem;
26
use TechDivision\Import\Subjects\FileUploadTrait;
27
use TechDivision\Import\Utils\ConfigurationKeys;
28
use TechDivision\Import\Utils\FileUploadConfigurationKeys;
29
use TechDivision\Import\Utils\RegistryKeys;
30
use TechDivision\Import\Product\Utils\RegistryKeys as ProductRegistryKeys;
31
use TechDivision\Import\Product\Subjects\AbstractProductSubject;
32
33
/**
34
 * The main Magic360 subject
35
 *
36
 * @author    Tim Wagner <[email protected]>
37
 * @author    Bernhard Wick <[email protected]>
38
 * @copyright 2017 TechDivision GmbH <[email protected]>
39
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
40
 * @link      https://github.com/techdivision/import-product-magic360
41
 * @link      http://www.techdivision.com
42
 *
43
 * @method \TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface getProductProcessor()
44
 */
45
class Magic360Subject extends AbstractProductSubject
46
{
47
48
    /**
49
     * The trait that provides file upload functionality.
50
     *
51
     * @var \TechDivision\Import\Subjects\FileUploadTrait
52
     */
53
    use FileUploadTrait;
54
55
    /**
56
     * The mapping for the SKUs to the created entity IDs.
57
     *
58
     * @var array $skuEntityIdMapping
59
     */
60
    protected $skuEntityIdMapping = array();
61
62
    /**
63
     * The entity IDs which were initially within the data storage, before other observers influenced them
64
     *
65
     * @var array $preloadEntityIds
66
     */
67
    protected $preloadEntityIds = array();
68
69
    /**
70
     * Initializes the subject data
71
     *
72
     * @param string $serial The serial of the actual import
73
     *
74
     * @return void
75
     * @see \Importer\Csv\Actions\ProductImportAction::prepare()
76
     */
77
    public function setUp($serial)
78
    {
79
80
        // invoke the parent method
81
        parent::setUp($serial);
82
83
        // load the entity manager and the registry processor
84
        $registryProcessor = $this->getRegistryProcessor();
85
86
        // load the status of the actual import process
87
        $status = $registryProcessor->getAttribute($serial);
88
89
        // load the attribute set we've prepared initially
90
        $this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING];
91
        $this->preloadEntityIds = $status[ProductRegistryKeys::PRE_LOADED_ENTITY_IDS];
92
93
        // initialize the flag to decide copy images or not
94
        $this->setCopyImages($this->getConfiguration()->getParam(FileUploadConfigurationKeys::COPY_IMAGES));
0 ignored issues
show
Documentation introduced by
$this->getConfiguration(...ationKeys::COPY_IMAGES) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
96
        // initialize the filesystems root directory
97
        $this->setRootDir($this->getConfiguration()->getParam(ConfigurationKeys::ROOT_DIRECTORY, getcwd()));
98
99
        // initialize the filesystem
100
        $this->setFilesystem(new Filesystem(new Local($this->getRootDir())));
101
102
        // initialize media directory => can be absolute or relative
103
        if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY)) {
104
            $this->setMediaDir(
105
                $this->resolvePath(
106
                    $this->getConfiguration()->getParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY)
107
                )
108
            );
109
        }
110
111
        // initialize images directory => can be absolute or relative
112
        if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY)) {
113
            $this->setImagesFileDir(
114
                $this->resolvePath(
115
                    $this->getConfiguration()->getParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY)
116
                )
117
            );
118
        }
119
    }
120
121
    /**
122
     * Return the entity ID for the passed SKU.
123
     *
124
     * @param string $sku The SKU to return the entity ID for
125
     *
126
     * @return integer The mapped entity ID
127
     * @throws \Exception Is thrown if the SKU is not mapped yet
128
     */
129
    public function mapSkuToEntityId($sku)
130
    {
131
132
        // query weather or not the SKU has been mapped
133
        if (isset($this->skuEntityIdMapping[$sku])) {
134
            return $this->skuEntityIdMapping[$sku];
135
        }
136
137
        // throw an exception if the SKU has not been mapped yet
138
        throw new \Exception(sprintf('Found not mapped SKU %s', $sku));
139
    }
140
141
    /**
142
     * Return the entity ID for the passed SKU based on the preload entity IDs.
143
     *
144
     * @param string $sku The SKU to return the entity ID for
145
     *
146
     * @return integer The mapped entity ID
147
     * @throws \Exception Is thrown if the SKU is not mapped yet
148
     */
149
    public function mapSkuToPreloadEntityId($sku)
150
    {
151
152
        // query weather or not the SKU has been mapped
153
        if (isset($this->preloadEntityIds[$sku])) {
154
            return $this->preloadEntityIds[$sku];
155
        }
156
157
        // throw an exception if the SKU has not been mapped yet
158
        throw new \Exception(sprintf('Found not mapped SKU %s within preload entities', $sku));
159
    }
160
}
161