• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / 77cfcd86-13ba-4918-aeab-35e967c86487

28 Sep 2024 11:34AM UTC coverage: 91.619% (-0.02%) from 91.637%
77cfcd86-13ba-4918-aeab-35e967c86487

push

circleci

aimeos
Fixed file check

1 of 2 new or added lines in 1 file covered. (50.0%)

2 existing lines in 1 file now uncovered.

9543 of 10416 relevant lines covered (91.62%)

79.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.66
/src/MShop/Media/Manager/Standard.php
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;
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 );
1✔
39

40
                $path = $item->getUrl();
1✔
41
                $mime = $item->getMimeType();
1✔
42
                $domain = $item->getDomain();
1✔
43
                $previews = $item->getPreviews();
1✔
44
                $fsname = $item->getFileSystem();
1✔
45
                $fs = $this->context()->fs( $fsname );
1✔
46

47
                if( $fs->has( $path ) )
1✔
48
                {
49
                        $newPath = $this->path( substr( basename( $path ), 9 ), $mime, $domain );
1✔
50
                        $fs->copy( $path, $newPath );
1✔
51
                        $item->setUrl( $newPath );
1✔
52
                }
53

54
                if( empty( $previews ) ) {
1✔
55
                        return $this->scale( $item, true );
×
56
                }
57

58
                foreach( $previews as $size => $preview )
1✔
59
                {
60
                        if( $fsname !== 'fs-mimeicon' && $fs->has( $preview ) )
1✔
61
                        {
62
                                $newPath = $this->path( substr( basename( $preview ), 9 ), $mime, $domain );
1✔
63
                                $fs->copy( $preview, $newPath );
1✔
64
                                $previews[$size] = $newPath;
1✔
65
                        }
66
                }
67

68
                return $item->setPreviews( $previews );
1✔
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();
21✔
81

82
                $values['.languageid'] = $locale->getLanguageId();
21✔
83
                $values['media.siteid'] = $values['media.siteid'] ?? $locale->getSiteId();
21✔
84

85
                return new \Aimeos\MShop\Media\Item\Standard( 'media.', $values );
21✔
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 )
3✔
98
                {
99
                        if( $item instanceof \Aimeos\MShop\Media\Item\Iface && $item->getFileSystem() === 'fs-media' )
3✔
100
                        {
101
                                try
102
                                {
103
                                        $this->deletePreviews( $item, $item->getPreviews() );
2✔
104
                                        $this->deleteFile( $item->getUrl(), 'fs-media' );
2✔
105
                                }
UNCOV
106
                                catch( \Exception $e )
×
107
                                {
UNCOV
108
                                        $this->context()->logger()->notice( $e->getMessage() );
×
109
                                }
110
                        }
111
                }
112

113
                return parent::delete( $items );
3✔
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 );
14✔
127

128
                if( $default !== false )
14✔
129
                {
130
                        if( $langid = $this->context()->locale()->getLanguageId() )
1✔
131
                        {
132
                                $filter->add( $filter->or( [
1✔
133
                                        $filter->compare( '==', 'media.languageid', $langid ),
1✔
134
                                        $filter->compare( '==', 'media.languageid', null ),
1✔
135
                                ] ) );
1✔
136
                        }
137
                }
138

139
                return $filter;
14✔
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( [
13✔
151
                        'media.type' => [
13✔
152
                                'label' => 'Type',
13✔
153
                                'internalcode' => 'type',
13✔
154
                        ],
13✔
155
                        'media.label' => [
13✔
156
                                'label' => 'Label',
13✔
157
                                'internalcode' => 'label',
13✔
158
                        ],
13✔
159
                        'media.domain' => [
13✔
160
                                'label' => 'Domain',
13✔
161
                                'internalcode' => 'domain',
13✔
162
                        ],
13✔
163
                        'media.languageid' => [
13✔
164
                                'label' => 'Language code',
13✔
165
                                'internalcode' => 'langid',
13✔
166
                        ],
13✔
167
                        'media.mimetype' => [
13✔
168
                                'label' => 'Mime type',
13✔
169
                                'internalcode' => 'mimetype',
13✔
170
                        ],
13✔
171
                        'media.url' => [
13✔
172
                                'label' => 'URL',
13✔
173
                                'internalcode' => 'link',
13✔
174
                        ],
13✔
175
                        'media.previews' => [
13✔
176
                                'label' => 'Preview URLs as JSON encoded string',
13✔
177
                                'internalcode' => 'preview',
13✔
178
                                'type' => 'json',
13✔
179
                        ],
13✔
180
                        'media.filesystem' => [
13✔
181
                                'label' => 'File sytem name',
13✔
182
                                'internalcode' => 'fsname',
13✔
183
                        ],
13✔
184
                        'media.status' => [
13✔
185
                                'label' => 'Status',
13✔
186
                                'internalcode' => 'status',
13✔
187
                                'type' => 'int',
13✔
188
                        ],
13✔
189
                ] );
