Passed
Push — master ( 8673f8...5c56ce )
by Aimeos
04:42
created

Standard::copy()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 33
rs 9.0111
cc 6
nc 8
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package MShop
7
 * @subpackage Media
8
 */
9
10
11
namespace Aimeos\MShop\Media\Manager;
12
13
use \Psr\Http\Message\UploadedFileInterface;
0 ignored issues
show
Bug introduced by
The type \Psr\Http\Message\UploadedFileInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
16
/**
17
 * Default media manager implementation.
18
 *
19
 * @package MShop
20
 * @subpackage Media
21
 */
22
class Standard
23
	extends Base
24
	implements \Aimeos\MShop\Media\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
25
{
26
	use \Aimeos\MShop\Common\Manager\PropertyRef\Traits;
27
	use \Aimeos\MShop\Common\Manager\ListsRef\Traits;
28
	use \Aimeos\MShop\Upload;
29
	use Preview;
30
31
32
	/**
33
	 * Copies the media item and the referenced files
34
	 *
35
	 * @param \Aimeos\MShop\Media\Item\Iface $item Media item whose files should be copied
36
	 * @return \Aimeos\MShop\Media\Item\Iface Copied media item with new files
37
	 */
38
	public function copy( \Aimeos\MShop\Media\Item\Iface $item ) : \Aimeos\MShop\Media\Item\Iface
39
	{
40
		$item = ( clone $item )->setId( null );
41
42
		$path = $item->getUrl();
43
		$mime = $item->getMimeType();
44
		$domain = $item->getDomain();
45
		$previews = $item->getPreviews();
46
		$fsname = $item->getFileSystem();
47
		$fs = $this->context()->fs( $fsname );
48
49
		if( $fs->has( $path ) )
50
		{
51
			$newPath = $this->path( substr( basename( $path ), 9 ), $mime, $domain );
52
			$fs->copy( $path, $newPath );
53
			$item->setUrl( $newPath );
54
		}
55
56
		if( empty( $previews ) ) {
57
			return $this->scale( $item, true );
58
		}
59
60
		foreach( $previews as $size => $preview )
61
		{
62
			if( $fsname !== 'fs-mimeicon' && $fs->has( $preview ) )
63
			{
64
				$newPath = $this->path( substr( basename( $preview ), 9 ), $mime, $domain );
65
				$fs->copy( $preview, $newPath );
66
				$previews[$size] = $newPath;
67
			}
68
		}
69
70
		return $item->setPreviews( $previews );
71
	}
72
73
74
	/**
75
	 * Creates a new empty item instance
76
	 *
77
	 * @param array $values Values the item should be initialized with
78
	 * @return \Aimeos\MShop\Media\Item\Iface New media item object
79
	 */
80
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
81
	{
82
		$locale = $this->context()->locale();
83
84
		$values['.languageid'] = $locale->getLanguageId();
85
		$values['media.siteid'] = $values['media.siteid'] ?? $locale->getSiteId();
86
87
		return new \Aimeos\MShop\Media\Item\Standard( 'media.', $values );
88
	}
89
90
91
	/**
92
	 * Removes multiple items.
93
	 *
94
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $items List of item objects or IDs of the items
95
	 * @return \Aimeos\MShop\Media\Manager\Iface Manager object for chaining method calls
96
	 */
97
	public function delete( $items ) : \Aimeos\MShop\Common\Manager\Iface
98
	{
99
		foreach( map( $items ) as $item )
100
		{
101
			if( $item instanceof \Aimeos\MShop\Media\Item\Iface && $item->getFileSystem() === 'fs-media' )
102
			{
103
				try
104
				{
105
					$this->deletePreviews( $item, $item->getPreviews() );
106
					$this->deleteFile( $item->getUrl(), 'fs-media' );
107
				}
108
				catch( \Exception $e )
109
				{
110
					$this->context()->logger()->warning( $e->getMessage() );
111
				}
112
			}
113
		}
114
115
		return parent::delete( $items )->deleteRefItems( $items );
116
	}
117
118
119
	/**
120
	 * Creates a filter object.
121
	 *
122
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
123
	 * @param bool $site TRUE for adding site criteria to limit items by the site of related items
124
	 * @return \Aimeos\Base\Criteria\Iface Returns the filter object
125
	 */
126
	public function filter( ?bool $default = false, bool $site = false ) : \Aimeos\Base\Criteria\Iface
127
	{
128
		$filter = $this->filterBase( 'media', $default );
129
130
		if( $default !== false )
131
		{
132
			if( $langid = $this->context()->locale()->getLanguageId() )
133
			{
134
				$filter->add( $filter->or( [
135
					$filter->compare( '==', 'media.languageid', $langid ),
136
					$filter->compare( '==', 'media.languageid', null ),
137
				] ) );
138
			}
139
		}
140
141
		return $filter;
142
	}
143
144
145
	/**
146
	 * Returns the additional column/search definitions
147
	 *
148
	 * @return array Associative list of column names as keys and items implementing \Aimeos\Base\Criteria\Attribute\Iface
149
	 */
150
	public function getSaveAttributes() : array
151
	{
152
		return $this->createAttributes( [
153
			'media.type' => [
154
				'label' => 'Type',
155
				'internalcode' => 'type',
156
			],
157
			'media.label' => [
158
				'label' => 'Label',
159
				'internalcode' => 'label',
160
			],
161
			'media.domain' => [
162
				'label' => 'Domain',
163
				'internalcode' => 'domain',
164
			],
165
			'media.languageid' => [
166
				'label' => 'Language code',
167
				'internalcode' => 'langid',
168
			],
169
			'media.mimetype' => [
170
				'label' => 'Mime type',
171
				'internalcode' => 'mimetype',
172
			],
173
			'media.url' => [
174
				'label' => 'URL',
175
				'internalcode' => 'link',
176
			],
177
			'media.previews' => [
178
				'label' => 'Preview URLs as JSON encoded string',
179
				'internalcode' => 'preview',
180
				'type' => 'json',
181
			],
182
			'media.filesystem' => [
183
				'label' => 'File sytem name',
184
				'internalcode' => 'fsname',
185
			],
186
			'media.status' => [
187
				'label' => 'Status',
188
				'internalcode' => 'status',
189
				'type' => 'int',
190
			],
191
		] );
192
	}
193
194
195
	/**
196
	 * Returns the attributes that can be used for searching.
197
	 *
198
	 * @param bool $withsub Return also attributes of sub-managers if true
199
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attribute items
200
	 */
201
	public function getSearchAttributes( bool $withsub = true ) : array
202
	{
203
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
204
		$level = $this->context()->config()->get( 'mshop/media/manager/sitemode', $level );
205
206
		return array_replace( parent::getSearchAttributes( $withsub ), $this->createAttributes( [
207
			'media.preview' => [
208
				'label' => 'Preview URLs as JSON encoded string',
209
				'internalcode' => 'preview',
210
				'type' => 'json',
211
			],
212
			'media:has' => array(
213
				'code' => 'media:has()',
214
				'internalcode' => ':site AND :key AND mmedli."id"',
215
				'internaldeps' => ['LEFT JOIN "mshop_media_list" AS mmedli ON ( mmedli."parentid" = mmed."id" )'],
216
				'label' => 'Media has list item, parameter(<domain>[,<list type>[,<reference ID>)]]',
217
				'type' => 'null',
218
				'public' => false,
219
				'function' => function( &$source, array $params ) use ( $level ) {
220
					$keys = [];
221
222
					foreach( (array) ( $params[1] ?? '' ) as $type ) {
223
						foreach( (array) ( $params[2] ?? '' ) as $id ) {
224
							$keys[] = $params[0] . '|' . ( $type ? $type . '|' : '' ) . $id;
225
						}
226
					}
227
228
					$sitestr = $this->siteString( 'mmedli."siteid"', $level );
229
					$keystr = $this->toExpression( 'mmedli."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' );
230
					$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );
231
232
					return $params;
233
				}
234
			),
235
			'media:prop' => array(
236
				'code' => 'media:prop()',
237
				'internalcode' => ':site AND :key AND mmedpr."id"',
238
				'internaldeps' => ['LEFT JOIN "mshop_media_property" AS mmedpr ON ( mmedpr."parentid" = mmed."id" )'],
239
				'label' => 'Media has property item, parameter(<property type>[,<language code>[,<property value>]])',
240
				'type' => 'null',
241
				'public' => false,
242
				'function' => function( &$source, array $params ) use ( $level ) {
243
					$keys = [];
244
					$langs = array_key_exists( 1, $params ) ? ( $params[1] ?? 'null' ) : '';
245
246
					foreach( (array) $langs as $lang ) {
247
						foreach( (array) ( $params[2] ?? '' ) as $val ) {
248
							$keys[] = substr( $params[0] . '|' . ( $lang === null ? 'null|' : ( $lang ? $lang . '|' : '' ) ) . $val, 0, 255 );
249
						}
250
					}
251
252
					$sitestr = $this->siteString( 'mmedpr."siteid"', $level );
253
					$keystr = $this->toExpression( 'mmedpr."key"', $keys, ( $params[2] ?? null ) ? '==' : '=~' );
254
					$source = str_replace( [':site', ':key'], [$sitestr, $keystr], $source );
255
256
					return $params;
257
				}
258
			),
259
		] ) );
260
	}
