Passed
Push — master ( 640ca2...01f5f1 )
by Aimeos
04:18
created

Standard::createItemBase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
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 );
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
	 * Fetches the rows from the database statement and returns the list of items.
265
	 *
266
	 * @param \Aimeos\Base\DB\Result\Iface $stmt Database statement object
267
	 * @param array $ref List of domains whose items should be fetched too
268
	 * @param string $prefix Prefix for the property names
269
	 * @param array $attrs List of attributes that should be decoded
270
	 * @return \Aimeos\Map List of items implementing \Aimeos\MShop\Common\Item\Iface
271
	 */
272
	protected function fetch( \Aimeos\Base\DB\Result\Iface $results, array $ref, string $prefix = '', array $attrs = [] ) : \Aimeos\Map
273
	{
274
		$map = $items = $parentIds = $propItems = [];
275
276
		while( $row = $results->fetch() )
277
		{
278
			foreach( $attrs as $code => $attr ) {
279
				$row[$code] = json_decode( $row[$code], true );
280
			}
281
282
			$map[$row['media.id']] = $row;
283
			$parentIds[] = $row['media.id'];
284
		}
285
286
		if( $this->hasRef( $ref, 'media/property' ) )
287
		{
288
			$name = 'media/property';
289
			$propTypes = isset( $ref[$name] ) && is_array( $ref[$name] ) ? $ref[$name] : null;
290
291
			$propItems = $this->getPropertyItems( $parentIds, 'media', $propTypes );
292
		}
293
294
		$listItems = map( $this->getListItems( $parentIds, $ref, 'media' ) )->groupBy( 'media.lists.parentid' );
295
296
		foreach( $map as $id => $row )
297
		{
298
			$row['.listitems'] = $listItems[$id] ?? [];
299
			$row['.propitems'] = $propItems[$id] ?? [];
300
301
			if( $item = $this->applyFilter( $this->create( $row ) ) ) {
302
				$items[$id] = $item;
303
			}
304
		}
305
306
		return map( $items );
307
	}
308
309
310
	/**
311
	 * Returns the prefix for the item properties and search keys.
312
	 *
313
	 * @return string Prefix for the item properties and search keys
314
	 */
315
	protected function prefix() : string
316
	{
317
		return 'media.';
318
	}
319
320
321
	/**
322
	 * Saves the dependent items of the item
323
	 *
324
	 * @param \Aimeos\MShop\Common\Item\Iface $item Item object
325
	 * @param bool $fetch True if the new ID should be returned in the item
326
	 * @return \Aimeos\MShop\Common\Item\Iface Updated item
327
	 */
328
	protected function saveDeps( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch = true ) : \Aimeos\MShop\Common\Item\Iface
