1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Metaways Infosystems GmbH, 2012 |
||
6 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||
7 | * @package MShop |
||
8 | * @subpackage Index |
||
9 | */ |
||
10 | |||
11 | namespace Aimeos\MShop\Index\Manager\Attribute; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * Index sub-manager for product attributes. |
||
16 | * |
||
17 | * @package MShop |
||
18 | * @subpackage Index |
||
19 | */ |
||
20 | class Standard |
||
21 | extends \Aimeos\MShop\Index\Manager\DBBase |
||
22 | implements \Aimeos\MShop\Index\Manager\Attribute\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface |
||
23 | { |
||
24 | private $searchConfig = array( |
||
25 | 'index.attribute.id' => array( |
||
26 | 'code' => 'index.attribute.id', |
||
27 | 'internalcode' => 'mindat."attrid"', |
||
28 | 'internaldeps'=>array( 'LEFT JOIN "mshop_index_attribute" AS mindat ON mindat."prodid" = mpro."id"' ), |
||
29 | 'label' => 'Product index attribute ID', |
||
30 | 'type' => 'integer', |
||
31 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT, |
||
32 | 'public' => false, |
||
33 | ), |
||
34 | 'index.attribute:all' => array( |
||
35 | 'code' => 'index.attribute:all()', |
||
36 | 'internalcode' => '( SELECT mpro_all."id" FROM mshop_product AS mpro_all |
||
37 | WHERE mpro."id" = mpro_all."id" AND ( |
||
38 | SELECT COUNT(DISTINCT mindat_all."attrid") |
||
39 | FROM "mshop_index_attribute" AS mindat_all |
||
40 | WHERE mpro."id" = mindat_all."prodid" AND :site |
||
41 | AND mindat_all."attrid" IN ( $1 ) ) = $2 |
||
42 | )', |
||
43 | 'label' => 'Number of product attributes, parameter(<attribute IDs>)', |
||
44 | 'type' => 'null', |
||
45 | 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_NULL, |
||
46 | 'public' => false, |
||
47 | ), |
||
48 | ); |
||
49 | |||
50 | private $subManagers; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Initializes the manager instance. |
||
55 | * |
||
56 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
57 | */ |
||
58 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
||
59 | { |
||
60 | parent::__construct( $context ); |
||
61 | |||
62 | $locale = $context->getLocale(); |
||
63 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
||
64 | $level = $context->getConfig()->get( 'mshop/index/manager/sitemode', $level ); |
||
65 | |||
66 | $siteIds = [$locale->getSiteId()]; |
||
67 | |||
68 | if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) { |
||
69 | $siteIds = array_merge( $siteIds, $locale->getSitePath() ); |
||
70 | } |
||
71 | |||
72 | if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) { |
||
73 | $siteIds = array_merge( $siteIds, $locale->getSiteSubTree() ); |
||
74 | } |
||
75 | |||
76 | $this->searchConfig['index.attribute:all']['function'] = function( $source, array $params ) { |
||
77 | return [$params[0], count( explode( ',', $params[0] ) )]; |
||
78 | }; |
||
79 | |||
80 | $this->replaceSiteMarker( $this->searchConfig['index.attribute:all'], 'mindat_all."siteid"', $siteIds ); |
||
81 | } |
||
82 | |||
83 | |||
84 | /** |
||
85 | * Counts the number products that are available for the values of the given key. |
||
86 | * |
||
87 | * @param \Aimeos\MW\Criteria\Iface $search Search criteria |
||
88 | * @param string $key Search key (usually the ID) to aggregate products for |
||
89 | * @return array List of ID values as key and the number of counted products as value |
||
90 | */ |
||
91 | public function aggregate( \Aimeos\MW\Criteria\Iface $search, $key ) |
||
92 | { |
||
93 | return $this->aggregateBase( $search, $key, 'mshop/index/manager/standard/aggregate' ); |
||
94 | } |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Removes old entries from the storage. |
||
99 | * |
||
100 | * @param integer[] $siteids List of IDs for sites whose entries should be deleted |
||
101 | */ |
||
102 | public function cleanup( array $siteids ) |
||
103 | { |
||
104 | parent::cleanup( $siteids ); |
||
105 | |||
106 | $this->cleanupBase( $siteids, 'mshop/index/manager/attribute/standard/delete' ); |
||
107 | } |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Removes all entries not touched after the given timestamp in the index. |
||
112 | * This can be a long lasting operation. |
||
113 | * |
||
114 | * @param string $timestamp Timestamp in ISO format (YYYY-MM-DD HH:mm:ss) |
||
115 | */ |
||
116 | public function cleanupIndex( $timestamp ) |
||
117 | { |
||
118 | /** mshop/index/manager/attribute/standard/cleanup/mysql |
||
119 | * Deletes the index attribute records that haven't been touched |
||
120 | * |
||
121 | * @see mshop/index/manager/attribute/standard/cleanup/ansi |
||
122 | */ |
||
123 | |||
124 | /** mshop/index/manager/attribute/standard/cleanup/ansi |
||
125 | * Deletes the index attribute records that haven't been touched |
||
126 | * |
||
127 | * During the rebuild process of the product index, the entries of all |
||
128 | * active products will be removed and readded. Thus, no stale data for |
||
129 | * these products will remain in the database. |
||
130 | * |
||
131 | * All products that have been disabled since the last rebuild will be |
||
132 | * still part of the index. The cleanup statement removes all records |
||
133 | * that belong to products that haven't been touched during the index |
||
134 | * rebuild because these are the disabled ones. |
||
135 | * |
||
136 | * The SQL statement should conform to the ANSI standard to be |
||
137 | * compatible with most relational database systems. This also |
||
138 | * includes using double quotes for table and column names. |
||
139 | * |
||
140 | * @param string SQL statement for deleting the outdated attribute index records |
||
141 | * @since 2014.03 |
||
142 | * @category Developer |
||
143 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
144 | * @see mshop/index/manager/attribute/standard/delete/ansi |
||
145 | * @see mshop/index/manager/attribute/standard/insert/ansi |
||
146 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
147 | */ |
||
148 | $this->cleanupIndexBase( $timestamp, 'mshop/index/manager/attribute/standard/cleanup' ); |
||
149 | } |
||
150 | |||
151 | |||
152 | /** |
||
153 | * Removes multiple items from the index. |
||
154 | * |
||
155 | * @param array $ids list of Product IDs |
||
156 | */ |
||
157 | public function deleteItems( array $ids ) |
||
158 | { |
||
159 | /** mshop/index/manager/attribute/standard/delete/mysql |
||
160 | * Deletes the items matched by the given IDs from the database |
||
161 | * |
||
162 | * @see mshop/index/manager/attribute/standard/delete/ansi |
||
163 | */ |
||
164 | |||
165 | /** mshop/index/manager/attribute/standard/delete/ansi |
||
166 | * Deletes the items matched by the given IDs from the database |
||
167 | * |
||
168 | * Removes the records specified by the given IDs from the index database. |
||
169 | * The records must be from the site that is configured via the |
||
170 | * context item. |
||
171 | * |
||
172 | * The ":cond" placeholder is replaced by the name of the ID column and |
||
173 | * the given ID or list of IDs while the site ID is bound to the question |
||
174 | * mark. |
||
175 | * |
||
176 | * The SQL statement should conform to the ANSI standard to be |
||
177 | * compatible with most relational database systems. This also |
||
178 | * includes using double quotes for table and column names. |
||
179 | * |
||
180 | * @param string SQL statement for deleting index attribute records |
||
181 | * @since 2014.03 |
||
182 | * @category Developer |
||
183 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
184 | * @see mshop/index/manager/attribute/standard/cleanup/ansi |
||
185 | * @see mshop/index/manager/attribute/standard/insert/ansi |
||
186 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
187 | */ |
||
188 | $this->deleteItemsBase( $ids, 'mshop/index/manager/attribute/standard/delete' ); |
||
189 | } |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Returns the available manager types |
||
194 | * |
||
195 | * @param boolean $withsub Return also the resource type of sub-managers if true |
||
196 | * @return array Type of the manager and submanagers, subtypes are separated by slashes |
||
197 | */ |
||
198 | public function getResourceType( $withsub = true ) |
||
199 | { |
||
200 | $path = 'mshop/index/manager/attribute/submanagers'; |
||
201 | |||
202 | return $this->getResourceTypeBase( 'index/attribute', $path, [], $withsub ); |
||
203 | } |
||
204 | |||
205 | |||
206 | /** |
||
207 | * Returns a list of objects describing the available criterias for searching. |
||
208 | * |
||
209 | * @param boolean $withsub Return also attributes of sub-managers if true |
||
210 | * @return array List of items implementing \Aimeos\MW\Criteria\Attribute\Iface |
||
211 | */ |
||
212 | public function getSearchAttributes( $withsub = true ) |
||
213 | { |
||
214 | $list = parent::getSearchAttributes( $withsub ); |
||
215 | |||
216 | /** mshop/index/manager/attribute/submanagers |
||
217 | * List of manager names that can be instantiated by the index attribute manager |
||
218 | * |
||
219 | * Managers provide a generic interface to the underlying storage. |
||
220 | * Each manager has or can have sub-managers caring about particular |
||
221 | * aspects. Each of these sub-managers can be instantiated by its |
||
222 | * parent manager using the getSubManager() method. |
||
223 | * |
||
224 | * The search keys from sub-managers can be normally used in the |
||
225 | * manager as well. It allows you to search for items of the manager |
||
226 | * using the search keys of the sub-managers to further limit the |
||
227 | * retrieved list of items. |
||
228 | * |
||
229 | * @param array List of sub-manager names |
||
230 | * @since 2014.03 |
||
231 | * @category Developer |
||
232 | */ |
||
233 | $path = 'mshop/index/manager/attribute/submanagers'; |
||
234 | |||
235 | $list += $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub ); |
||
236 | |||
237 | return $list; |
||
238 | } |
||
239 | |||
240 | |||
241 | /** |
||
242 | * Returns a new manager for product extensions. |
||
243 | * |
||
244 | * @param string $manager Name of the sub manager type in lower case |
||
245 | * @param string|null $name Name of the implementation, will be from configuration (or Default) if null |
||
246 | * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g stock, tags, locations, etc. |
||
247 | */ |
||
248 | public function getSubManager( $manager, $name = null ) |
||
249 | { |
||
250 | /** mshop/index/manager/attribute/name |
||
251 | * Class name of the used index attribute manager implementation |
||
252 | * |
||
253 | * Each default index attribute manager can be replaced by an alternative imlementation. |
||
254 | * To use this implementation, you have to set the last part of the class |
||
255 | * name as configuration value so the manager factory knows which class it |
||
256 | * has to instantiate. |
||
257 | * |
||
258 | * For example, if the name of the default class is |
||
259 | * |
||
260 | * \Aimeos\MShop\Index\Manager\Attribute\Standard |
||
261 | * |
||
262 | * and you want to replace it with your own version named |
||
263 | * |
||
264 | * \Aimeos\MShop\Index\Manager\Attribute\Myattribute |
||
265 | * |
||
266 | * then you have to set the this configuration option: |
||
267 | * |
||
268 | * mshop/index/manager/attribute/name = Myattribute |
||
269 | * |
||
270 | * The value is the last part of your own class name and it's case sensitive, |
||
271 | * so take care that the configuration value is exactly named like the last |
||
272 | * part of the class name. |
||
273 | * |
||
274 | * The allowed characters of the class name are A-Z, a-z and 0-9. No other |
||
275 | * characters are possible! You should always start the last part of the class |
||
276 | * name with an upper case character and continue only with lower case characters |
||
277 | * or numbers. Avoid chamel case names like "MyAttribute"! |
||
278 | * |
||
279 | * @param string Last part of the class name |
||
280 | * @since 2014.03 |
||
281 | * @category Developer |
||
282 | */ |
||
283 | |||
284 | /** mshop/index/manager/attribute/decorators/excludes |
||
285 | * Excludes decorators added by the "common" option from the index attribute manager |
||
286 | * |
||
287 | * Decorators extend the functionality of a class by adding new aspects |
||
288 | * (e.g. log what is currently done), executing the methods of the underlying |
||
289 | * class only in certain conditions (e.g. only for logged in users) or |
||
290 | * modify what is returned to the caller. |
||
291 | * |
||
292 | * This option allows you to remove a decorator added via |
||
293 | * "mshop/common/manager/decorators/default" before they are wrapped |
||
294 | * around the index attribute manager. |
||
295 | * |
||
296 | * mshop/index/manager/attribute/decorators/excludes = array( 'decorator1' ) |
||
297 | * |
||
298 | * This would remove the decorator named "decorator1" from the list of |
||
299 | * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via |
||
300 | * "mshop/common/manager/decorators/default" for the index attribute manager. |
||
301 | * |
||
302 | * @param array List of decorator names |
||
303 | * @since 2014.03 |
||
304 | * @category Developer |
||
305 | * @see mshop/common/manager/decorators/default |
||
306 | * @see mshop/index/manager/attribute/decorators/global |
||
307 | * @see mshop/index/manager/attribute/decorators/local |
||
308 | */ |
||
309 | |||
310 | /** mshop/index/manager/attribute/decorators/global |
||
311 | * Adds a list of globally available decorators only to the index attribute manager |
||
312 | * |
||
313 | * Decorators extend the functionality of a class by adding new aspects |
||
314 | * (e.g. log what is currently done), executing the methods of the underlying |
||
315 | * class only in certain conditions (e.g. only for logged in users) or |
||
316 | * modify what is returned to the caller. |
||
317 | * |
||
318 | * This option allows you to wrap global decorators |
||
319 | * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the index attribute |
||
320 | * manager. |
||
321 | * |
||
322 | * mshop/index/manager/attribute/decorators/global = array( 'decorator1' ) |
||
323 | * |
||
324 | * This would add the decorator named "decorator1" defined by |
||
325 | * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the index |
||
326 | * attribute manager. |
||
327 | * |
||
328 | * @param array List of decorator names |
||
329 | * @since 2014.03 |
||
330 | * @category Developer |
||
331 | * @see mshop/common/manager/decorators/default |
||
332 | * @see mshop/index/manager/attribute/decorators/excludes |
||
333 | * @see mshop/index/manager/attribute/decorators/local |
||
334 | */ |
||
335 | |||
336 | /** mshop/index/manager/attribute/decorators/local |
||
337 | * Adds a list of local decorators only to the index attribute manager |
||
338 | * |
||
339 | * Decorators extend the functionality of a class by adding new aspects |
||
340 | * (e.g. log what is currently done), executing the methods of the underlying |
||
341 | * class only in certain conditions (e.g. only for logged in users) or |
||
342 | * modify what is returned to the caller. |
||
343 | * |
||
344 | * This option allows you to wrap local decorators |
||
345 | * ("\Aimeos\MShop\Index\Manager\Attribute\Decorator\*") around the index |
||
346 | * attribute manager. |
||
347 | * |
||
348 | * mshop/index/manager/attribute/decorators/local = array( 'decorator2' ) |
||
349 | * |
||
350 | * This would add the decorator named "decorator2" defined by |
||
351 | * "\Aimeos\MShop\Index\Manager\Attribute\Decorator\Decorator2" only to th |
||
352 | * index attribute manager. |
||
353 | * |
||
354 | * @param array List of decorator names |
||
355 | * @since 2014.03 |
||
356 | * @category Developer |
||
357 | * @see mshop/common/manager/decorators/default |
||
358 | * @see mshop/index/manager/attribute/decorators/excludes |
||
359 | * @see mshop/index/manager/attribute/decorators/global |
||
360 | */ |
||
361 | |||
362 | return $this->getSubManagerBase( 'index', 'attribute/' . $manager, $name ); |
||
363 | } |
||
364 | |||
365 | |||
366 | /** |
||
367 | * Optimizes the index if necessary. |
||
368 | * Execution of this operation can take a very long time and shouldn't be |
||
369 | * called through a web server enviroment. |
||
370 | */ |
||
371 | public function optimize() |
||
372 | { |
||
373 | /** mshop/index/manager/attribute/standard/optimize/mysql |
||
374 | * Optimizes the stored attribute data for retrieving the records faster |
||
375 | * |
||
376 | * @see mshop/index/manager/attribute/standard/optimize/ansi |
||
377 | */ |
||
378 | |||
379 | /** mshop/index/manager/attribute/standard/optimize/ansi |
||
380 | * Optimizes the stored attribute data for retrieving the records faster |
||
381 | * |
||
382 | * The SQL statement should reorganize the data in the DBMS storage to |
||
383 | * optimize access to the records of the table or tables. Some DBMS |
||
384 | * offer specialized statements to optimize indexes and records. This |
||
385 | * statement doesn't return any records. |
||
386 | * |
||
387 | * The SQL statement should conform to the ANSI standard to be |
||
388 | * compatible with most relational database systems. This also |
||
389 | * includes using double quotes for table and column names. |
||
390 | * |
||
391 | * @param string SQL statement for optimizing the stored attribute data |
||
392 | * @since 2014.09 |
||
393 | * @category Developer |
||
394 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
395 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
396 | * @see mshop/index/manager/attribute/standard/aggregate/ansi |
||
397 | */ |
||
398 | $this->optimizeBase( 'mshop/index/manager/attribute/standard/optimize' ); |
||
399 | } |
||
400 | |||
401 | |||
402 | /** |
||
403 | * Rebuilds the index attribute for searching products or specified list of products. |
||
404 | * This can be a long lasting operation. |
||
405 | * |
||
406 | * @param \Aimeos\MShop\Common\Item\Iface[] $items Associative list of product IDs and items implementing \Aimeos\MShop\Product\Item\Iface |
||
407 | */ |
||
408 | public function rebuildIndex( array $items = [] ) |
||
409 | { |
||
410 | if( empty( $items ) ) { return; } |
||
411 | |||
412 | \Aimeos\MW\Common\Base::checkClassList( \Aimeos\MShop\Product\Item\Iface::class, $items ); |
||
413 | |||
414 | $context = $this->getContext(); |
||
415 | $dbm = $context->getDatabaseManager(); |
||
416 | $dbname = $this->getResourceName(); |
||
417 | $conn = $dbm->acquire( $dbname ); |
||
418 | |||
419 | try |
||
420 | { |
||
421 | /** mshop/index/manager/attribute/standard/insert/mysql |
||
422 | * Inserts a new attribute record into the product index database |
||
423 | * |
||
424 | * @see mshop/index/manager/attribute/standard/insert/ansi |
||
425 | */ |
||
426 | |||
427 | /** mshop/index/manager/attribute/standard/insert/ansi |
||
428 | * Inserts a new attribute record into the product index database |
||
429 | * |
||
430 | * During the product index rebuild, attributes related to a product |
||
431 | * will be stored in the index for this product. All records |
||
432 | * are deleted before the new ones are inserted. |
||
433 | * |
||
434 | * The SQL statement must be a string suitable for being used as |
||
435 | * prepared statement. It must include question marks for binding |
||
436 | * the values from the order item to the statement before they are |
||
437 | * sent to the database server. The number of question marks must |
||
438 | * be the same as the number of columns listed in the INSERT |
||
439 | * statement. The order of the columns must correspond to the |
||
440 | * order in the rebuildIndex() method, so the correct values are |
||
441 | * bound to the columns. |
||
442 | * |
||
443 | * The SQL statement should conform to the ANSI standard to be |
||
444 | * compatible with most relational database systems. This also |
||
445 | * includes using double quotes for table and column names. |
||
446 | * |
||
447 | * @param string SQL statement for inserting records |
||
448 | * @since 2014.03 |
||
449 | * @category Developer |
||
450 | * @see mshop/index/manager/attribute/standard/cleanup/ansi |
||
451 | * @see mshop/index/manager/attribute/standard/delete/ansi |
||
452 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
453 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
454 | */ |
||
455 | $stmt = $this->getCachedStatement( $conn, 'mshop/index/manager/attribute/standard/insert' ); |
||
456 | |||
457 | foreach( $items as $item ) |
||
458 | { |
||
459 | $listTypes = []; |
||
460 | foreach( $item->getListItems( 'attribute' ) as $listItem ) { |
||
461 | $listTypes[$listItem->getRefId()][] = $listItem->getType(); |
||
462 | } |
||
463 | |||
464 | $this->saveAttributes( $stmt, $item, $listTypes ); |
||
465 | } |
||
466 | |||
467 | $dbm->release( $conn, $dbname ); |
||
468 | } |
||
469 | catch( \Exception $e ) |
||
470 | { |
||
471 | $dbm->release( $conn, $dbname ); |
||
472 | throw $e; |
||
473 | } |
||
474 | |||
475 | foreach( $this->getSubManagers() as $submanager ) { |
||
476 | $submanager->rebuildIndex( $items ); |
||
477 | } |
||
478 | } |
||
479 | |||
480 | |||
481 | /** |
||
482 | * Searches for items matching the given criteria. |
||
483 | * |
||
484 | * @param \Aimeos\MW\Criteria\Iface $search Search criteria object |
||
485 | * @param string[] $ref List of domains to fetch list items and referenced items for |
||
486 | * @param integer|null &$total Number of items that are available in total |
||
487 | * @return array List of items implementing \Aimeos\MShop\Product\Item\Iface with ids as keys |
||
488 | */ |
||
489 | public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null ) |
||
490 | { |
||
491 | /** mshop/index/manager/attribute/standard/search/mysql |
||
492 | * Retrieves the records matched by the given criteria in the database |
||
493 | * |
||
494 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
495 | */ |
||
496 | |||
497 | /** mshop/index/manager/attribute/standard/search/ansi |
||
498 | * Retrieves the records matched by the given criteria in the database |
||
499 | * |
||
500 | * Fetches the records matched by the given criteria from the product index |
||
501 | * database. The records must be from one of the sites that are |
||
502 | * configured via the context item. If the current site is part of |
||
503 | * a tree of sites, the SELECT statement can retrieve all records |
||
504 | * from the current site and the complete sub-tree of sites. |
||
505 | * |
||
506 | * As the records can normally be limited by criteria from sub-managers, |
||
507 | * their tables must be joined in the SQL context. This is done by |
||
508 | * using the "internaldeps" property from the definition of the ID |
||
509 | * column of the sub-managers. These internal dependencies specify |
||
510 | * the JOIN between the tables and the used columns for joining. The |
||
511 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
512 | * the sub-managers. |
||
513 | * |
||
514 | * To limit the records matched, conditions can be added to the given |
||
515 | * criteria object. It can contain comparisons like column names that |
||
516 | * must match specific values which can be combined by AND, OR or NOT |
||
517 | * operators. The resulting string of SQL conditions replaces the |
||
518 | * ":cond" placeholder before the statement is sent to the database |
||
519 | * server. |
||
520 | * |
||
521 | * If the records that are retrieved should be ordered by one or more |
||
522 | * columns, the generated string of column / sort direction pairs |
||
523 | * replaces the ":order" placeholder. In case no ordering is required, |
||
524 | * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
||
525 | * markers is removed to speed up retrieving the records. Columns of |
||
526 | * sub-managers can also be used for ordering the result set but then |
||
527 | * no index can be used. |
||
528 | * |
||
529 | * The number of returned records can be limited and can start at any |
||
530 | * number between the begining and the end of the result set. For that |
||
531 | * the ":size" and ":start" placeholders are replaced by the |
||
532 | * corresponding values from the criteria object. The default values |
||
533 | * are 0 for the start and 100 for the size value. |
||
534 | * |
||
535 | * The SQL statement should conform to the ANSI standard to be |
||
536 | * compatible with most relational database systems. This also |
||
537 | * includes using double quotes for table and column names. |
||
538 | * |
||
539 | * @param string SQL statement for searching items |
||
540 | * @since 2014.03 |
||
541 | * @category Developer |
||
542 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
543 | * @see mshop/index/manager/attribute/standard/optimize/ansi |
||
544 | * @see mshop/index/manager/attribute/standard/aggregate/ansi |
||
545 | */ |
||
546 | $cfgPathSearch = 'mshop/index/manager/attribute/standard/search'; |
||
547 | |||
548 | /** mshop/index/manager/attribute/standard/count/mysql |
||
549 | * Counts the number of records matched by the given criteria in the database |
||
550 | * |
||
551 | * @see mshop/index/manager/attribute/standard/count/ansi |
||
552 | */ |
||
553 | |||
554 | /** mshop/index/manager/attribute/standard/count/ansi |
||
555 | * Counts the number of records matched by the given criteria in the database |
||
556 | * |
||
557 | * Counts all records matched by the given criteria from the product index |
||
558 | * database. The records must be from one of the sites that are |
||
559 | * configured via the context item. If the current site is part of |
||
560 | * a tree of sites, the statement can count all records from the |
||
561 | * current site and the complete sub-tree of sites. |
||
562 | * |
||
563 | * As the records can normally be limited by criteria from sub-managers, |
||
564 | * their tables must be joined in the SQL context. This is done by |
||
565 | * using the "internaldeps" property from the definition of the ID |
||
566 | * column of the sub-managers. These internal dependencies specify |
||
567 | * the JOIN between the tables and the used columns for joining. The |
||
568 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
569 | * the sub-managers. |
||
570 | * |
||
571 | * To limit the records matched, conditions can be added to the given |
||
572 | * criteria object. It can contain comparisons like column names that |
||
573 | * must match specific values which can be combined by AND, OR or NOT |
||
574 | * operators. The resulting string of SQL conditions replaces the |
||
575 | * ":cond" placeholder before the statement is sent to the database |
||
576 | * server. |
||
577 | * |
||
578 | * Both, the strings for ":joins" and for ":cond" are the same as for |
||
579 | * the "search" SQL statement. |
||
580 | * |
||
581 | * Contrary to the "search" statement, it doesn't return any records |
||
582 | * but instead the number of records that have been found. As counting |
||
583 | * thousands of records can be a long running task, the maximum number |
||
584 | * of counted records is limited for performance reasons. |
||
585 | * |
||
586 | * The SQL statement should conform to the ANSI standard to be |
||
587 | * compatible with most relational database systems. This also |
||
588 | * includes using double quotes for table and column names. |
||
589 | * |
||
590 | * @param string SQL statement for counting items |
||
591 | * @since 2014.03 |
||
592 | * @category Developer |
||
593 | * @see mshop/index/manager/attribute/standard/search/ansi |
||
594 | * @see mshop/index/manager/attribute/standard/optimize/ansi |
||
595 | * @see mshop/index/manager/attribute/standard/aggregate/ansi |
||
596 | */ |
||
597 | $cfgPathCount = 'mshop/index/manager/attribute/standard/count'; |
||
598 | |||
599 | return $this->searchItemsIndexBase( $search, $ref, $total, $cfgPathSearch, $cfgPathCount ); |
||
600 | } |
||
601 | |||
602 | |||
603 | /** |
||
604 | * Returns the list of sub-managers available for the index attribute manager. |
||
605 | * |
||
606 | * @return array Associative list of the sub-domain as key and the manager object as value |
||
607 | */ |
||
608 | protected function getSubManagers() |
||
609 | { |
||
610 | if( $this->subManagers === null ) |
||
611 | { |
||
612 | $this->subManagers = []; |
||
613 | |||
614 | /** mshop/index/manager/attribute/submanagers |
||
615 | * A list of sub-manager names used for indexing associated items to attributes |
||
616 | * |
||
617 | * All items referenced by a product (e.g. texts, prices, media, |
||
618 | * etc.) are added to the product index via specialized index |
||
619 | * managers. You can add the name of new sub-managers to add more |
||
620 | * data to the index or remove existing ones if you don't want to |
||
621 | * index that data at all. |
||
622 | * |
||
623 | * This option configures the sub-managers that cares about |
||
624 | * indexing data associated to product attributes. |
||
625 | * |
||
626 | * @param string List of index sub-manager names |
||
627 | * @since 2014.09 |
||
628 | * @category User |
||
629 | * @category Developer |
||
630 | * @see mshop/index/manager/standard/submanagers |
||
631 | */ |
||
632 | $path = 'mshop/index/manager/attribute/submanagers'; |
||
633 | |||
634 | foreach( $this->getContext()->getConfig()->get( $path, [] ) as $domain ) { |
||
635 | $this->subManagers[$domain] = $this->getObject()->getSubManager( $domain ); |
||
636 | } |
||
637 | |||
638 | return $this->subManagers; |
||
639 | } |
||
640 | |||
641 | return $this->subManagers; |
||
642 | } |
||
643 | |||
644 | |||
645 | /** |
||
646 | * Saves the text items referenced indirectly by products |
||
647 | * |
||
648 | * @param \Aimeos\MW\DB\Statement\Iface $stmt Prepared SQL statement with place holders |
||
649 | * @param \Aimeos\MShop\Common\Item\ListRef\Iface $item Item containing associated text items |
||
650 | * @param array $listTypes Associative list of item ID / list type code pairs |
||
651 | * @throws \Aimeos\MShop\Index\Exception If no list type for the item is available |
||
652 | */ |
||
653 | protected function saveAttributes( \Aimeos\MW\DB\Statement\Iface $stmt, \Aimeos\MShop\Common\Item\ListRef\Iface $item, array $listTypes ) |
||
654 | { |
||
655 | $context = $this->getContext(); |
||
656 | $siteid = $context->getLocale()->getSiteId(); |
||
657 | $editor = $context->getEditor(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
658 | $date = date( 'Y-m-d H:i:s' ); |
||
659 | |||
660 | foreach( $item->getRefItems( 'attribute' ) as $refId => $refItem ) |
||
661 | { |
||
662 | if( !isset( $listTypes[$refId] ) ) { |
||
663 | continue; |
||
664 | } |
||
665 | |||
666 | foreach( $listTypes[$refId] as $listType ) |
||
667 | { |
||
668 | $stmt->bind( 1, $item->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
669 | $stmt->bind( 2, $refItem->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
670 | $stmt->bind( 3, $listType ); |
||
671 | $stmt->bind( 4, $refItem->getType() ); |
||
672 | $stmt->bind( 5, $refItem->getCode() ); |
||
673 | $stmt->bind( 6, $date ); // mtime |
||
674 | $stmt->bind( 7, $siteid, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
675 | |||
676 | try { |
||
677 | $stmt->execute()->finish(); |
||
678 | } catch( \Aimeos\MW\DB\Exception $e ) { ; } // Ignore duplicates |
||
679 | } |
||
680 | } |
||
681 | } |
||
682 | } |