Total Complexity | 58 |
Total Lines | 1027 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Standard extends Base |
||
22 | implements \Aimeos\MShop\Catalog\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
||
23 | { |
||
24 | private $searchConfig = array( |
||
25 | 'id' => array( |
||
26 | 'code' => 'catalog.id', |
||
27 | 'internalcode' => 'mcat."id"', |
||
28 | 'label' => 'ID', |
||
29 | 'type' => 'integer', |
||
30 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
31 | 'public' => false, |
||
32 | ), |
||
33 | 'catalog.siteid' => array( |
||
34 | 'code' => 'catalog.siteid', |
||
35 | 'internalcode' => 'mcat."siteid"', |
||
36 | 'label' => 'Site ID', |
||
37 | 'type' => 'integer', |
||
38 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
39 | 'public' => false, |
||
40 | ), |
||
41 | 'parentid' => array( |
||
42 | 'code' => 'catalog.parentid', |
||
43 | 'internalcode' => 'mcat."parentid"', |
||
44 | 'label' => 'Parent ID', |
||
45 | 'type' => 'integer', |
||
46 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
47 | 'public' => false, |
||
48 | ), |
||
49 | 'level' => array( |
||
50 | 'code' => 'catalog.level', |
||
51 | 'internalcode' => 'mcat."level"', |
||
52 | 'label' => 'Tree level', |
||
53 | 'type' => 'integer', |
||
54 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
55 | 'public' => false, |
||
56 | ), |
||
57 | 'left' => array( |
||
58 | 'code' => 'catalog.left', |
||
59 | 'internalcode' => 'mcat."nleft"', |
||
60 | 'label' => 'Left value', |
||
61 | 'type' => 'integer', |
||
62 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
63 | 'public' => false, |
||
64 | ), |
||
65 | 'right' => array( |
||
66 | 'code' => 'catalog.right', |
||
67 | 'internalcode' => 'mcat."nright"', |
||
68 | 'label' => 'Right value', |
||
69 | 'type' => 'integer', |
||
70 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
71 | 'public' => false, |
||
72 | ), |
||
73 | 'label' => array( |
||
74 | 'code' => 'catalog.label', |
||
75 | 'internalcode' => 'mcat."label"', |
||
76 | 'label' => 'Label', |
||
77 | 'type' => 'string', |
||
78 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
79 | ), |
||
80 | 'code' => array( |
||
81 | 'code' => 'catalog.code', |
||
82 | 'internalcode' => 'mcat."code"', |
||
83 | 'label' => 'Code', |
||
84 | 'type' => 'string', |
||
85 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
86 | ), |
||
87 | 'catalog.target' => array( |
||
88 | 'code' => 'catalog.target', |
||
89 | 'internalcode' => 'mcat."target"', |
||
90 | 'label' => 'URL target', |
||
91 | 'type' => 'string', |
||
92 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
93 | ), |
||
94 | 'status' => array( |
||
95 | 'code' => 'catalog.status', |
||
96 | 'internalcode' => 'mcat."status"', |
||
97 | 'label' => 'Status', |
||
98 | 'type' => 'integer', |
||
99 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
100 | ), |
||
101 | 'config' => array( |
||
102 | 'code' => 'catalog.config', |
||
103 | 'internalcode' => 'mcat."config"', |
||
104 | 'label' => 'Config', |
||
105 | 'type' => 'string', |
||
106 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
107 | 'public' => false, |
||
108 | ), |
||
109 | 'catalog.ctime' => array( |
||
110 | 'label' => 'Create date/time', |
||
111 | 'code' => 'catalog.ctime', |
||
112 | 'internalcode' => 'mcat."ctime"', |
||
113 | 'type' => 'datetime', |
||
114 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
115 | 'public' => false, |
||
116 | ), |
||
117 | 'catalog.mtime' => array( |
||
118 | 'label' => 'Modify date/time', |
||
119 | 'code' => 'catalog.mtime', |
||
120 | 'internalcode' => 'mcat."mtime"', |
||
121 | 'type' => 'datetime', |
||
122 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
123 | 'public' => false, |
||
124 | ), |
||
125 | 'catalog.editor' => array( |
||
126 | 'code' => 'catalog.editor', |
||
127 | 'internalcode' => 'mcat."editor"', |
||
128 | 'label' => 'Editor', |
||
129 | 'type' => 'string', |
||
130 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, |
||
131 | 'public' => false, |
||
132 | ), |
||
133 | 'catalog:has' => array( |
||
134 | 'code' => 'catalog:has()', |
||
135 | 'internalcode' => '( |
||
136 | SELECT mcatli_has."id" FROM mshop_catalog_list AS mcatli_has |
||
137 | WHERE mcat."id" = mcatli_has."parentid" AND :site AND mcatli_has."domain" = $1 :type :refid |
||
138 | LIMIT 1 |
||
139 | )', |
||
140 | 'label' => 'Catalog has list item, parameter(<domain>[,<list type>[,<reference ID>)]]', |
||
141 | 'type' => 'null', |
||
142 | 'internaltype' => 'null', |
||
143 | 'public' => false, |
||
144 | ), |
||
145 | ); |
||
146 | |||
147 | |||
148 | /** |
||
149 | * Initializes the object. |
||
150 | * |
||
151 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
152 | */ |
||
153 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
||
154 | { |
||
155 | parent::__construct( $context, $this->searchConfig ); |
||
156 | $this->setResourceName( 'db-catalog' ); |
||
157 | |||
158 | $locale = $context->getLocale(); |
||
159 | |||
160 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
||
161 | $level = $context->getConfig()->get( 'mshop/catalog/manager/sitemode', $level ); |
||
162 | |||
163 | $siteIds = [$locale->getSiteId()]; |
||
164 | |||
165 | if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) { |
||
166 | $siteIds = array_merge( $siteIds, $locale->getSitePath() ); |
||
167 | } |
||
168 | |||
169 | if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) { |
||
170 | $siteIds = array_merge( $siteIds, $locale->getSiteSubTree() ); |
||
171 | } |
||
172 | |||
173 | $this->replaceSiteMarker( $this->searchConfig['catalog:has'], 'mcatli_has."siteid"', $siteIds, ':site' ); |
||
174 | |||
175 | |||
176 | $this->searchConfig['catalog:has']['function'] = function( &$source, array $params ) { |
||
177 | |||
178 | $source = str_replace( ':type', isset( $params[1] ) ? 'AND mcatli_has."type" = $2' : '', $source ); |
||
179 | $source = str_replace( ':refid', isset( $params[2] ) ? 'AND mcatli_has."refid" = $3' : '', $source ); |
||
180 | |||
181 | return $params; |
||
182 | }; |
||
183 | } |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Removes old entries from the storage. |
||
188 | * |
||
189 | * @param string[] $siteids List of IDs for sites whose entries should be deleted |
||
190 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
191 | */ |
||
192 | public function cleanup( array $siteids ) |
||
193 | { |
||
194 | $context = $this->getContext(); |
||
195 | $config = $context->getConfig(); |
||
196 | $search = $this->getObject()->createSearch(); |
||
197 | |||
198 | foreach( $config->get( 'mshop/catalog/manager/submanagers', ['lists'] ) as $domain ) { |
||
199 | $this->getObject()->getSubManager( $domain )->cleanup( $siteids ); |
||
200 | } |
||
201 | |||
202 | $dbm = $context->getDatabaseManager(); |
||
203 | $dbname = $this->getResourceName(); |
||
204 | $conn = $dbm->acquire( $dbname ); |
||
205 | |||
206 | try |
||
207 | { |
||
208 | /** mshop/catalog/manager/standard/cleanup/mysql |
||
209 | * Deletes the categories for the given site from the database |
||
210 | * |
||
211 | * @see mshop/catalog/manager/standard/cleanup/ansi |
||
212 | */ |
||
213 | |||
214 | /** mshop/catalog/manager/standard/cleanup/ansi |
||
215 | * Deletes the categories for the given site from the database |
||
216 | * |
||
217 | * Removes the records matched by the given site ID from the catalog |
||
218 | * database. |
||
219 | * |
||
220 | * The ":siteid" placeholder is replaced by the name and value of the |
||
221 | * site ID column and the given ID or list of IDs. |
||
222 | * |
||
223 | * The SQL statement should conform to the ANSI standard to be |
||
224 | * compatible with most relational database systems. This also |
||
225 | * includes using double quotes for table and column names. |
||
226 | * |
||
227 | * @param string SQL statement for removing the records |
||
228 | * @since 2014.03 |
||
229 | * @category Developer |
||
230 | * @see mshop/catalog/manager/standard/delete/ansi |
||
231 | * @see mshop/catalog/manager/standard/insert/ansi |
||
232 | * @see mshop/catalog/manager/standard/update/ansi |
||
233 | * @see mshop/catalog/manager/standard/newid/ansi |
||
234 | * @see mshop/catalog/manager/standard/search/ansi |
||
235 | * @see mshop/catalog/manager/standard/count/ansi |
||
236 | */ |
||
237 | $path = 'mshop/catalog/manager/standard/cleanup'; |
||
238 | $sql = $this->getSqlConfig( $path ); |
||
239 | |||
240 | $types = array( 'siteid' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ); |
||
241 | $translations = array( 'siteid' => '"siteid"' ); |
||
242 | |||
243 | $search->setConditions( $search->compare( '==', 'siteid', $siteids ) ); |
||
244 | $sql = str_replace( ':siteid', $search->getConditionSource( $types, $translations ), $sql ); |
||
245 | |||
246 | $stmt = $conn->create( $sql ); |
||
247 | $stmt->bind( 1, 0, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
248 | $stmt->bind( 2, 0x7FFFFFFF, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
249 | $stmt->execute()->finish(); |
||
250 | |||
251 | $dbm->release( $conn, $dbname ); |
||
252 | } |
||
253 | catch( \Exception $e ) |
||
254 | { |
||
255 | $dbm->release( $conn, $dbname ); |
||
256 | throw $e; |
||
257 | } |
||
258 | |||
259 | return $this; |
||
260 | } |
||
261 | |||
262 | |||
263 | /** |
||
264 | * Creates a new empty item instance |
||
265 | * |
||
266 | * @param array $values Values the item should be initialized with |
||
267 | * @return \Aimeos\MShop\Catalog\Item\Iface New catalog item object |
||
268 | */ |
||
269 | public function createItem( array $values = [] ) |
||
270 | { |
||
271 | $values['siteid'] = $this->getContext()->getLocale()->getSiteId(); |
||
272 | return $this->createItemBase( $values ); |
||
273 | } |
||
274 | |||
275 | |||
276 | /** |
||
277 | * Creates a search object. |
||
278 | * |
||
279 | * @param boolean $default Add default criteria |
||
280 | * @return \Aimeos\MW\Criteria\Iface Returns the search object |
||
281 | */ |
||
282 | public function createSearch( $default = false ) |
||
283 | { |
||
284 | if( $default === true ) { |
||
285 | return $this->createSearchBase( 'catalog' ); |
||
286 | } |
||
287 | |||
288 | return parent::createSearch(); |
||
289 | } |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Deletes the item specified by its ID. |
||
294 | * |
||
295 | * @param string $id ID of the item object |
||
296 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
297 | */ |
||
298 | public function deleteItem( $id ) |
||
299 | { |
||
300 | $this->begin(); |
||
301 | $this->lock(); |
||
302 | |||
303 | try |
||
304 | { |
||
305 | $siteid = $this->getContext()->getLocale()->getSiteId(); |
||
306 | $this->createTreeManager( $siteid )->deleteNode( $id ); |
||
307 | $this->unlock(); |
||
308 | $this->commit(); |
||
309 | } |
||
310 | catch( \Exception $e ) |
||
311 | { |
||
312 | $this->unlock(); |
||
313 | $this->rollback(); |
||
314 | throw $e; |
||
315 | } |
||
316 | |||
317 | return $this; |
||
318 | } |
||
319 | |||
320 | |||
321 | /** |
||
322 | * Removes multiple items specified by ids in the array. |
||
323 | * |
||
324 | * @param string[] $ids List of IDs |
||
325 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
326 | */ |
||
327 | public function deleteItems( array $ids ) |
||
328 | { |
||
329 | foreach( $ids as $id ) { |
||
330 | $this->getObject()->deleteItem( $id ); |
||
331 | } |
||
332 | |||
333 | return $this; |
||
334 | } |
||
335 | |||
336 | |||
337 | /** |
||
338 | * Returns the item specified by its code and domain/type if necessary |
||
339 | * |
||
340 | * @param string $code Code of the item |
||
341 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
342 | * @param string|null $domain Domain of the item if necessary to identify the item uniquely |
||
343 | * @param string|null $type Type code of the item if necessary to identify the item uniquely |
||
344 | * @param boolean $default True to add default criteria |
||
345 | * @return \Aimeos\MShop\Catalog\Item\Iface Catalog item object |
||
346 | */ |
||
347 | public function findItem( $code, array $ref = [], $domain = null, $type = null, $default = false ) |
||
348 | { |
||
349 | return $this->findItemBase( array( 'catalog.code' => $code ), $ref, $default ); |
||
350 | } |
||
351 | |||
352 | |||
353 | /** |
||
354 | * Returns the item specified by its ID. |
||
355 | * |
||
356 | * @param string $id Unique ID of the catalog item |
||
357 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
358 | * @param boolean $default Add default criteria |
||
359 | * @return \Aimeos\MShop\Catalog\Item\Iface Catalog item of the given ID |
||
360 | * @throws \Aimeos\MShop\Exception If item couldn't be found |
||
361 | */ |
||
362 | public function getItem( $id, array $ref = [], $default = false ) |
||
363 | { |
||
364 | return $this->getItemBase( 'catalog.id', $id, $ref, $default ); |
||
365 | } |
||
366 | |||
367 | |||
368 | /** |
||
369 | * Returns the available manager types |
||
370 | * |
||
371 | * @param boolean $withsub Return also the resource type of sub-managers if true |
||
372 | * @return string[] Type of the manager and submanagers, subtypes are separated by slashes |
||
373 | */ |
||
374 | public function getResourceType( $withsub = true ) |
||
375 | { |
||
376 | $path = 'mshop/catalog/manager/submanagers'; |
||
377 | return $this->getResourceTypeBase( 'catalog', $path, array( 'lists' ), $withsub ); |
||
378 | } |
||
379 | |||
380 | |||
381 | /** |
||
382 | * Returns the attributes that can be used for searching. |
||
383 | * |
||
384 | * @param boolean $withsub Return also attributes of sub-managers if true |
||
385 | * @return \Aimeos\MW\Criteria\Attribute\Iface[] List of search attribute items |
||
386 | */ |
||
387 | public function getSearchAttributes( $withsub = true ) |
||
388 | { |
||
389 | /** mshop/catalog/manager/submanagers |
||
390 | * List of manager names that can be instantiated by the catalog manager |
||
391 | * |
||
392 | * Managers provide a generic interface to the underlying storage. |
||
393 | * Each manager has or can have sub-managers caring about particular |
||
394 | * aspects. Each of these sub-managers can be instantiated by its |
||
395 | * parent manager using the getSubManager() method. |
||
396 | * |
||
397 | * The search keys from sub-managers can be normally used in the |
||
398 | * manager as well. It allows you to search for items of the manager |
||
399 | * using the search keys of the sub-managers to further limit the |
||
400 | * retrieved list of items. |
||
401 | * |
||
402 | * @param array List of sub-manager names |
||
403 | * @since 2014.03 |
||
404 | * @category Developer |
||
405 | */ |
||
406 | $path = 'mshop/catalog/manager/submanagers'; |
||
407 | |||
408 | return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
||
409 | } |
||
410 | |||
411 | |||
412 | /** |
||
413 | * Adds a new item object. |
||
414 | * |
||
415 | * @param \Aimeos\MShop\Catalog\Item\Iface $item Item which should be inserted |
||
416 | * @param string|null $parentId ID of the parent item where the item should be inserted into |
||
417 | * @param string|null $refId ID of the item where the item should be inserted before (null to append) |
||
418 | * @return \Aimeos\MShop\Catalog\Item\Iface $item Updated item including the generated ID |
||
419 | */ |
||
420 | public function insertItem( \Aimeos\MShop\Catalog\Item\Iface $item, $parentId = null, $refId = null ) |
||
421 | { |
||
422 | $this->begin(); |
||
423 | $this->lock(); |
||
424 | |||
425 | try |
||
426 | { |
||
427 | $node = $item->getNode(); |
||
|
|||
428 | $siteid = $this->getContext()->getLocale()->getSiteId(); |
||
429 | |||
430 | $this->createTreeManager( $siteid )->insertNode( $node, $parentId, $refId ); |
||
431 | $this->updateUsage( $node->getId(), $item, true ); |
||
432 | $this->unlock(); |
||
433 | $this->commit(); |
||
434 | } |
||
435 | catch( \Exception $e ) |
||
436 | { |
||
437 | $this->unlock(); |
||
438 | $this->rollback(); |
||
439 | throw $e; |
||
440 | } |
||
441 | |||
442 | $item = $this->saveListItems( $item, 'catalog' ); |
||
443 | return $this->saveChildren( $item ); |
||
444 | } |
||
445 | |||
446 | |||
447 | /** |
||
448 | * Moves an existing item to the new parent in the storage. |
||
449 | * |
||
450 | * @param string $id ID of the item that should be moved |
||
451 | * @param string $oldParentId ID of the old parent item which currently contains the item that should be removed |
||
452 | * @param string $newParentId ID of the new parent item where the item should be moved to |
||
453 | * @param string|null $refId ID of the item where the item should be inserted before (null to append) |
||
454 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
455 | */ |
||
456 | public function moveItem( $id, $oldParentId, $newParentId, $refId = null ) |
||
457 | { |
||
458 | $this->begin(); |
||
459 | $this->lock(); |
||
460 | |||
461 | try |
||
462 | { |
||
463 | $item = $this->getObject()->getItem( $id ); |
||
464 | $siteid = $this->getContext()->getLocale()->getSiteId(); |
||
465 | |||
466 | $this->createTreeManager( $siteid )->moveNode( $id, $oldParentId, $newParentId, $refId ); |
||
467 | $this->updateUsage( $id, $item ); |
||
468 | $this->unlock(); |
||
469 | $this->commit(); |
||
470 | } |
||
471 | catch( \Exception $e ) |
||
472 | { |
||
473 | $this->unlock(); |
||
474 | $this->rollback(); |
||
475 | throw $e; |
||
476 | } |
||
477 | |||
478 | return $this; |
||
479 | } |
||
480 | |||
481 | |||
482 | /** |
||
483 | * Updates an item object. |
||
484 | * |
||
485 | * @param \Aimeos\MShop\Catalog\Item\Iface $item Item object whose data should be saved |
||
486 | * @param boolean $fetch True if the new ID should be returned in the item |
||
487 | * @return \Aimeos\MShop\Catalog\Item\Iface $item Updated item including the generated ID |
||
488 | */ |
||
489 | public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true ) |
||
490 | { |
||
491 | self::checkClass( \Aimeos\MShop\Catalog\Item\Iface::class, $item ); |
||
492 | |||
493 | if( !$item->isModified() ) |
||
494 | { |
||
495 | $item = $this->saveListItems( $item, 'catalog', $fetch ); |
||
496 | return $this->saveChildren( $item ); |
||
497 | } |
||
498 | |||
499 | $node = $item->getNode(); |
||
500 | $siteid = $this->getContext()->getLocale()->getSiteId(); |
||
501 | |||
502 | $this->createTreeManager( $siteid )->saveNode( $node ); |
||
503 | $this->updateUsage( $node->getId(), $item ); |
||
504 | |||
505 | $item = $this->saveListItems( $item, 'catalog', $fetch ); |
||
506 | return $this->saveChildren( $item ); |
||
507 | } |
||
508 | |||
509 | |||
510 | /** |
||
511 | * Searches for all items matching the given critera. |
||
512 | * |
||
513 | * @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
||
514 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
515 | * @param integer|null &$total Number of items that are available in total |
||
516 | * @return \Aimeos\MShop\Catalog\Item\Iface[] List of catalog items |
||
517 | */ |
||
518 | public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
||
715 | } |
||
716 | |||
717 | |||
718 | /** |
||
719 | * Returns a list of items starting with the given category that are in the path to the root node |
||
720 | * |
||
721 | * @param string $id ID of item to get the path for |
||
722 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
723 | * @return \Aimeos\MShop\Catalog\Item\Iface[] Associative list of catalog items with IDs as keys |
||
724 | */ |
||
725 | public function getPath( $id, array $ref = [] ) |
||
726 | { |
||
727 | $sitePath = array_reverse( $this->getContext()->getLocale()->getSitePath() ); |
||
728 | |||
729 | foreach( $sitePath as $siteId ) |
||
730 | { |
||
731 | try { |
||
732 | $path = $this->createTreeManager( $siteId )->getPath( $id ); |
||
733 | } catch( \Exception $e ) { |
||
734 | continue; |
||
735 | } |
||
736 | |||
737 | if( !empty( $path ) ) |
||
738 | { |
||
739 | $itemMap = []; |
||
740 | |||
741 | foreach( $path as $node ) { |
||
742 | $itemMap[$node->getId()] = $node; |
||
743 | } |
||
744 | |||
745 | return $this->buildItems( $itemMap, $ref, 'catalog' ); |
||
746 | } |
||
747 | } |
||
748 | |||
749 | throw new \Aimeos\MShop\Catalog\Exception( sprintf( 'Catalog path for ID "%1$s" not found', $id ) ); |
||
750 | } |
||
751 | |||
752 | |||
753 | /** |
||
754 | * Returns a node and its descendants depending on the given resource. |
||
755 | * |
||
756 | * @param string|null $id Retrieve nodes starting from the given ID |
||
757 | * @param string[] List of domains (e.g. text, media, etc.) whose referenced items should be attached to the objects |
||
758 | * @param integer $level One of the level constants from \Aimeos\MW\Tree\Manager\Base |
||
759 | * @param \Aimeos\MW\Criteria\Iface|null $criteria Optional criteria object with conditions |
||
760 | * @return \Aimeos\MShop\Catalog\Item\Iface Catalog item, maybe with subnodes |
||
761 | */ |
||
762 | public function getTree( $id = null, array $ref = [], $level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE, \Aimeos\MW\Criteria\Iface $criteria = null ) |
||
763 | { |
||
764 | $sitePath = array_reverse( $this->getContext()->getLocale()->getSitePath() ); |
||
765 | |||
766 | foreach( $sitePath as $siteId ) |
||
767 | { |
||
768 | try { |
||
769 | $node = $this->createTreeManager( $siteId )->getNode( $id, $level, $criteria ); |
||
770 | } catch( \Exception $e ) { |
||
771 | continue; |
||
772 | } |
||
773 | |||
774 | $listItems = $listItemMap = $refIdMap = []; |
||
775 | $nodeMap = $this->getNodeMap( $node ); |
||
776 | |||
777 | if( count( $ref ) > 0 ) { |
||
778 | $listItems = $this->getListItems( array_keys( $nodeMap ), $ref, 'catalog' ); |
||
779 | } |
||
780 | |||
781 | foreach( $listItems as $listItem ) |
||
782 | { |
||
783 | $domain = $listItem->getDomain(); |
||
784 | $parentid = $listItem->getParentId(); |
||
785 | |||
786 | $listItemMap[$parentid][$domain][$listItem->getId()] = $listItem; |
||
787 | $refIdMap[$domain][$listItem->getRefId()][] = $parentid; |
||
788 | } |
||
789 | |||
790 | $refItemMap = $this->getRefItems( $refIdMap ); |
||
791 | $nodeid = $node->getId(); |
||
792 | |||
793 | $listItems = []; |
||
794 | if( array_key_exists( $nodeid, $listItemMap ) ) { |
||
795 | $listItems = $listItemMap[$nodeid]; |
||
796 | } |
||
797 | |||
798 | $refItems = []; |
||
799 | if( array_key_exists( $nodeid, $refItemMap ) ) { |
||
800 | $refItems = $refItemMap[$nodeid]; |
||
801 | } |
||
802 | |||
803 | $item = $this->createItemBase( [], $listItems, $refItems, [], $node ); |
||
804 | $this->createTree( $node, $item, $listItemMap, $refItemMap ); |
||
805 | |||
806 | return $item; |
||
807 | } |
||
808 | |||
809 | throw new \Aimeos\MShop\Catalog\Exception( sprintf( 'No catalog node for ID "%1$s"', $id ) ); |
||
810 | } |
||
811 | |||
812 | |||
813 | /** |
||
814 | * Creates a new extension manager in the domain. |
||
815 | * |
||
816 | * @param string $manager Name of the sub manager type |
||
817 | * @param string|null $name Name of the implementation, will be from configuration (or Default) |
||
818 | * @return \Aimeos\MShop\Common\Manager\Iface Manager extending the domain functionality |
||
819 | */ |
||
820 | public function getSubManager( $manager, $name = null ) |
||
821 | { |
||
822 | return $this->getSubManagerBase( 'catalog', $manager, $name ); |
||
823 | } |
||
824 | |||
825 | |||
826 | /** |
||
827 | * Saves the children of the given node |
||
828 | * |
||
829 | * @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item object incl. child items |
||
830 | * @return \Aimeos\MShop\Catalog\Item\Iface Catalog item with saved child items |
||
831 | */ |
||
832 | protected function saveChildren( \Aimeos\MShop\Catalog\Item\Iface $item ) |
||
858 | } |
||
859 | |||
860 | |||
861 | /** |
||
862 | * Locks the catalog table against modifications from other connections |
||
863 | * |
||
864 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
865 | */ |
||
866 | protected function lock() |
||
867 | { |
||
868 | $path = 'mshop/catalog/manager/standard/lock'; |
||
869 | |||
870 | if( ( $sql = $this->getSqlConfig( $path ) ) !== $path ) |
||
871 | { |
||
872 | $dbname = $this->getResourceName(); |
||
873 | $dbm = $this->getContext()->getDatabaseManager(); |
||
874 | |||
875 | $conn = $dbm->acquire( $dbname ); |
||
876 | $conn->create( $sql )->execute()->finish(); |
||
877 | $dbm->release( $conn, $dbname ); |
||
878 | } |
||
879 | |||
880 | return $this; |
||
881 | } |
||
882 | |||
883 | |||
884 | /** |
||
885 | * Unlocks the catalog table for modifications from other connections |
||
886 | * |
||
887 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
888 | */ |
||
889 | protected function unlock() |
||
890 | { |
||
891 | $path = 'mshop/catalog/manager/standard/unlock'; |
||
892 | |||
893 | if( ( $sql = $this->getSqlConfig( $path ) ) !== $path ) |
||
894 | { |
||
895 | $dbname = $this->getResourceName(); |
||
896 | $dbm = $this->getContext()->getDatabaseManager(); |
||
897 | |||
898 | $conn = $dbm->acquire( $dbname ); |
||
899 | $conn->create( $sql )->execute()->finish(); |
||
900 | $dbm->release( $conn, $dbname ); |
||
901 | } |
||
902 | |||
903 | return $this; |
||
904 | } |
||
905 | |||
906 | |||
907 | /** |
||
908 | * Updates the usage information of a node. |
||
909 | * |
||
910 | * @param string $id Id of the record |
||
911 | * @param \Aimeos\MShop\Catalog\Item\Iface $item Catalog item |
||
912 | * @param boolean $case True if the record shoud be added or false for an update |
||
913 | * @return \Aimeos\MShop\Catalog\Manager\Iface Manager object for chaining method calls |
||
914 | */ |
||
915 | private function updateUsage( $id, \Aimeos\MShop\Catalog\Item\Iface $item, $case = false ) |
||
1048 | } |
||
1049 | } |
||
1050 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.