261
262
263
	/**
264
	 * Saves the dependent items of the item
265
	 *
266
	 * @param \Aimeos\MShop\Common\Item\Iface $item Item object
267
	 * @param bool $fetch True if the new ID should be returned in the item
268
	 * @return \Aimeos\MShop\Common\Item\Iface Updated item
269
	 */
270
	public function saveRefs( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface
271
	{
272
		$this->savePropertyItems( $item, 'media', $fetch );
273
		$this->saveListItems( $item, 'media', $fetch );
274
275
		return $item;
276
	}
277
278
279
	/**
280
	 * Merges the data from the given map and the referenced items
281
	 *
282
	 * @param array $entries Associative list of ID as key and the associative list of property key/value pairs as values
283
	 * @param array $ref List of referenced items to fetch and add to the entries
284
	 * @return array Associative list of ID as key and the updated entries as value
285
	 */
286
	public function searchRefs( array $entries, array $ref ) : array
287
	{
288
		$parentIds = array_keys( $entries );
289
290
		if( $this->hasRef( $ref, 'media/property' ) )
291
		{
292
			$name = 'media/property';
293
			$propTypes = isset( $ref[$name] ) && is_array( $ref[$name] ) ? $ref[$name] : null;
294
295
			foreach( $this->getPropertyItems( $parentIds, 'media', $propTypes ) as $id => $list ) {
296
				$entries[$id]['.propitems'] = $list;
297
			}
298
		}
299
300
		foreach( $this->getListItems( $parentIds, $ref, 'media' ) as $id => $listItem ) {
301
			$entries[$listItem->getParentId()]['.listitems'][$id] = $listItem;
302
		}
303
304
		return $entries;
305
	}
306
307
308
	/**
309
	 * Returns the prefix for the item properties and search keys.
310
	 *
311
	 * @return string Prefix for the item properties and search keys
312
	 */
313
	protected function prefix() : string
314
	{
315
		return 'media.';
316
	}
317
318
319
	/**
320
	 * Rescales the original file to preview files referenced by the media item
321
	 *
322
	 * The height/width configuration for scaling
323
	 * - mshop/media/<files|preview>/maxheight
324
	 * - mshop/media/<files|preview>/maxwidth
325
	 * - mshop/media/<files|preview>/force-size
326
	 *
327
	 * @param \Aimeos\MShop\Media\Item\Iface $item Media item whose files should be scaled
328
	 * @param bool $force True to enforce creating new preview images
329
	 * @return \Aimeos\MShop\Media\Item\Iface Rescaled media item
330
	 */
331
	public function scale( \Aimeos\MShop\Media\Item\Iface $item, bool $force = false ) : \Aimeos\MShop\Media\Item\Iface
332
	{
333
		$mime = $item->getMimeType();
334
335
		if( empty( $url = $item->getUrl() )
336
			|| $item->getFileSystem() === 'fs-mimeicon'
337
			|| strncmp( 'data:', $url, 5 ) === 0
338
			|| strncmp( 'image/svg', $mime, 9 ) === 0
339
			|| strncmp( 'image/', $mime, 6 ) !== 0
340
		) {
341
			return $item;
342
		}
343
344
		$fs = $this->context()->fs( $item->getFileSystem() );
345
		$is = ( $fs instanceof \Aimeos\Base\Filesystem\MetaIface ? true : false );
346
347
		if( !$force
348
			&& !empty( $item->getPreviews() )
349
			&& preg_match( '#^[a-zA-Z]{2,6}://#', $url ) !== 1
350
			&& ( $is && date( 'Y-m-d H:i:s', $fs->time( $url ) ) < $item->getTimeModified() || $fs->has( $url ) )
351
		) {
352
			return $item;
353
		}
354
355
		$domain = $item->getDomain() ?: '-';
356
		$sizes = $this->sizes( $domain, $item->getType() );
357
		$image = $this->image( $url );
358
		$quality = $this->quality();
359
		$old = $item->getPreviews();
360
		$previews = [];
361
362
		foreach( $this->createPreviews( $image, $sizes ) as $width => $image )
363
		{
364
			$path = $old[$width] ?? $this->path( $url, 'image/webp', $domain );
365
			$fs->write( $path, (string) $image->toWebp( $quality ) );
366
367
			$previews[$width] = $path;
368
			unset( $old[$width] );
369
		}
370
371
		$item = $this->deletePreviews( $item, $old )->setPreviews( $previews );
372
373
		$this->call( 'scaled', $item, $image );
374
375
		return $item;
376
	}
377
378
379
	/**
380
	 * Returns the preview image sizes for scaling the images.
381
	 *
382
	 * @param string $domain Domain of the image
383
	 * @param string $type Type of the image
384
	 * @return array List of image sizes with "maxwidth", "maxheight" and "force-size" properties
385
	 */
386
	protected function sizes( string $domain, string $type ) : array
387
	{
388
		$config = $this->context()->config();
389
390
		/** mshop/media/manager/previews/common
391
		 * Scaling options for preview images
392
		 *
393
		 * For responsive images, several preview images of different sizes are
394
		 * generated. This setting controls how many preview images are generated,
395
		 * what's their maximum width and height and if the given width/height is
396
		 * enforced by cropping images that doesn't fit.
397
		 *
398
		 * The setting must consist of a list image size definitions like:
399
		 *
400
		 *  [
401
		 *    ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => 2],
402
		 *    ['maxwidth' => 720, 'maxheight' => 960, 'force-size' => 1],
403
		 *    ['maxwidth' => 2160, 'maxheight' => 2880, 'force-size' => 0],
404
		 *  ]
405
		 *
406
		 * "maxwidth" sets the maximum allowed width of the image whereas
407
		 * "maxheight" does the same for the maximum allowed height. If both
408
		 * values are given, the image is scaled proportionally so it fits into
409
		 * the box defined by both values.
410
		 *
411
		 * In case the image has different proportions than the specified ones
412
		 * and "force-size" is "0", the image is resized to fit entirely into
413
		 * the specified box. One side of the image will be shorter than it
414
		 * would be possible by the specified box.
415
		 *
416
		 * If "force-size" is "1", scaled images that doesn't fit into the
417
		 * given maximum width/height are centered and then filled with the
418
		 * background color.
419
		 *
420
		 * The value of "2" will center the image while the given maxwidth and
421
		 * maxheight are fully covered and crop the parts of the image which
422
		 * are outside the box created by maxwidth and maxheight.
423
		 *
424
		 * By default, images aren't padded or cropped, only scaled.
425
		 *
426
		 * The values for "maxwidth" and "maxheight" can also be null or not
427
		 * used. In that case, the width or height or both is unbound. If none
428
		 * of the values are given, the image won't be scaled at all. If only
429
		 * one value is set, the image will be scaled exactly to the given width
430
		 * or height and the other side is scaled proportionally.
431
		 *
432
		 * You can also define different preview sizes for different domains (e.g.
433
		 * for catalog images) and for different types (e.g. catalog stage images).
434
		 * Use configuration settings like
435
		 *
436
		 *  mshop/media/manager/previews/previews/<domain>/
437
		 *  mshop/media/manager/previews/previews/<domain>/<type>/
438
		 *
439
		 * for example:
440
		 *
441
		 *  mshop/media/manager/previews/catalog/previews => [
442
		 *    ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => true],
443
		 *  ]
444
		 *  mshop/media/manager/previews/catalog/previews => [
445
		 *    ['maxwidth' => 400, 'maxheight' => 300, 'force-size' => false]
446
		 *  ]
447
		 *  mshop/media/manager/previews/catalog/stage/previews => [
448
		 *    ['maxwidth' => 360, 'maxheight' => 320, 'force-size' => true],
449
		 *    ['maxwidth' => 720, 'maxheight' => 480, 'force-size' => true]
450
		 *  ]
451
		 *
452
		 * These settings will create two preview images for catalog stage images,
453
		 * one with a different size for all other catalog images and all images
454
		 * from other domains will be sized to 240x320px. The available domains
455
		 * which can have images are:
456
		 *
457
		 * * attribute
458
		 * * catalog
459
		 * * product
460
		 * * service
461
		 * * supplier
462
		 *
463
		 * There are a few image types included per domain ("default" is always
464
		 * available). You can also add your own types in the admin backend and
465
		 * extend the frontend to display them where you need them.
466
		 *
467
		 * @param array List of image size definitions
468
		 * @since 2019.07
469
		 */
470
		$sizes = $config->get( 'mshop/media/manager/previews/common', [] );
471
		$sizes = $config->get( 'mshop/media/manager/previews/' . $domain, $sizes );
472
		$sizes = $config->get( 'mshop/media/manager/previews/' . $domain . '/' . $type, $sizes );
473
474
		return $sizes;
475
	}
476
477
478
	/**
479
	 * Stores the uploaded file and returns the updated item
480
	 *
481
	 * @param \Aimeos\MShop\Media\Item\Iface $item Media item for storing the file meta data, "domain" must be set
482
	 * @param \Psr\Http\Message\UploadedFileInterface|null $file Uploaded file object
483
	 * @param \Psr\Http\Message\UploadedFileInterface|null $preview Uploaded preview image
484
	 * @return \Aimeos\MShop\Media\Item\Iface Updated media item including file and preview paths
485
	 */
486
	public function upload( \Aimeos\MShop\Media\Item\Iface $item, ?UploadedFileInterface $file, UploadedFileInterface $preview = null ) : \Aimeos\MShop\Media\Item\Iface
487
	{
488
		$domain = $item->getDomain() ?: '-';
489
		$fsname = $item->getFileSystem() ?: 'fs-media';
490
		$fs = $this->context()->fs( $fsname );
491
492
		if( $file && $file->getError() !== UPLOAD_ERR_NO_FILE && $this->isAllowed( $mime = $this->mimetype( $file ) ) )
493
		{
494
			try
495
			{
496
				$oldpath = $item->getUrl();
497
498
				$path = $this->path( $file->getClientFilename(), $mime, $domain );
499
				$fs->write( $path, $this->sanitize( $file->getStream()->getContents(), $mime ) );
500
501
				$item->setLabel( $file->getClientFilename() )
502
					->setMimetype( $mime )
503
					->setUrl( $path );
504
505
				if( !$preview ) {
506
					$this->scale( $item, true );
507
				}
508
509
				if( !empty( $oldpath ) && $fs->has( $oldpath ) ) {
510
					$fs->rm( $oldpath );
511
				}
512
			}
513
			catch( \Exception $e )
514
			{
515
				if( !empty( $path ) && $fs->has( $path ) ) {
516
					$fs->rm( $path );
517
				}
518
519
				throw $e;
520
			}
521
		}
522
523
		if( $preview && $preview->getError() !== UPLOAD_ERR_NO_FILE && $this->isAllowed( $mime = $this->mimetype( $preview ) ) )
524
		{
525
			$path = $this->path( $preview->getClientFilename(), $mime, $domain );
526
			$fs->write( $path, $this->sanitize( $preview->getStream()->getContents(), $mime ) );
527
528
			$item->setPreview( $path );
529
		}
530
531
		return $item;
532
	}
533
534
535
	/** mshop/media/manager/resource
536
	 * Name of the database connection resource to use
537
	 *
538
	 * You can configure a different database connection for each data domain
539
	 * and if no such connection name exists, the "db" connection will be used.
540
	 * It's also possible to use the same database connection for different
541
	 * data domains by configuring the same connection name using this setting.
542
	 *
543
	 * @param string Database connection name
544
	 * @since 2023.04
545
	 */
546
547
	/** mshop/media/manager/name
548
	 * Class name of the used media manager implementation
549
	 *
550
	 * Each default manager can be replace by an alternative imlementation.
551
	 * To use this implementation, you have to set the last part of the class
552
	 * name as configuration value so the manager factory knows which class it
553
	 * has to instantiate.
554
	 *
555
	 * For example, if the name of the default class is
556
	 *
557
	 *  \Aimeos\MShop\Media\Manager\Standard
558
	 *
559
	 * and you want to replace it with your own version named
560
	 *
561
	 *  \Aimeos\MShop\Media\Manager\Mymanager
562
	 *
563
	 * then you have to set the this configuration option:
564
	 *
565
	 *  mshop/media/manager/name = Mymanager
566
	 *
567
	 * The value is the last part of your own class name and it's case sensitive,
568
	 * so take care that the configuration value is exactly named like the last
569
	 * part of the class name.
570
	 *
571
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
572
	 * characters are possible! You should always start the last part of the class
573
	 * name with an upper case character and continue only with lower case characters
574
	 * or numbers. Avoid chamel case names like "MyManager"!
575
	 *
576
	 * @param string Last part of the class name
577
	 * @since 2015.10
578
	 */
579
580
	/** mshop/media/manager/decorators/excludes
581
	 * Excludes decorators added by the "common" option from the media manager
582
	 *
583
	 * Decorators extend the functionality of a class by adding new aspects
584
	 * (e.g. log what is currently done), executing the methods of the underlying
585
	 * class only in certain conditions (e.g. only for logged in users) or
586
	 * modify what is returned to the caller.
587
	 *
588
	 * This option allows you to remove a decorator added via
589
	 * "mshop/common/manager/decorators/default" before they are wrapped
590
	 * around the media manager.
591
	 *
592
	 *  mshop/media/manager/decorators/excludes = array( 'decorator1' )
593
	 *
594
	 * This would remove the decorator named "decorator1" from the list of
595
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
596
	 * "mshop/common/manager/decorators/default" for the media manager.
597
	 *
598
	 * @param array List of decorator names
599
	 * @since 2015.10
600
	 * @see mshop/common/manager/decorators/default
601
	 * @see mshop/media/manager/decorators/global
602
	 * @see mshop/media/manager/decorators/local
603
	 */
604
605
	/** mshop/media/manager/decorators/global
606
	 * Adds a list of globally available decorators only to the media manager
607
	 *
608
	 * Decorators extend the functionality of a class by adding new aspects
609
	 * (e.g. log what is currently done), executing the methods of the underlying
610
	 * class only in certain conditions (e.g. only for logged in users) or
611
	 * modify what is returned to the caller.
612
	 *
613
	 * This option allows you to wrap global decorators
614
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the media manager.
615
	 *
616
	 *  mshop/media/manager/decorators/global = array( 'decorator1' )
617
	 *
618
	 * This would add the decorator named "decorator1" defined by
619
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the media
620
	 * manager.
621
	 *
622
	 * @param array List of decorator names
623
	 * @since 2015.10
624
	 * @see mshop/common/manager/decorators/default
625
	 * @see mshop/media/manager/decorators/excludes
626
	 * @see mshop/media/manager/decorators/local
627
	 */
628
629
	/** mshop/media/manager/decorators/local
630
	 * Adds a list of local decorators only to the media manager
631
	 *
632
	 * Decorators extend the functionality of a class by adding new aspects
633
	 * (e.g. log what is currently done), executing the methods of the underlying
634
	 * class only in certain conditions (e.g. only for logged in users) or
635
	 * modify what is returned to the caller.
636
	 *
637
	 * This option allows you to wrap local decorators
638
	 * ("\Aimeos\MShop\Media\Manager\Decorator\*") around the media manager.
639
	 *
640
	 *  mshop/media/manager/decorators/local = array( 'decorator2' )
641
	 *
642
	 * This would add the decorator named "decorator2" defined by
643
	 * "\Aimeos\MShop\Media\Manager\Decorator\Decorator2" only to the media
644
	 * manager.
645
	 *
646
	 * @param array List of decorator names
647
	 * @since 2015.10
648
	 * @see mshop/common/manager/decorators/default
649
	 * @see mshop/media/manager/decorators/excludes
650
	 * @see mshop/media/manager/decorators/global
651
	 */
652
653
	/** mshop/media/manager/submanagers
654
	 * List of manager names that can be instantiated by the media manager
655
	 *
656
	 * Managers provide a generic interface to the underlying storage.
657
	 * Each manager has or can have sub-managers caring about particular
658
	 * aspects. Each of these sub-managers can be instantiated by its
659
	 * parent manager using the getSubManager() method.
660
	 *
661
	 * The search keys from sub-managers can be normally used in the
662
	 * manager as well. It allows you to search for items of the manager
663
	 * using the search keys of the sub-managers to further limit the
664
	 * retrieved list of items.
665
	 *
666
	 * @param array List of sub-manager names
667
	 * @since 2015.10
668
	 */
669
670
	/** mshop/media/manager/delete/mysql
671
	 * Deletes the items matched by the given IDs from the database
672
	 *
673
	 * @see mshop/media/manager/delete/ansi
674
	 */
675
676
	/** mshop/media/manager/delete/ansi
677
	 * Deletes the items matched by the given IDs from the database
678
	 *
679
	 * Removes the records specified by the given IDs from the media database.
680
	 * The records must be from the site that is configured via the
681
	 * context item.
682
	 *
683
	 * The ":cond" placeholder is replaced by the name of the ID column and
684
	 * the given ID or list of IDs while the site ID is bound to the question
685
	 * mark.
686
	 *
687
	 * The SQL statement should conform to the ANSI standard to be
688
	 * compatible with most relational database systems. This also
689
	 * includes using double quotes for table and column names.
690
	 *
691
	 * @param string SQL statement for deleting items
692
	 * @since 2015.10
693
	 * @see mshop/media/manager/insert/ansi
694
	 * @see mshop/media/manager/update/ansi
695
	 * @see mshop/media/manager/newid/ansi
696
	 * @see mshop/media/manager/search/ansi
697
	 * @see mshop/media/manager/count/ansi
698
	 */
699
700
	/** mshop/media/manager/insert/mysql
701
	 * Inserts a new media record into the database table
702
	 *
703
	 * @see mshop/media/manager/insert/ansi
704
	 */
705
706
	/** mshop/media/manager/insert/ansi
707
	 * Inserts a new media record into the database table
708
	 *
709
	 * Items with no ID yet (i.e. the ID is NULL) will be created in
710
	 * the database and the newly created ID retrieved afterwards
711
	 * using the "newid" SQL statement.
712
	 *
713
	 * The SQL statement must be a string suitable for being used as
714
	 * prepared statement. It must include question marks for binding
715
	 * the values from the media item to the statement before they are
716
	 * sent to the database server. The number of question marks must
717
	 * be the same as the number of columns listed in the INSERT
718
	 * statement. The order of the columns must correspond to the
719
	 * order in the save() method, so the correct values are
720
	 * bound to the columns.
721
	 *
722
	 * The SQL statement should conform to the ANSI standard to be
723
	 * compatible with most relational database systems. This also
724
	 * includes using double quotes for table and column names.
725
	 *
726
	 * @param string SQL statement for inserting records
727
	 * @since 2015.10
728
	 * @see mshop/media/manager/update/ansi
729
	 * @see mshop/media/manager/newid/ansi
730
	 * @see mshop/media/manager/delete/ansi
731
	 * @see mshop/media/manager/search/ansi
732
	 * @see mshop/media/manager/count/ansi
733
	 */
734
735
	/** mshop/media/manager/update/mysql
736
	 * Updates an existing media record in the database
737
	 *
738
	 * @see mshop/media/manager/update/ansi
739
	 */
740
741
	/** mshop/media/manager/update/ansi
742
	 * Updates an existing media record in the database
743
	 *
744
	 * Items which already have an ID (i.e. the ID is not NULL) will
745
	 * be updated in the database.
746
	 *
747
	 * The SQL statement must be a string suitable for being used as
748
	 * prepared statement. It must include question marks for binding
749
	 * the values from the media item to the statement before they are
750
	 * sent to the database server. The order of the columns must
751
	 * correspond to the order in the save() method, so the
752
	 * correct values are bound to the columns.
753
	 *
754
	 * The SQL statement should conform to the ANSI standard to be
755
	 * compatible with most relational database systems. This also
756
	 * includes using double quotes for table and column names.
757
	 *
758
	 * @param string SQL statement for updating records
759
	 * @since 2015.10
760
	 * @see mshop/media/manager/insert/ansi
761
	 * @see mshop/media/manager/newid/ansi
762
	 * @see mshop/media/manager/delete/ansi
763
	 * @see mshop/media/manager/search/ansi
764
	 * @see mshop/media/manager/count/ansi
765
	 */
766
767
	/** mshop/media/manager/newid/mysql
768
	 * Retrieves the ID generated by the database when inserting a new record
769
	 *
770
	 * @see mshop/media/manager/newid/ansi
771
	 */
772
773
	/** mshop/media/manager/newid/ansi
774
	 * Retrieves the ID generated by the database when inserting a new record
775
	 *
776
	 * As soon as a new record is inserted into the database table,
777
	 * the database server generates a new and unique identifier for
778
	 * that record. This ID can be used for retrieving, updating and
779
	 * deleting that specific record from the table again.
780
	 *
781
	 * For MySQL:
782
	 *  SELECT LAST_INSERT_ID()
783
	 * For PostgreSQL:
784
	 *  SELECT currval('seq_mmed_id')
785
	 * For SQL Server:
786
	 *  SELECT SCOPE_IDENTITY()
787
	 * For Oracle:
788
	 *  SELECT "seq_mmed_id".CURRVAL FROM DUAL
789
	 *
790
	 * There's no way to retrive the new ID by a SQL statements that
791
	 * fits for most database servers as they implement their own
792
	 * specific way.
793
	 *
794
	 * @param string SQL statement for retrieving the last inserted record ID
795
	 * @since 2015.10
796
	 * @see mshop/media/manager/insert/ansi
797
	 * @see mshop/media/manager/update/ansi
798
	 * @see mshop/media/manager/delete/ansi
799
	 * @see mshop/media/manager/search/ansi
800
	 * @see mshop/media/manager/count/ansi
801
	 */
802
803
	/** mshop/media/manager/sitemode
804
	 * Mode how items from levels below or above in the site tree are handled
805
	 *
806
	 * By default, only items from the current site are fetched from the
807
	 * storage. If the ai-sites extension is installed, you can create a
808
	 * tree of sites. Then, this setting allows you to define for the
809
	 * whole media domain if items from parent sites are inherited,
810
	 * sites from child sites are aggregated or both.
811
	 *
812
	 * Available constants for the site mode are:
813
	 * * 0 = only items from the current site
814
	 * * 1 = inherit items from parent sites
815
	 * * 2 = aggregate items from child sites
816
	 * * 3 = inherit and aggregate items at the same time
817
	 *
818
	 * You also need to set the mode in the locale manager
819
	 * (mshop/locale/manager/sitelevel) to one of the constants.
820
	 * If you set it to the same value, it will work as described but you
821
	 * can also use different modes. For example, if inheritance and
822
	 * aggregation is configured the locale manager but only inheritance
823
	 * in the domain manager because aggregating items makes no sense in
824
	 * this domain, then items wil be only inherited. Thus, you have full
825
	 * control over inheritance and aggregation in each domain.
826
	 *
827
	 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
828
	 * @since 2018.01
829
	 * @see mshop/locale/manager/sitelevel
830
	 */
831
832
	/** mshop/media/manager/search/mysql
833
	 * Retrieves the records matched by the given criteria in the database
834
	 *
835
	 * @see mshop/media/manager/search/ansi
836
	 */
837
838
	/** mshop/media/manager/search/ansi
839
	 * Retrieves the records matched by the given criteria in the database
840
	 *
841
	 * Fetches the records matched by the given criteria from the media
842
	 * database. The records must be from one of the sites that are
843
	 * configured via the context item. If the current site is part of
844
	 * a tree of sites, the SELECT statement can retrieve all records
845
	 * from the current site and the complete sub-tree of sites.
846
	 *
847
	 * As the records can normally be limited by criteria from sub-managers,
848
	 * their tables must be joined in the SQL context. This is done by
849
	 * using the "internaldeps" property from the definition of the ID
850
	 * column of the sub-managers. These internal dependencies specify
851
	 * the JOIN between the tables and the used columns for joining. The
852
	 * ":joins" placeholder is then replaced by the JOIN strings from
853
	 * the sub-managers.
854
	 *
855
	 * To limit the records matched, conditions can be added to the given
856
	 * criteria object. It can contain comparisons like column names that
857
	 * must match specific values which can be combined by AND, OR or NOT
858
	 * operators. The resulting string of SQL conditions replaces the
859
	 * ":cond" placeholder before the statement is sent to the database
860
	 * server.
861
	 *
862
	 * If the records that are retrieved should be ordered by one or more
863
	 * columns, the generated string of column / sort direction pairs
864
	 * replaces the ":order" placeholder. Columns of
865
	 * sub-managers can also be used for ordering the result set but then
866
	 * no index can be used.
867
	 *
868
	 * The number of returned records can be limited and can start at any
869
	 * number between the begining and the end of the result set. For that
870
	 * the ":size" and ":start" placeholders are replaced by the
871
	 * corresponding values from the criteria object. The default values
872
	 * are 0 for the start and 100 for the size value.
873
	 *
874
	 * The SQL statement should conform to the ANSI standard to be
875
	 * compatible with most relational database systems. This also
876
	 * includes using double quotes for table and column names.
877
	 *
878
	 * @param string SQL statement for searching items
879
	 * @since 2015.10
880
	 * @see mshop/media/manager/insert/ansi
881
	 * @see mshop/media/manager/update/ansi
882
	 * @see mshop/media/manager/newid/ansi
883
	 * @see mshop/media/manager/delete/ansi
884
	 * @see mshop/media/manager/count/ansi
885
	 */
886
887
	/** mshop/media/manager/count/mysql
888
	 * Counts the number of records matched by the given criteria in the database
889
	 *
890
	 * @see mshop/media/manager/count/ansi
891
	 */
892
893
	/** mshop/media/manager/count/ansi
894
	 * Counts the number of records matched by the given criteria in the database
895
	 *
896
	 * Counts all records matched by the given criteria from the media
897
	 * database. The records must be from one of the sites that are
898
	 * configured via the context item. If the current site is part of
899
	 * a tree of sites, the statement can count all records from the
900
	 * current site and the complete sub-tree of sites.
901
	 *
902
	 * As the records can normally be limited by criteria from sub-managers,
903
	 * their tables must be joined in the SQL context. This is done by
904
	 * using the "internaldeps" property from the definition of the ID
905
	 * column of the sub-managers. These internal dependencies specify
906
	 * the JOIN between the tables and the used columns for joining. The
907
	 * ":joins" placeholder is then replaced by the JOIN strings from
908
	 * the sub-managers.
909
	 *
910
	 * To limit the records matched, conditions can be added to the given
911
	 * criteria object. It can contain comparisons like column names that
912
	 * must match specific values which can be combined by AND, OR or NOT
913
	 * operators. The resulting string of SQL conditions replaces the
914
	 * ":cond" placeholder before the statement is sent to the database
915
	 * server.
916
	 *
917
	 * Both, the strings for ":joins" and for ":cond" are the same as for
918
	 * the "search" SQL statement.
919
	 *
920
	 * Contrary to the "search" statement, it doesn't return any records
921
	 * but instead the number of records that have been found. As counting
922
	 * thousands of records can be a long running task, the maximum number
923
	 * of counted records is limited for performance reasons.
924
	 *
925
	 * The SQL statement should conform to the ANSI standard to be
926
	 * compatible with most relational database systems. This also
927
	 * includes using double quotes for table and column names.
928
	 *
929
	 * @param string SQL statement for counting items
930
	 * @since 2015.10
931
	 * @see mshop/media/manager/insert/ansi
932
	 * @see mshop/media/manager/update/ansi
933
	 * @see mshop/media/manager/newid/ansi
934
	 * @see mshop/media/manager/delete/ansi
935
	 * @see mshop/media/manager/search/ansi
936
	 */
937
}
938