13✔
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( [
13✔
202
                        'media.preview' => [
13✔
203
                                'label' => 'Preview URLs as JSON encoded string',
13✔
204
                                'internalcode' => 'preview',
13✔
205
                                'type' => 'json',
13✔
206
                        ],
13✔
207
                ] ) );
13✔
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.';
13✔
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();
3✔
237

238
                if( empty( $url = $item->getUrl() )
3✔
239
                        || $item->getFileSystem() === 'fs-mimeicon'
3✔
240
                        || strncmp( 'data:', $url, 5 ) === 0
3✔
241
                        || strncmp( 'image/svg', $mime, 9 ) === 0
3✔
242
                        || strncmp( 'image/', $mime, 6 ) !== 0
3✔
243
                ) {
244
                        return $item;
×
245
                }
246

247
                $fs = $this->context()->fs( $item->getFileSystem() );
3✔
248
                $is = ( $fs instanceof \Aimeos\Base\Filesystem\MetaIface ? true : false );
3✔
249

250
                if( !$force
3✔
251
                        && !empty( $item->getPreviews() )
3✔
252
                        && preg_match( '#^[a-zA-Z]{2,6}://#', $url ) !== 1
3✔
253
                        && ( $is && date( 'Y-m-d H:i:s', $fs->time( $url ) ) < $item->getTimeModified() || $fs->has( $url ) )
3✔
254
                ) {
255
                        return $item;
×
256
                }
257

258
                $domain = $item->getDomain() ?: '-';
3✔
259
                $sizes = $this->sizes( $domain, $item->getType() );
3✔
260
                $image = $this->image( $url );
3✔
261
                $quality = $this->quality();
3✔
262
                $old = $item->getPreviews();
3✔
263
                $previews = [];
3✔
264

265
                foreach( $this->createPreviews( $image, $sizes ) as $width => $image )
3✔
266
                {
267
                        $path = $old[$width] ?? $this->path( $url, 'image/webp', $domain );
3✔
268
                        $fs->write( $path, (string) $image->toWebp( $quality ) );
3✔
269

270
                        $previews[$width] = $path;
3✔
271
                        unset( $old[$width] );
3✔
272
                }
273

274
                $item = $this->deletePreviews( $item, $old )->setPreviews( $previews );
3✔
275

276
                $this->call( 'scaled', $item, $image );
3✔
277

278
                return $item;
3✔
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();
3✔
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', [] );
3✔
374
                $sizes = $config->get( 'mshop/media/manager/previews/' . $domain, $sizes );
3✔
375
                $sizes = $config->get( 'mshop/media/manager/previews/' . $domain . '/' . $type, $sizes );
3✔
376

377
                return $sizes;
3✔
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() ?: '-';
3✔
392
                $fsname = $item->getFileSystem() ?: 'fs-media';
3✔
393
                $fs = $this->context()->fs( $fsname );
3✔
394

395
                if( $file && $file->getError() !== UPLOAD_ERR_NO_FILE && $this->isAllowed( $mime = $this->mimetype( $file ) ) )
3✔
396
                {
397
                        try
398
                        {
399
                                $oldpath = $item->getUrl();
2✔
400

401
                                $path = $this->path( $file->getClientFilename(), $mime, $domain );
2✔
402
                                $fs->write( $path, $this->sanitize( $file->getStream()->getContents(), $mime ) );
2✔
403

404
                                $item->setLabel( $file->getClientFilename() )
2✔
405
                                        ->setMimetype( $mime )
2✔
406
                                        ->setUrl( $path );
2✔
407

408
                                if( !$preview ) {
2✔
409
                                        $this->scale( $item, true );
1✔
410
                                }
411

412
                                if( !empty( $oldpath ) && $fs->has( $oldpath ) ) {
2✔
413
                                        $fs->rm( $oldpath );
2✔
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 ) ) )
2✔
427
                {
428
                        $path = $this->path( $preview->getClientFilename(), $mime, $domain );
1✔
429
                        $fs->write( $path, $this->sanitize( $preview->getStream()->getContents(), $mime ) );
1✔
430

431
                        $item->setPreview( $path );
1✔
432
                }
433

434
                return $item;
2✔
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
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc