Passed
Push — master ( 6aab01...0294bc )
by Aimeos
09:44
created

Standard::saveItem()   B

Complexity

Conditions 8
Paths 33

Size

Total Lines 161
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 161
rs 8.1475
c 0
b 0
f 0
cc 8
nc 33
nop 2

How to fix   Long Method   

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 Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 * @package MAdmin
8
 * @subpackage Log
9
 */
10
11
12
namespace Aimeos\MAdmin\Log\Manager;
13
14
15
/**
16
 * Default log manager implementation.
17
 *
18
 * @package MAdmin
19
 * @subpackage Log
20
 */
21
class Standard
22
	extends \Aimeos\MAdmin\Common\Manager\Base
23
	implements \Aimeos\MAdmin\Log\Manager\Iface, \Aimeos\MShop\Common\Manager\Factory\Iface
24
{
25
	use \Aimeos\Base\Logger\Traits;
26
27
28
	private $loglevel;
29
	private $requestid;
30
31
	private $searchConfig = array(
32
		'log.id' => array(
33
			'code' => 'log.id',
34
			'internalcode' => 'malog."id"',
35
			'label' => 'Log ID',
36
			'type' => 'integer',
37
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
38
		),
39
		'log.siteid' => array(
40
			'code' => 'log.siteid',
41
			'internalcode' => 'malog."siteid"',
42
			'label' => 'Log site ID',
43
			'type' => 'string',
44
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
45
			'public' => false,
46
		),
47
		'log.message' => array(
48
			'code' => 'log.message',
49
			'internalcode' => 'malog."message"',
50
			'label' => 'Log message',
51
			'type' => 'string',
52
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
53
		),
54
		'log.facility' => array(
55
			'code' => 'log.facility',
56
			'internalcode' => 'malog."facility"',
57
			'label' => 'Log facility',
58
			'type' => 'string',
59
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
60
		),
61
		'log.priority' => array(
62
			'code' => 'log.priority',
63
			'internalcode' => 'malog."priority"',
64
			'label' => 'Log priority',
65
			'type' => 'integer',
66
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
67
		),
68
		'log.timestamp' => array(
69
			'code' => 'log.timestamp',
70
			'internalcode' => 'malog."timestamp"',
71
			'label' => 'Log create date/time',
72
			'type' => 'datetime',
73
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
74
		),
75
		'log.request' => array(
76
			'code' => 'log.request',
77
			'internalcode' => 'malog."request"',
78
			'label' => 'Log request',
79
			'type' => 'string',
80
			'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
81
		)
82
	);
83
84
85
	/**
86
	 * Creates the log manager that will use the given context object.
87
	 *
88
	 * @param \Aimeos\MShop\ContextIface $context Context object with required objects
89
	 */
90
	public function __construct( \Aimeos\MShop\ContextIface $context )
91
	{
92
		parent::__construct( $context );
93
		$this->setResourceName( 'db-log' );
94
95
		$config = $context->config();
96
97
		/** madmin/log/manager/loglevel
98
		 * Sets the severity level for messages to be written to the log
99
		 *
100
		 * Manager, provider and other active components write messages about
101
		 * problems, informational and debug output to the logs. The messages
102
		 * that are actually written to the logs can be limited with the
103
		 * "loglevel" configuration.
104
		 *
105
		 * Available log levels are:
106
		 * * Emergency (0): system is unusable
107
		 * * Alert (1): action must be taken immediately
108
		 * * Critical (2): critical conditions
109
		 * * Error (3): error conditions
110
		 * * Warning (4): warning conditions
111
		 * * Notice (5): normal but significant condition
112
		 * * Informational (6): informational messages
113
		 * * Debug (7): debug messages
114
		 *
115
		 * The "loglevel" configuration option defines the severity of messages
116
		 * that will be written to the logs, e.g. a log level of "3" (error)
117
		 * will allow all messages with an associated level of three and below
118
		 * (error, critical, alert and emergency) to be written to the storage.
119
		 * Messages with other log levels (warning, notice, informational and
120
		 * debug) would be discarded and won't be written to the storage.
121
		 *
122
		 * The higher the log level, the more messages will be written to the
123
		 * storage. Keep in mind that a higher volume of messages will slow
124
		 * down the system and the debug log level shouldn't be used in
125
		 * production environments with a high number of visitors!
126
		 *
127
		 * @param int Log level number
128
		 * @since 2014.03
129
		 * @category Developer
130
		 * @category User
131
		 */
132
		$this->loglevel = $config->get( 'madmin/log/manager/loglevel', \Aimeos\Base\Logger\Iface::NOTICE );
133
		$this->requestid = md5( php_uname( 'n' ) . getmypid() . date( 'Y-m-d H:i:s' ) );
134
	}
135
136
137
	/**
138
	 * Removes old entries from the storage.
139
	 *
140
	 * @param iterable $siteids List of IDs for sites whose entries should be deleted
141
	 * @return \Aimeos\MAdmin\Log\Manager\Iface Manager object for chaining method calls
142
	 */
143
	public function clear( iterable $siteids ) : \Aimeos\MShop\Common\Manager\Iface
144
	{
145
		$path = 'madmin/log/manager/submanagers';
146
		foreach( $this->context()->config()->get( $path, [] ) as $domain ) {
147
			$this->object()->getSubManager( $domain )->clear( $siteids );
148
		}
149
150
		return $this->clearBase( $siteids, 'madmin/log/manager/delete' );
151
	}
152
153
154
	/**
155
	 * Creates a new empty item instance
156
	 *
157
	 * @param array $values Values the item should be initialized with
158
	 * @return \Aimeos\MAdmin\Log\Item\Iface New log item object
159
	 */
160
	public function create( array $values = [] ) : \Aimeos\MShop\Common\Item\Iface
161
	{
162
		try {
163
			$values['log.siteid'] = $this->context()->locale()->getSiteId();
164
		} catch( \Exception $e ) {
165
			$values['log.siteid'] = null;
166
		}
167
168
		return $this->createItemBase( $values );
169
	}
170
171
172
	/**
173
	 * Adds a new log to the storage.
174
	 *
175
	 * @param \Aimeos\MAdmin\Log\Item\Iface $item Log item that should be saved to the storage
176
	 * @param bool $fetch True if the new ID should be returned in the item
177
	 * @return \Aimeos\MAdmin\Log\Item\Iface Updated item including the generated ID
178
	 */
179
	public function saveItem( \Aimeos\MAdmin\Log\Item\Iface $item, bool $fetch = true ) : \Aimeos\MAdmin\Log\Item\Iface
180
	{
181
		if( !$item->isModified() ) {
182
			return $item;
183
		}
184
185
		$context = $this->context();
186
		$conn = $context->db( $this->getResourceName() );
187
188
		try {
189
			$siteid = $context->locale()->getSiteId();
190
		} catch( \Exception $e ) {
191
			$siteid = '';
192
		}
193
194
			$id = $item->getId();
195
			$columns = $this->object()->getSaveAttributes();
196
197
			if( $id === null )
198
			{
199
				/** madmin/log/manager/insert/mysql
200
				 * Inserts a new log record into the database table
201
				 *
202
				 * @see madmin/log/manager/insert/ansi
203
				 */
204
205
				/** madmin/log/manager/insert/ansi
206
				 * Inserts a new log record into the database table
207
				 *
208
				 * Items with no ID yet (i.e. the ID is NULL) will be created in
209
				 * the database and the newly created ID retrieved afterwards
210
				 * using the "newid" SQL statement.
211
				 *
212
				 * The SQL statement must be a string suitable for being used as
213
				 * prepared statement. It must include question marks for binding
214
				 * the values from the log item to the statement before they are
215
				 * sent to the database server. The number of question marks must
216
				 * be the same as the number of columns listed in the INSERT
217
				 * statement. The order of the columns must correspond to the
218
				 * order in the save() method, so the correct values are
219
				 * bound to the columns.
220
				 *
221
				 * The SQL statement should conform to the ANSI standard to be
222
				 * compatible with most relational database systems. This also
223
				 * includes using double quotes for table and column names.
224
				 *
225
				 * @param string SQL statement for inserting records
226
				 * @since 2014.03
227
				 * @category Developer
228
				 * @see madmin/log/manager/update/ansi
229
				 * @see madmin/log/manager/newid/ansi
230
				 * @see madmin/log/manager/delete/ansi
231
				 * @see madmin/log/manager/search/ansi
232
				 * @see madmin/log/manager/count/ansi
233
				 */
234
				$path = 'madmin/log/manager/insert';
235
				$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ) );
0 ignored issues
show
Bug introduced by
It seems like $this->getSqlConfig($path) can also be of type array; however, parameter $sql of Aimeos\MShop\Common\Manager\Base::addSqlColumns() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

235
				$sql = $this->addSqlColumns( array_keys( $columns ), /** @scrutinizer ignore-type */ $this->getSqlConfig( $path ) );
Loading history...
236
			}
