ProductMagic360Processor::beginTransaction()   A
last analyzed

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 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Magic360\Services\ProductMagic360Processor
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\Services;
23
24
use TechDivision\Import\Connection\ConnectionInterface;
25
use TechDivision\Import\Product\Magic360\Actions\Magic360GalleryActionInterface;
26
use TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsActionInterface;
27
use TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepositoryInterface;
28
use TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepositoryInterface;
29
30
/**
31
 * The product magic 360 processor implementation.
32
 *
33
 * @author    Tim Wagner <[email protected]>
34
 * @author    Bernhard Wick <[email protected]>
35
 * @copyright 2017 TechDivision GmbH <[email protected]>
36
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
37
 * @link      https://github.com/techdivision/import-product-magic360
38
 * @link      http://www.techdivision.com
39
 */
40
class ProductMagic360Processor implements ProductMagic360ProcessorInterface
41
{
42
43
    /**
44
     * A PDO connection initialized with the values from the Doctrine EntityManager.
45
     *
46
     * @var \TechDivision\Import\Connection\ConnectionInterface
47
     */
48
    protected $connection;
49
50
    /**
51
     * The repository to load magic360 galleries.
52
     *
53
     * @var \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepositoryInterface
54
     */
55
    protected $productMagic360GalleryRepository;
56
57
    /**
58
     * The repository to load magic360 gallery to entities.
59
     *
60
     * @var \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepositoryInterface
61
     */
62
    protected $productMagic360ColumnsRepository;
63
64
    /**
65
     * The action with the magic360 gallery CRUD methods.
66
     *
67
     * @var \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryActionInterface
68
     */
69
    protected $magic360GalleryAction;
70
71
    /**
72
     * The action with the magic360 gallery value CRUD methods.
73
     *
74
     * @var \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsActionInterface
75
     */
76
    protected $magic360ColumnsAction;
77
78
    /**
79
     * Initialize the processor with the necessary assembler and repository instances.
80
     *
81
     * @param \TechDivision\Import\Connection\ConnectionInterface                                          $connection                       The connection to use
82
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepositoryInterface $productMagic360GalleryRepository The product magic 360 gallery repository to use
83
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepositoryInterface $productMagic360ColumnsRepository The product magic 360 columns repository to use
84
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryActionInterface                 $magic360GalleryAction            The product magic 360 gallery action to use
85
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsActionInterface                 $magic360ColumnsAction            The product magic 360 columns action to use
86
     */
87
    public function __construct(
88
        ConnectionInterface $connection,
89
        ProductMagic360GalleryRepositoryInterface $productMagic360GalleryRepository,
90
        ProductMagic360ColumnsRepositoryInterface $productMagic360ColumnsRepository,
91
        Magic360GalleryActionInterface $magic360GalleryAction,
92
        Magic360ColumnsActionInterface $magic360ColumnsAction
93
    ) {
94
        $this->setConnection($connection);
95
        $this->setProductMagic360GalleryRepository($productMagic360GalleryRepository);
96
        $this->setProductMagic360ColumnsRepository($productMagic360ColumnsRepository);
97
        $this->setMagic360GalleryAction($magic360GalleryAction);
98
        $this->setMagic360ColumnsAction($magic360ColumnsAction);
99
    }
100
101
    /**
102
     * Set's the passed connection.
103
     *
104
     * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set
105
     *
106
     * @return void
107
     */
108
    public function setConnection(ConnectionInterface $connection)
109
    {
110
        $this->connection = $connection;
111
    }
112
113
    /**
114
     * Return's the connection.
115
     *
116
     * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance
117
     */
118
    public function getConnection()
119
    {
120
        return $this->connection;
121
    }
122
123
    /**
124
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
125
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
126
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
127
     * to autocommit mode.
128
     *
129
     * @return boolean Returns TRUE on success or FALSE on failure
130
     * @link http://php.net/manual/en/pdo.begintransaction.php
131
     */
132
    public function beginTransaction()
133
    {
134
        return $this->connection->beginTransaction();
135
    }
136
137
    /**
138
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
139
     * ProductProcessor::beginTransaction() starts a new transaction.
140
     *
141
     * @return boolean Returns TRUE on success or FALSE on failure
142
     * @link http://php.net/manual/en/pdo.commit.php
143
     */
144
    public function commit()
145
    {
146
        return $this->connection->commit();
147
    }
148
149
    /**
150
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
151
     *
152
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
153
     * rolled back the transaction.
154
     *
155
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
156
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
157
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
158
     *
159
     * @return boolean Returns TRUE on success or FALSE on failure
160
     * @link http://php.net/manual/en/pdo.rollback.php
161
     */
162
    public function rollBack()
163
    {
164
        return $this->connection->rollBack();
165
    }
166
167
    /**
168
     * Sets the repository to load magic360 gallery data.
169
     *
170
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepositoryInterface $productMagic360GalleryRepository The repository instance
171
     *
172
     * @return void
173
     */
174
    public function setProductMagic360GalleryRepository(ProductMagic360GalleryRepositoryInterface $productMagic360GalleryRepository)
175
    {
176
        $this->productMagic360GalleryRepository = $productMagic360GalleryRepository;
177
    }
178
179
    /**
180
     * Returns the repository to load magic360 gallery data.
181
     *
182
     * @return \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360GalleryRepositoryInterface The repository instance
183
     */
184
    public function getProductMagic360GalleryRepository()
185
    {
186
        return $this->productMagic360GalleryRepository;
187
    }
188
189
    /**
190
     * Sets the repository to load magic360 column data.
191
     *
192
     * @param \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepositoryInterface $productMagic360ColumnsRepository The repository instance
193
     *
194
     * @return void
195
     */
196
    public function setProductMagic360ColumnsRepository(ProductMagic360ColumnsRepositoryInterface $productMagic360ColumnsRepository)
197
    {
198
        $this->productMagic360ColumnsRepository = $productMagic360ColumnsRepository;
199
    }
200
201
    /**
202
     * Returns the repository to load magic360 column data.
203
     *
204
     * @return \TechDivision\Import\Product\Magic360\Repositories\ProductMagic360ColumnsRepositoryInterface The repository instance
205
     */
206
    public function getProductMagic360ColumnsRepository()
207
    {
208
        return $this->productMagic360ColumnsRepository;
209
    }
210
211
    /**
212
     * Sets the action with the magic360 gallery CRUD methods.
213
     *
214
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryActionInterface $magic360GalleryAction The action with the magic360 gallery CRUD methods
215
     *
216
     * @return void
217
     */
218
    public function setMagic360GalleryAction(Magic360GalleryActionInterface $magic360GalleryAction)
219
    {
220
        $this->magic360GalleryAction = $magic360GalleryAction;
221
    }
222
223
    /**
224
     * Returns the action with the magic360 gallery CRUD methods.
225
     *
226
     * @return \TechDivision\Import\Product\Magic360\Actions\Magic360GalleryActionInterface $magic360GalleryAction The action with the magic360 gallery CRUD methods
227
     */
228
    public function getMagic360GalleryAction()
229
    {
230
        return $this->magic360GalleryAction;
231
    }
232
233
    /**
234
     * Sets the action with the magic360 column CRUD methods.
235
     *
236
     * @param \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsActionInterface $magic360ColumnsAction The action with the magic360 column CRUD methods
237
     *
238
     * @return void
239
     */
240
    public function setMagic360ColumnsAction(Magic360ColumnsActionInterface $magic360ColumnsAction)
241
    {
242
        $this->magic360ColumnsAction = $magic360ColumnsAction;
243
    }
244
245
    /**
246
     * Returns the action with the magic360 column CRUD methods.
247
     *
248
     * @return \TechDivision\Import\Product\Magic360\Actions\Magic360ColumnsActionInterface The action with the magic360 column CRUD methods
249
     */
250
    public function getMagic360ColumnsAction()
251
    {
252
        return $this->magic360ColumnsAction;
253
    }
254
255
    /**
256
     * Persists the passed magic360 gallery data and returns the ID.
257
     *
258
     * @param array       $galleryEntry The magic360 gallery data to persist
259
     * @param string|null $name         The name of the prepared statement that has to be executed
260
     *
261
     * @return string The ID of the persisted entity
262
     */
263
    public function persistMagic360Gallery($galleryEntry, $name = null)
264
    {
265
        return $this->getMagic360GalleryAction()->persist($galleryEntry, $name);
0 ignored issues
show
Unused Code introduced by
The call to Magic360GalleryActionInterface::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
266
    }
267
268
    /**
269
     * Persists the passed magic360 column data.
270
     *
271
     * @param array       $magic360Columns The magic360 gallery value data to persist
272
     * @param string|null $name            The name of the prepared statement that has to be executed
273
     *
274
     * @return void
275
     */
276
    public function persistMagic360Columns($magic360Columns, $name = null)
277
    {
278
        $this->getMagic360ColumnsAction()->persist($magic360Columns, $name);
0 ignored issues
show
Unused Code introduced by
The call to Magic360ColumnsActionInterface::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
279
    }
280
281
    /**
282
     * Persists the passed magic360 gallery data and returns the ID.
283
     *
284
     * @param array       $row  The magic360 gallery data to persist
285
     * @param string|null $name The name of the prepared statement that has to be executed
286
     *
287
     * @return void
288
     */
289
    public function deleteMagic360Gallery($row, $name = null)
290
    {
291
        $this->getMagic360GalleryAction()->delete($row, $name);
292
    }
293
294
    /**
295
     * Persists the passed magic360 column data.
296
     *
297
     * @param array       $row  The magic360 column data to persist
298
     * @param string|null $name The name of the prepared statement that has to be executed
299
     *
300
     * @return void
301
     */
302
    public function deleteMagic360Columns($row, $name = null)
303
    {
304
        $this->getMagic360ColumnsAction()->delete($row, $name);
305
    }
306
307
    /**
308
     * Loads the magic360 gallery with the passed product ID and position
309
     *
310
     * @param integer $productId The product ID of the magic360 gallery to load
311
     * @param string  $position  The position of the magic360 gallery entry to load
312
     *
313
     * @return array The magic360 gallery
314
     */
315
    public function loadMagic360Gallery($productId, $position)
316
    {
317
        return $this->getProductMagic360GalleryRepository()->findOneByProductIdAndPosition($productId, $position);
318
    }
319
320
    /**
321
     * Loads the magic360 gallery with the passed product ID.
322
     *
323
     * @param integer $productId The product ID of the magic360 column to load
324
     *
325
     * @return array The magic360 gallery
326
     */
327
    public function loadMagic360Columns($productId)
328
    {
329
        return $this->getProductMagic360ColumnsRepository()->findOneByProductId($productId);
330
    }
331
}
332