Completed
Push — master ( 9df19e...cf5247 )
by Tim
10s
created

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