237
			else
238
			{
239
				/** madmin/log/manager/update/mysql
240
				 * Updates an existing log record in the database
241
				 *
242
				 * @see madmin/log/manager/update/ansi
243
				 */
244
245
				/** madmin/log/manager/update/ansi
246
				 * Updates an existing log record in the database
247
				 *
248
				 * Items which already have an ID (i.e. the ID is not NULL) will
249
				 * be updated in the database.
250
				 *
251
				 * The SQL statement must be a string suitable for being used as
252
				 * prepared statement. It must include question marks for binding
253
				 * the values from the log item to the statement before they are
254
				 * sent to the database server. The order of the columns must
255
				 * correspond to the order in the save() method, so the
256
				 * correct values are bound to the columns.
257
				 *
258
				 * The SQL statement should conform to the ANSI standard to be
259
				 * compatible with most relational database systems. This also
260
				 * includes using double quotes for table and column names.
261
				 *
262
				 * @param string SQL statement for updating records
263
				 * @since 2014.03
264
				 * @category Developer
265
				 * @see madmin/log/manager/insert/ansi
266
				 * @see madmin/log/manager/newid/ansi
267
				 * @see madmin/log/manager/delete/ansi
268
				 * @see madmin/log/manager/search/ansi
269
				 * @see madmin/log/manager/count/ansi
270
				 */
271
				$path = 'madmin/log/manager/update';
272
				$sql = $this->addSqlColumns( array_keys( $columns ), $this->getSqlConfig( $path ), false );
273
			}
274
275
			$idx = 1;
276
			$stmt = $this->getCachedStatement( $conn, $path, $sql );
277
278
			foreach( $columns as $name => $entry ) {
279
				$stmt->bind( $idx++, $item->get( $name ), $entry->getInternalType() );
280
			}
281
282
283
			$stmt->bind( $idx++, $item->getFacility() );
284
			$stmt->bind( $idx++, date( 'Y-m-d H:i:s' ) );
285
			$stmt->bind( $idx++, $item->getPriority(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
286
			$stmt->bind( $idx++, $item->getMessage() );
287
			$stmt->bind( $idx++, $item->getRequest() );
288
			$stmt->bind( $idx++, $siteid );
289
290
			if( $item->getId() !== null ) {
291
				$stmt->bind( $idx++, $item->getId(), \Aimeos\Base\DB\Statement\Base::PARAM_INT );
292
			}
293
294
			$stmt->execute()->finish();
295
296
			if( $id === null && $fetch === true )
297
			{
298
				/** madmin/log/manager/newid/mysql
299
				 * Retrieves the ID generated by the database when inserting a new record
300
				 *
301
				 * @see madmin/log/manager/newid/ansi
302
				 */
303
304
				/** madmin/log/manager/newid/ansi
305
				 * Retrieves the ID generated by the database when inserting a new record
306
				 *
307
				 * As soon as a new record is inserted into the database table,
308
				 * the database server generates a new and unique identifier for
309
				 * that record. This ID can be used for retrieving, updating and
310
				 * deleting that specific record from the table again.
311
				 *
312
				 * For MySQL:
313
				 *  SELECT LAST_INSERT_ID()
314
				 * For PostgreSQL:
315
				 *  SELECT currval('seq_malog_id')
316
				 * For SQL Server:
317
				 *  SELECT SCOPE_IDENTITY()
318
				 * For Oracle:
319
				 *  SELECT "seq_malog_id".CURRVAL FROM DUAL
320
				 *
321
				 * There's no way to retrive the new ID by a SQL statements that
322
				 * fits for most database servers as they implement their own
323
				 * specific way.
324
				 *
325
				 * @param string SQL statement for retrieving the last inserted record ID
326
				 * @since 2014.03
327
				 * @category Developer
328
				 * @see madmin/log/manager/insert/ansi
329
				 * @see madmin/log/manager/update/ansi
330
				 * @see madmin/log/manager/delete/ansi
331
				 * @see madmin/log/manager/search/ansi
332
				 * @see madmin/log/manager/count/ansi
333
				 */
334
				$id = $this->newId( $conn, 'madmin/log/manager/newid' );
335
			}
336
337
			$item->setId( $id );
338
339
		return $item;
340
	}
341
342
343
	/**
344
	 * Removes multiple items.
345
	 *
346
	 * @param \Aimeos\MShop\Common\Item\Iface[]|string[] $itemIds List of item objects or IDs of the items
347
	 * @return \Aimeos\MAdmin\Log\Manager\Iface Manager object for chaining method calls
348
	 */
349
	public function delete( $itemIds ) : \Aimeos\MShop\Common\Manager\Iface
350
	{
351
		/** madmin/log/manager/delete/mysql
352
		 * Deletes the items matched by the given IDs from the database
353
		 *
354
		 * @see madmin/log/manager/delete/ansi
355
		 */
356
357
		/** madmin/log/manager/delete/ansi
358
		 * Deletes the items matched by the given IDs from the database
359
		 *
360
		 * Removes the records specified by the given IDs from the log database.
361
		 * The records must be from the site that is configured via the
362
		 * context item.
363
		 *
364
		 * The ":cond" placeholder is replaced by the name of the ID column and
365
		 * the given ID or list of IDs while the site ID is bound to the question
366
		 * mark.
367
		 *
368
		 * The SQL statement should conform to the ANSI standard to be
369
		 * compatible with most relational database systems. This also
370
		 * includes using double quotes for table and column names.
371
		 *
372
		 * @param string SQL statement for deleting items
373
		 * @since 2014.03
374
		 * @category Developer
375
		 * @see madmin/log/manager/insert/ansi
376
		 * @see madmin/log/manager/update/ansi
377
		 * @see madmin/log/manager/newid/ansi
378
		 * @see madmin/log/manager/search/ansi
379
		 * @see madmin/log/manager/count/ansi
380
		 */
381
		$path = 'madmin/log/manager/delete';
382
383
		return $this->deleteItemsBase( $itemIds, $path );
384
	}
385
386
387
	/**
388
	 * Creates the log object for the given log id.
389
	 *
390
	 * @param string $id Log ID to fetch log object for
391
	 * @param string[] $ref List of domains to fetch list items and referenced items for
392
	 * @param bool|null $default Add default criteria or NULL for relaxed default criteria
393
	 * @return \Aimeos\MAdmin\Log\Item\Iface Returns the log item of the given id
394
	 * @throws \Aimeos\MAdmin\Log\Exception If item couldn't be found
395
	 */
396
	public function get( string $id, array $ref = [], ?bool $default = false ) : \Aimeos\MShop\Common\Item\Iface
397
	{
398
		$criteria = $this->object()->filter( $default );
399
		$expr = [
400
			$criteria->compare( '==', 'log.id', $id ),
401
			$criteria->getConditions()
402
		];
403
		$criteria->setConditions( $criteria->and( $expr ) );
404
405
		if( ( $item = $this->object()->search( $criteria, $ref )->first() ) ) {
406
			return $item;
407
		}
408
409
		$msg = $this->context()->translate( 'mshop', 'Log entry with ID "%1$s" not found' );
410
		throw new \Aimeos\MAdmin\Log\Exception( sprintf( $msg, $id ) );
411
	}
412
413
414
	/**
415
	 * Search for log entries based on the given criteria.
416
	 *
417
	 * @param \Aimeos\Base\Criteria\Iface $search Search object containing the conditions
418
	 * @param string[] $ref List of domains to fetch list items and referenced items for
419
	 * @param int &$total Number of items that are available in total
420
	 * @return \Aimeos\Map List of items implementing Aimeos\MAdmin\Log\Item\Iface with ids as keys
421
	 */
422
	public function search( \Aimeos\Base\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
423
	{
424
		$items = [];
425
		$context = $this->context();
426
		$conn = $context->db( $this->getResourceName() );
427
428
			$required = array( 'log' );
429
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE;
430
431
			/** madmin/log/manager/search/mysql
432
			 * Retrieves the records matched by the given criteria in the database
433
			 *
434
			 * @see madmin/log/manager/search/ansi
435
			 */
436
437
			/** madmin/log/manager/search/ansi
438
			 * Retrieves the records matched by the given criteria in the database
439
			 *
440
			 * Fetches the records matched by the given criteria from the log
441
			 * database. The records must be from one of the sites that are
442
			 * configured via the context item. If the current site is part of
443
			 * a tree of sites, the SELECT statement can retrieve all records
444
			 * from the current site and the complete sub-tree of sites.
445
			 *
446
			 * As the records can normally be limited by criteria from sub-managers,
447
			 * their tables must be joined in the SQL context. This is done by
448
			 * using the "internaldeps" property from the definition of the ID
449
			 * column of the sub-managers. These internal dependencies specify
450
			 * the JOIN between the tables and the used columns for joining. The
451
			 * ":joins" placeholder is then replaced by the JOIN strings from
452
			 * the sub-managers.
453
			 *
454
			 * To limit the records matched, conditions can be added to the given
455
			 * criteria object. It can contain comparisons like column names that
456
			 * must match specific values which can be combined by AND, OR or NOT
457
			 * operators. The resulting string of SQL conditions replaces the
458
			 * ":cond" placeholder before the statement is sent to the database
459
			 * server.
460
			 *
461
			 * If the records that are retrieved should be ordered by one or more
462
			 * columns, the generated string of column / sort direction pairs
463
			 * replaces the ":order" placeholder. In case no ordering is required,
464
			 * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/"
465
			 * markers is removed to speed up retrieving the records. Columns of
466
			 * sub-managers can also be used for ordering the result set but then
467
			 * no index can be used.
468
			 *
469
			 * The number of returned records can be limited and can start at any
470
			 * number between the begining and the end of the result set. For that
471
			 * the ":size" and ":start" placeholders are replaced by the
472
			 * corresponding values from the criteria object. The default values
473
			 * are 0 for the start and 100 for the size value.
474
			 *
475
			 * The SQL statement should conform to the ANSI standard to be
476
			 * compatible with most relational database systems. This also
477
			 * includes using double quotes for table and column names.
478
			 *
479
			 * @param string SQL statement for searching items
480
			 * @since 2014.03
481
			 * @category Developer
482
			 * @see madmin/log/manager/insert/ansi
483
			 * @see madmin/log/manager/update/ansi
484
			 * @see madmin/log/manager/newid/ansi
485
			 * @see madmin/log/manager/delete/ansi
486
			 * @see madmin/log/manager/count/ansi
487
			 */
488
			$cfgPathSearch = 'madmin/log/manager/search';
489
490
			/** madmin/log/manager/count/mysql
491
			 * Counts the number of records matched by the given criteria in the database
492
			 *
493
			 * @see madmin/log/manager/count/ansi
494
			 */
495
496
			/** madmin/log/manager/count/ansi
497
			 * Counts the number of records matched by the given criteria in the database
498
			 *
499
			 * Counts all records matched by the given criteria from the log
500
			 * database. The records must be from one of the sites that are
501
			 * configured via the context item. If the current site is part of
502
			 * a tree of sites, the statement can count all records from the
503
			 * current site and the complete sub-tree of sites.
504
			 *
505
			 * As the records can normally be limited by criteria from sub-managers,
506
			 * their tables must be joined in the SQL context. This is done by
507
			 * using the "internaldeps" property from the definition of the ID
508
			 * column of the sub-managers. These internal dependencies specify
509
			 * the JOIN between the tables and the used columns for joining. The
510
			 * ":joins" placeholder is then replaced by the JOIN strings from
511
			 * the sub-managers.
512
			 *
513
			 * To limit the records matched, conditions can be added to the given
514
			 * criteria object. It can contain comparisons like column names that
515
			 * must match specific values which can be combined by AND, OR or NOT
516
			 * operators. The resulting string of SQL conditions replaces the
517
			 * ":cond" placeholder before the statement is sent to the database
518
			 * server.
519
			 *
520
			 * Both, the strings for ":joins" and for ":cond" are the same as for
521
			 * the "search" SQL statement.
522
			 *
523
			 * Contrary to the "search" statement, it doesn't return any records
524
			 * but instead the number of records that have been found. As counting
525
			 * thousands of records can be a long running task, the maximum number
526
			 * of counted records is limited for performance reasons.
527
			 *
528
			 * The SQL statement should conform to the ANSI standard to be
529
			 * compatible with most relational database systems. This also
530
			 * includes using double quotes for table and column names.
531
			 *
532
			 * @param string SQL statement for counting items
533
			 * @since 2014.03
534
			 * @category Developer
535
			 * @see madmin/log/manager/insert/ansi
536
			 * @see madmin/log/manager/update/ansi
537
			 * @see madmin/log/manager/newid/ansi
538
			 * @see madmin/log/manager/delete/ansi
539
			 * @see madmin/log/manager/search/ansi
540
			 */
541
			$cfgPathCount = 'madmin/log/manager/count';
542
543
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
544
545
			while( ( $row = $results->fetch() ) !== null )
546
			{
547
				if( $item = $this->applyFilter( $this->createItemBase( $row ) ) ) {
548
					$items[$row['log.id']] = $item;
549
				}
550
			}
551
552
		return map( $items );
553
	}
554
555
556
	/**
557
	 * Returns the available manager types
558
	 *
559
	 * @param bool $withsub Return also the resource type of sub-managers if true
560
	 * @return string[] Type of the manager and submanagers, subtypes are separated by slashes
561
	 */
562
	public function getResourceType( bool $withsub = true ) : array
563
	{
564
		$path = 'madmin/log/manager/submanagers';
565
		return $this->getResourceTypeBase( 'log', $path, [], $withsub );
566
	}
567
568
569
	/**
570
	 * Returns the attributes that can be used for searching.
571
	 *
572
	 * @param bool $withsub Return also attributes of sub-managers if true
573
	 * @return \Aimeos\Base\Criteria\Attribute\Iface[] Returns a list of search attributes
574
	 */
575
	public function getSearchAttributes( bool $withsub = true ) : array
576
	{
577
		/** madmin/log/manager/submanagers
578
		 * List of manager names that can be instantiated by the log manager
579
		 *
580
		 * Managers provide a generic interface to the underlying storage.
581
		 * Each manager has or can have sub-managers caring about particular
582
		 * aspects. Each of these sub-managers can be instantiated by its
583
		 * parent manager using the getSubManager() method.
584
		 *
585
		 * The search keys from sub-managers can be normally used in the
586
		 * manager as well. It allows you to search for items of the manager
587
		 * using the search keys of the sub-managers to further limit the
588
		 * retrieved list of items.
589
		 *
590
		 * @param array List of sub-manager names
591
		 * @since 2014.03
592
		 * @category Developer
593
		 */
594
		$path = 'madmin/log/manager/submanagers';
595
596
		return $this->getSearchAttributesBase( $this->searchConfig, $path, [], $withsub );
597
	}
598
599
600
	/**
601
	 * Returns a new manager for log extensions
602
	 *
603
	 * @param string $manager Name of the sub manager type in lower case
604
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
605
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager for different extensions, e.g stock, tags, locations, etc.
606
	 */
607
	public function getSubManager( string $manager, string $name = null ) : \Aimeos\MShop\Common\Manager\Iface
608
	{
609
		return $this->getSubManagerBase( 'log', $manager, $name );
610
	}
611
612
613
	/**
614
	 * Create new admin log item object initialized with given parameters.
615
	 *
616
	 * @param array $values Associative list of key/value pairs of a job
617
	 * @return \Aimeos\MAdmin\Log\Item\Iface New log item
618
	 */
619
	protected function createItemBase( array $values = [] ) : \Aimeos\MAdmin\Log\Item\Iface
620
	{
621
		return new \Aimeos\MAdmin\Log\Item\Standard( $values );
622
	}
623
624
625
	/**
626
	 * Writes a message to the configured log facility.
627
	 *
628
	 * @param string|array|object $message Message text that should be written to the log facility
629
	 * @param int $priority Priority of the message for filtering
630
	 * @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog)
631
	 * @return \Aimeos\Base\Logger\Iface Logger object for method chaining
632
	 */
633
	public function log( $message, int $priority = \Aimeos\Base\Logger\Iface::ERR, string $facility = 'message' ) : \Aimeos\Base\Logger\Iface
634
	{
635
		if( $priority <= $this->loglevel )
636
		{
637
			if( !is_scalar( $message ) ) {
638
				$message = json_encode( $message );
639
			}
640
641
			$item = $this->object()->create();
642
643
			$item->setFacility( $facility );
644
			$item->setPriority( $priority );
645
			$item->setMessage( $message );
646
			$item->setRequest( $this->requestid );
647
648
			$this->object()->save( $item );
649
		}
650
651
		return $this;
652
	}
653
}
654