329
	{
330
		$item = $this->savePropertyItems( $item, 'media', $fetch );
331
		return $this->saveListItems( $item, 'media', $fetch );
0 ignored issues
show
Bug introduced by
$item of type Aimeos\MShop\Common\Item\PropertyRef\Iface is incompatible with the type Aimeos\MShop\Common\Item\ListsRef\Iface expected by parameter $item of Aimeos\MShop\Media\Manag...andard::saveListItems(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

331
		return $this->saveListItems( /** @scrutinizer ignore-type */ $item, 'media', $fetch );
Loading history...
332
	}
333
334
335
	/**
336
	 * Rescales the original file to preview files referenced by the media item
337
	 *
338
	 * The height/width configuration for scaling
339
	 * - mshop/media/<files|preview>/maxheight
340
	 * - mshop/media/<files|preview>/maxwidth
341
	 * - mshop/media/<files|preview>/force-size
342
	 *
343
	 * @param \Aimeos\MShop\Media\Item\Iface $item Media item whose files should be scaled
344
	 * @param bool $force True to enforce creating new preview images
345
	 * @return \Aimeos\MShop\Media\Item\Iface Rescaled media item
346
	 */
347
	public function scale( \Aimeos\MShop\Media\Item\Iface $item, bool $force = false ) : \Aimeos\MShop\Media\Item\Iface
348
	{
349
		$mime = $item->getMimeType();
350
351
		if( empty( $url = $item->getUrl() )
352
			|| $item->getFileSystem() === 'fs-mimeicon'
353
			|| strncmp( 'data:', $url, 5 ) === 0
354
			|| strncmp( 'image/svg', $mime, 9 ) === 0
355
			|| strncmp( 'image/', $mime, 6 ) !== 0
356
		) {
357
			return $item;
358
		}
359
360
		$fs = $this->context()->fs( $item->getFileSystem() );
361
		$is = ( $fs instanceof \Aimeos\Base\Filesystem\MetaIface ? true : false );
362
363
		if( !$force
364
			&& !empty( $item->getPreviews() )
365
			&& preg_match( '#^[a-zA-Z]{2,6}://#', $url ) !== 1
366
			&& ( $is && date( 'Y-m-d H:i:s', $fs->time( $url ) ) < $item->getTimeModified() || $fs->has( $url ) )
367
		) {
368
			return $item;
369
		}
370
371
		$domain = $item->getDomain() ?: '-';
372
		$sizes = $this->sizes( $domain, $item->getType() );
373
		$image = $this->image( $url );
374
		$quality = $this->quality();
375
		$old = $item->getPreviews();
376
		$previews = [];
377
378
		foreach( $this->createPreviews( $image, $sizes ) as $width => $image )
379
		{
380
			$path = $old[$width] ?? $this->path( $url, 'image/webp', $domain );
381
			$fs->write( $path, (string) $image->toWebp( $quality ) );
382
383
			$previews[$width] = $path;
384
			unset( $old[$width] );
385
		}
386
387
		$item = $this->deletePreviews( $item, $old )->setPreviews( $previews );
388
389
		$this->call( 'scaled', $item, $image );
390
391
		return $item;
392
	}
393
394
395
	/**
396
	 * Returns the preview image sizes for scaling the images.
397
	 *
398
	 * @param string $domain Domain of the image
399
	 * @param string $type Type of the image
400
	 * @return array List of image sizes with "maxwidth", "maxheight" and "force-size" properties
401
	 */
402
	protected function sizes( string $domain, string $type ) : array
403
	{
404
		$config = $this->context()->config();
405
406
		/** mshop/media/manager/previews/common
407
		 * Scaling options for preview images
408
		 *
409
		 * For responsive images, several preview images of different sizes are
410
		 * generated. This setting controls how many preview images are generated,
411
		 * what's their maximum width and height and if the given width/height is
412
		 * enforced by cropping images that doesn't fit.
413
		 *
414
		 * The setting must consist of a list image size definitions like:
415
		 *
416
		 *  [
417
		 *    ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => 2],
418
		 *    ['maxwidth' => 720, 'maxheight' => 960, 'force-size' => 1],
419
		 *    ['maxwidth' => 2160, 'maxheight' => 2880, 'force-size' => 0],
420
		 *  ]
421
		 *
422
		 * "maxwidth" sets the maximum allowed width of the image whereas
423
		 * "maxheight" does the same for the maximum allowed height. If both
424
		 * values are given, the image is scaled proportionally so it fits into
425
		 * the box defined by both values.
426
		 *
427
		 * In case the image has different proportions than the specified ones
428
		 * and "force-size" is "0", the image is resized to fit entirely into
429
		 * the specified box. One side of the image will be shorter than it
430
		 * would be possible by the specified box.
431
		 *
432
		 * If "force-size" is "1", scaled images that doesn't fit into the
433
		 * given maximum width/height are centered and then filled with the
434
		 * background color.
435
		 *
436
		 * The value of "2" will center the image while the given maxwidth and
437
		 * maxheight are fully covered and crop the parts of the image which
438
		 * are outside the box created by maxwidth and maxheight.
439
		 *
440
		 * By default, images aren't padded or cropped, only scaled.
441
		 *
442
		 * The values for "maxwidth" and "maxheight" can also be null or not
443
		 * used. In that case, the width or height or both is unbound. If none
444
		 * of the values are given, the image won't be scaled at all. If only
445
		 * one value is set, the image will be scaled exactly to the given width
446
		 * or height and the other side is scaled proportionally.
447
		 *
448
		 * You can also define different preview sizes for different domains (e.g.
449
		 * for catalog images) and for different types (e.g. catalog stage images).
450
		 * Use configuration settings like
451
		 *
452
		 *  mshop/media/manager/previews/previews/<domain>/
453
		 *  mshop/media/manager/previews/previews/<domain>/<type>/
454
		 *
455
		 * for example:
456
		 *
457
		 *  mshop/media/manager/previews/catalog/previews => [
458
		 *    ['maxwidth' => 240, 'maxheight' => 320, 'force-size' => true],
459
		 *  ]
460
		 *  mshop/media/manager/previews/catalog/previews => [
461
		 *    ['maxwidth' => 400, 'maxheight' => 300, 'force-size' => false]
462
		 *  ]
463
		 *  mshop/media/manager/previews/catalog/stage/previews => [
464
		 *    ['maxwidth' => 360, 'maxheight' => 320, 'force-size' => true],
465
		 *    ['maxwidth' => 720, 'maxheight' => 480, 'force-size' => true]
466
		 *  ]
467
		 *
468
		 * These settings will create two preview images for catalog stage images,
469
		 * one with a different size for all other catalog images and all images
470
		 * from other domains will be sized to 240x320px. The available domains
471
		 * which can have images are:
472
		 *
473
		 * * attribute
474
		 * * catalog
475
		 * * product
476
		 * * service
477
		 * * supplier
478
		 *
479
		 * There are a few image types included per domain ("default" is always
480
		 * available). You can also add your own types in the admin backend and
481
		 * extend the frontend to display them where you need them.
482
		 *
483
		 * @param array List of image size definitions
484
		 * @since 2019.07
485
		 */
486
		$sizes = $config->get( 'mshop/media/manager/previews/common', [] );
487
		$sizes = $config->get( 'mshop/media/manager/previews/' . $domain, $sizes );
488
		$sizes = $config->get( 'mshop/media/manager/previews/' . $domain . '/' . $type, $sizes );
489
490
		return $sizes;
491
	}
492
493
494
	/**
495
	 * Stores the uploaded file and returns the updated item
496
	 *
497
	 * @param \Aimeos\MShop\Media\Item\Iface $item Media item for storing the file meta data, "domain" must be set
498
	 * @param \Psr\Http\Message\UploadedFileInterface|null $file Uploaded file object
499
	 * @param \Psr\Http\Message\UploadedFileInterface|null $preview Uploaded preview image
500
	 * @return \Aimeos\MShop\Media\Item\Iface Updated media item including file and preview paths
501
	 */
502
	public function upload( \Aimeos\MShop\Media\Item\Iface $item, ?UploadedFileInterface $file, UploadedFileInterface $preview = null ) : \Aimeos\MShop\Media\Item\Iface
503
	{
504
		$domain = $item->getDomain() ?: '-';
505
		$fsname = $item->getFileSystem() ?: 'fs-media';
506
		$fs = $this->context()->fs( $fsname );
507
508
		if( $file && $file->getError() !== UPLOAD_ERR_NO_FILE && $this->isAllowed( $mime = $this->mimetype( $file ) ) )
509
		{
510
			try
511
			{
512
				$oldpath = $item->getUrl();
513
514
				$path = $this->path( $file->getClientFilename(), $mime, $domain );
515
				$fs->write( $path, $this->sanitize( $file->getStream()->getContents(), $mime ) );
516
517
				$item->setLabel( $file->getClientFilename() )
518
					->setMimetype( $mime )
519
					->setUrl( $path );
520
521
				if( !$preview ) {
522
					$this->scale( $item, true );
523
				}
524
525
				if( !empty( $oldpath ) && $fs->has( $oldpath ) ) {
526
					$fs->rm( $oldpath );
527
				}
528
			}
529
			catch( \Exception $e )
530
			{
531
				if( !empty( $path ) && $fs->has( $path ) ) {
532
					$fs->rm( $path );
533
				}
534
535
				throw $e;
536
			}
537
		}
538
539
		if( $preview && $preview->getError() !== UPLOAD_ERR_NO_FILE && $this->isAllowed( $mime = $this->mimetype( $preview ) ) )
540
		{
541
			$path = $this->path( $preview->getClientFilename(), $mime, $domain );
542
			$fs->write( $path, $this->sanitize( $preview->getStream()->getContents(), $mime ) );
543
544
			$item->setPreview( $path );
545
		}
546
547
		return $item;
548
	}
549
550
551
	/** mshop/media/manager/resource
552
	 * Name of the database connection resource to use
553
	 *
554
	 * You can configure a different database connection for each data domain
555
	 * and if no such connection name exists, the "db" connection will be used.
556
	 * It's also possible to use the same database connection for different
557
	 * data domains by configuring the same connection name using this setting.
558
	 *
559
	 * @param string Database connection name
560
	 * @since 2023.04
561
	 */
562
563
	/** mshop/media/manager/name
564
	 * Class name of the used media manager implementation
565
	 *
566
	 * Each default manager can be replace by an alternative imlementation.
567
	 * To use this implementation, you have to set the last part of the class
568
	 * name as configuration value so the manager factory knows which class it
569
	 * has to instantiate.
570
	 *
571
	 * For example, if the name of the default class is
572
	 *
573
	 *  \Aimeos\MShop\Media\Manager\Standard
574
	 *
575
	 * and you want to replace it with your own version named
576
	 *
577
	 *  \Aimeos\MShop\Media\Manager\Mymanager
578
	 *
579
	 * then you have to set the this configuration option:
580
	 *
581
	 *  mshop/media/manager/name = Mymanager
582
	 *
583
	 * The value is the last part of your own class name and it's case sensitive,
584
	 * so take care that the configuration value is exactly named like the last
585
	 * part of the class name.
586
	 *
587
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
588
	 * characters are possible! You should always start the last part of the class
589
	 * name with an upper case character and continue only with lower case characters
590
	 * or numbers. Avoid chamel case names like "MyManager"!
591
	 *
592
	 * @param string Last part of the class name
593
	 * @since 2015.10
594
	 */
595
596
	/** mshop/media/manager/decorators/excludes
597
	 * Excludes decorators added by the "common" option from the media manager
598
	 *
599
	 * Decorators extend the functionality of a class by adding new aspects
600
	 * (e.g. log what is currently done), executing the methods of the underlying
601
	 * class only in certain conditions (e.g. only for logged in users) or
602
	 * modify what is returned to the caller.
603
	 *
604
	 * This option allows you to remove a decorator added via
605
	 * "mshop/common/manager/decorators/default" before they are wrapped
606
	 * around the media manager.
607
	 *
608
	 *  mshop/media/manager/decorators/excludes = array( 'decorator1' )
609
	 *
610
	 * This would remove the decorator named "decorator1" from the list of
611
	 * common decorators ("\Aimeos\MShop\Common\Manager\Decorator\*") added via
612
	 * "mshop/common/manager/decorators/default" for the media manager.
613
	 *
614
	 * @param array List of decorator names
615
	 * @since 2015.10
616
	 * @see mshop/common/manager/decorators/default
617
	 * @see mshop/media/manager/decorators/global
618
	 * @see mshop/media/manager/decorators/local
619
	 */
620
621
	/** mshop/media/manager/decorators/global
622
	 * Adds a list of globally available decorators only to the media manager
623
	 *
624
	 * Decorators extend the functionality of a class by adding new aspects
625
	 * (e.g. log what is currently done), executing the methods of the underlying
626
	 * class only in certain conditions (e.g. only for logged in users) or
627
	 * modify what is returned to the caller.
628
	 *
629
	 * This option allows you to wrap global decorators
630
	 * ("\Aimeos\MShop\Common\Manager\Decorator\*") around the media manager.
631
	 *
632
	 *  mshop/media/manager/decorators/global = array( 'decorator1' )
633
	 *
634
	 * This would add the decorator named "decorator1" defined by
635
	 * "\Aimeos\MShop\Common\Manager\Decorator\Decorator1" only to the media
636
	 * manager.
637
	 *
638
	 * @param array List of decorator names
639
	 * @since 2015.10
640
	 * @see mshop/common/manager/decorators/default
641
	 * @see mshop/media/manager/decorators/excludes
642
	 * @see mshop/media/manager/decorators/local
643
	 */
644
645
	/** mshop/media/manager/decorators/local
646
	 * Adds a list of local decorators only to the media manager
647
	 *
648
	 * Decorators extend the functionality of a class by adding new aspects
649
	 * (e.g. log what is currently done), executing the methods of the underlying
650
	 * class only in certain conditions (e.g. only for logged in users) or
651
	 * modify what is returned to the caller.
652
	 *
653
	 * This option allows you to wrap local decorators
654
	 * ("\Aimeos\MShop\Media\Manager\Decorator\*") around the media manager.
655
	 *
656
	 *  mshop/media/manager/decorators/local = array( 'decorator2' )
657
	 *
658
	 * This would add the decorator named "decorator2" defined by
659
	 * "\Aimeos\MShop\Media\Manager\Decorator\Decorator2" only to the media
660
	 * manager.
661
	 *
662
	 * @param array List of decorator names
663
	 * @since 2015.10
664
	 * @see mshop/common/manager/decorators/default
665
	 * @see mshop/media/manager/decorators/excludes
666
	 * @see mshop/media/manager/decorators/global
667
	 */
668
669
	/** mshop/media/manager/submanagers
670
	 * List of manager names that can be instantiated by the media manager
671
	 *
672
	 * Managers provide a generic interface to the underlying storage.
673
	 * Each manager has or can have sub-managers caring about particular
674
	 * aspects. Each of these sub-managers can be instantiated by its
675
	 * parent manager using the getSubManager() method.
676
	 *
677
	 * The search keys from sub-managers can be normally used in the
678
	 * manager as well. It allows you to search for items of the manager
679
	 * using the search keys of the sub-managers to further limit the
680
	 * retrieved list of items.
681
	 *
682
	 * @param array List of sub-manager names
683
	 * @since 2015.10
684
	 */
685
686
	/** mshop/media/manager/delete/mysql
687
	 * Deletes the items matched by the given IDs from the database
688
	 *
689
	 * @see mshop/media/manager/delete/ansi
690
	 */
691
692
	/** mshop/media/manager/delete/ansi
693
	 * Deletes the items matched by the given IDs from the database
694
	 *
695
	 * Removes the records specified by the given IDs from the media database.
696
	 * The records must be from the site that is configured via the
697
	 * context item.
698
	 *
699
	 * The ":cond" placeholder is replaced by the name of the ID column and
700
	 * the given ID or list of IDs while the site ID is bound to the question
701
	 * mark.
702
	 *
703
	 * The SQL statement should conform to the ANSI standard to be
704
	 * compatible with most relational database systems. This also
705
	 * includes using double quotes for table and column names.
706
	 *
707
	 * @param string SQL statement for deleting items
708
	 * @since 2015.10
709
	 * @see mshop/media/manager/insert/ansi
710
	 * @see mshop/media/manager/update/ansi
711
	 * @see mshop/media/manager/newid/ansi
712
	 * @see mshop/media/manager/search/ansi
713
	 * @see mshop/media/manager/count/ansi
714
	 */
715
716
	/** mshop/media/manager/insert/mysql
717
	 * Inserts a new media record into the database table
718
	 *
719
	 * @see mshop/media/manager/insert/ansi
720
	 */
721
722
	/** mshop/media/manager/insert/ansi
723
	 * Inserts a new media record into the database table
724
	 *
725
	 * Items with no ID yet (i.e. the ID is NULL) will be created in
726
	 * the database and the newly created ID retrieved afterwards
727
	 * using the "newid" SQL statement.
728
	 *
729
	 * The SQL statement must be a string suitable for being used as
730
	 * prepared statement. It must include question marks for binding
731
	 * the values from the media item to the statement before they are
732
	 * sent to the database server. The number of question marks must
733
	 * be the same as the number of columns listed in the INSERT
734
	 * statement. The order of the columns must correspond to the
735
	 * order in the save() method, so the correct values are
736
	 * bound to the columns.
737
	 *
738
	 * The SQL statement should conform to the ANSI standard to be
739
	 * compatible with most relational database systems. This also
740
	 * includes using double quotes for table and column names.
741
	 *
742
	 * @param string SQL statement for inserting records
743
	 * @since 2015.10
744
	 * @see mshop/media/manager/update/ansi
745
	 * @see mshop/media/manager/newid/ansi
746
	 * @see mshop/media/manager/delete/ansi
747
	 * @see mshop/media/manager/search/ansi
748
	 * @see mshop/media/manager/count/ansi
749
	 */
750
751
	/** mshop/media/manager/update/mysql
752
	 * Updates an existing media record in the database
753
	 *
754
	 * @see mshop/media/manager/update/ansi
755
	 */
756
757
	/** mshop/media/manager/update/ansi
758
	 * Updates an existing media record in the database
759
	 *
760
	 * Items which already have an ID (i.e. the ID is not NULL) will
761
	 * be updated in the database.
762
	 *
763
	 * The SQL statement must be a string suitable for being used as
764
	 * prepared statement. It must include question marks for binding
765
	 * the values from the media item to the statement before they are
766
	 * sent to the database server. The order of the columns must
767
	 * correspond to the order in the save() method, so the
768
	 * correct values are bound to the columns.
769
	 *
770
	 * The SQL statement should conform to the ANSI standard to be
771
	 * compatible with most relational database systems. This also
772
	 * includes using double quotes for table and column names.
773
	 *
774
	 * @param string SQL statement for updating records
775
	 * @since 2015.10
776
	 * @see mshop/media/manager/insert/ansi
777
	 * @see mshop/media/manager/newid/ansi
778
	 * @see mshop/media/manager/delete/ansi
779
	 * @see mshop/media/manager/search/ansi
780
	 * @see mshop/media/manager/count/ansi
781
	 */
782
783
	/** mshop/media/manager/newid/mysql
784
	 * Retrieves the ID generated by the database when inserting a new record
785
	 *
786
	 * @see mshop/media/manager/newid/ansi
787
	 */
788
789
	/** mshop/media/manager/newid/ansi
790
	 * Retrieves the ID generated by the database when inserting a new record
791
	 *
792
	 * As soon as a new record is inserted into the database table,
793
	 * the database server generates a new and unique identifier for
794
	 * that record. This ID can be used for retrieving, updating and
795
	 * deleting that specific record from the table again.
796
	 *
797
	 * For MySQL:
798
	 *  SELECT LAST_INSERT_ID()
799
	 * For PostgreSQL:
800
	 *  SELECT currval('seq_mmed_id')
801
	 * For SQL Server:
802
	 *  SELECT SCOPE_IDENTITY()
803
	 * For Oracle:
804
	 *  SELECT "seq_mmed_id".CURRVAL FROM DUAL
805
	 *
806
	 * There's no way to retrive the new ID by a SQL statements that
807
	 * fits for most database servers as they implement their own
808
	 * specific way.
809
	 *
810
	 * @param string SQL statement for retrieving the last inserted record ID
811
	 * @since 2015.10
812
	 * @see mshop/media/manager/insert/ansi
813
	 * @see mshop/media/manager/update/ansi
814
	 * @see mshop/media/manager/delete/ansi
815
	 * @see mshop/media/manager/search/ansi
816
	 * @see mshop/media/manager/count/ansi
817
	 */
818
819
	/** mshop/media/manager/sitemode
820
	 * Mode how items from levels below or above in the site tree are handled
821
	 *
822
	 * By default, only items from the current site are fetched from the
823
	 * storage. If the ai-sites extension is installed, you can create a
824
	 * tree of sites. Then, this setting allows you to define for the
825
	 * whole media domain if items from parent sites are inherited,
826
	 * sites from child sites are aggregated or both.
827
	 *
828
	 * Available constants for the site mode are:
829
	 * * 0 = only items from the current site
830
	 * * 1 = inherit items from parent sites
831
	 * * 2 = aggregate items from child sites
832
	 * * 3 = inherit and aggregate items at the same time
833
	 *
834
	 * You also need to set the mode in the locale manager
835
	 * (mshop/locale/manager/sitelevel) to one of the constants.
836
	 * If you set it to the same value, it will work as described but you
837
	 * can also use different modes. For example, if inheritance and
838
	 * aggregation is configured the locale manager but only inheritance
839
	 * in the domain manager because aggregating items makes no sense in
840
	 * this domain, then items wil be only inherited. Thus, you have full
841
	 * control over inheritance and aggregation in each domain.
842
	 *
843
	 * @param int Constant from Aimeos\MShop\Locale\Manager\Base class
844
	 * @since 2018.01
845
	 * @see mshop/locale/manager/sitelevel
846
	 */
847
848
	/** mshop/media/manager/search/mysql
849
	 * Retrieves the records matched by the given criteria in the database
850
	 *
851
	 * @see mshop/media/manager/search/ansi
852
	 */
853
854
	/** mshop/media/manager/search/ansi
855
	 * Retrieves the records matched by the given criteria in the database
856
	 *
857
	 * Fetches the records matched by the given criteria from the media
858
	 * database. The records must be from one of the sites that are
859
	 * configured via the context item. If the current site is part of
860
	 * a tree of sites, the SELECT statement can retrieve all records
861
	 * from the current site and the complete sub-tree of sites.
862
	 *
863
	 * As the records can normally be limited by criteria from sub-managers,
864
	 * their tables must be joined in the SQL context. This is done by
865
	 * using the "internaldeps" property from the definition of the ID
866
	 * column of the sub-managers. These internal dependencies specify
867
	 * the JOIN between the tables and the used columns for joining. The
868
	 * ":joins" placeholder is then replaced by the JOIN strings from
869
	 * the sub-managers.
870
	 *
871
	 * To limit the records matched, conditions can be added to the given
872
	 * criteria object. It can contain comparisons like column names that
873
	 * must match specific values which can be combined by AND, OR or NOT
874
	 * operators. The resulting string of SQL conditions replaces the
875
	 * ":cond" placeholder before the statement is sent to the database
876
	 * server.
877
	 *
878
	 * If the records that are retrieved should be ordered by one or more
879
	 * columns, the generated string of column / sort direction pairs
880
	 * replaces the ":order" placeholder. Columns of
881
	 * sub-managers can also be used for ordering the result set but then
882
	 * no index can be used.
883
	 *
884
	 * The number of returned records can be limited and can start at any
885
	 * number between the begining and the end of the result set. For that
886
	 * the ":size" and ":start" placeholders are replaced by the
887
	 * corresponding values from the criteria object. The default values
888
	 * are 0 for the start and 100 for the size value.
889
	 *
890
	 * The SQL statement should conform to the ANSI standard to be
891
	 * compatible with most relational database systems. This also
892
	 * includes using double quotes for table and column names.
893
	 *
894
	 * @param string SQL statement for searching items
895
	 * @since 2015.10
896
	 * @see mshop/media/manager/insert/ansi
897
	 * @see mshop/media/manager/update/ansi
898
	 * @see mshop/media/manager/newid/ansi
899
	 * @see mshop/media/manager/delete/ansi
900
	 * @see mshop/media/manager/count/ansi
901
	 */
902
903
	/** mshop/media/manager/count/mysql
904
	 * Counts the number of records matched by the given criteria in the database
905
	 *
906
	 * @see mshop/media/manager/count/ansi
907
	 */
908
909
	/** mshop/media/manager/count/ansi
910
	 * Counts the number of records matched by the given criteria in the database
911
	 *
912
	 * Counts all records matched by the given criteria from the media
913
	 * database. The records must be from one of the sites that are
914
	 * configured via the context item. If the current site is part of
915
	 * a tree of sites, the statement can count all records from the
916
	 * current site and the complete sub-tree of sites.
917
	 *
918
	 * As the records can normally be limited by criteria from sub-managers,
919
	 * their tables must be joined in the SQL context. This is done by
920
	 * using the "internaldeps" property from the definition of the ID
921
	 * column of the sub-managers. These internal dependencies specify
922
	 * the JOIN between the tables and the used columns for joining. The
923
	 * ":joins" placeholder is then replaced by the JOIN strings from
924
	 * the sub-managers.
925
	 *
926
	 * To limit the records matched, conditions can be added to the given
927
	 * criteria object. It can contain comparisons like column names that
928
	 * must match specific values which can be combined by AND, OR or NOT
929
	 * operators. The resulting string of SQL conditions replaces the
930
	 * ":cond" placeholder before the statement is sent to the database
931
	 * server.
932
	 *
933
	 * Both, the strings for ":joins" and for ":cond" are the same as for
934
	 * the "search" SQL statement.
935
	 *
936
	 * Contrary to the "search" statement, it doesn't return any records
937
	 * but instead the number of records that have been found. As counting
938
	 * thousands of records can be a long running task, the maximum number
939
	 * of counted records is limited for performance reasons.
940
	 *
941
	 * The SQL statement should conform to the ANSI standard to be
942
	 * compatible with most relational database systems. This also
943
	 * includes using double quotes for table and column names.
944
	 *
945
	 * @param string SQL statement for counting items
946
	 * @since 2015.10
947
	 * @see mshop/media/manager/insert/ansi
948
	 * @see mshop/media/manager/update/ansi
949
	 * @see mshop/media/manager/newid/ansi
950
	 * @see mshop/media/manager/delete/ansi
951
	 * @see mshop/media/manager/search/ansi
952
	 */
953
}
954