Passed
Push — master ( bfd2b7...b98f34 )
by Aimeos
04:16
created

Standard::scale()   C

Complexity

Conditions 15
Paths 7

Size

Total Lines 45
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 28
c 4
b 0
f 0
dl 0
loc 45
rs 5.9166
cc 15
nc 7
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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