Passed
Push — master ( 6468ac...54f711 )
by Aimeos
03:48
created

Standard::locales()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 * @package Controller
7
 * @subpackage Jobs
8
 */
9
10
11
namespace Aimeos\Controller\Jobs\Catalog\Export\Sitemap;
12
13
14
/**
15
 * Job controller for catalog sitemap.
16
 *
17
 * @package Controller
18
 * @subpackage Jobs
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Jobs\Base
22
	implements \Aimeos\Controller\Jobs\Iface
23
{
24
	/** controller/jobs/catalog/export/sitemap/name
25
	 * Class name of the used catalog sitemap export scheduler controller implementation
26
	 *
27
	 * Each default job controller can be replace by an alternative imlementation.
28
	 * To use this implementation, you have to set the last part of the class
29
	 * name as configuration value so the controller factory knows which class it
30
	 * has to instantiate.
31
	 *
32
	 * For example, if the name of the default class is
33
	 *
34
	 *  \Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Standard
35
	 *
36
	 * and you want to replace it with your own version named
37
	 *
38
	 *  \Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Mysitemap
39
	 *
40
	 * then you have to set the this configuration option:
41
	 *
42
	 *  controller/jobs/catalog/export/sitemap/name = Mysitemap
43
	 *
44
	 * The value is the last part of your own class name and it's case sensitive,
45
	 * so take care that the configuration value is exactly named like the last
46
	 * part of the class name.
47
	 *
48
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
49
	 * characters are possible! You should always start the last part of the class
50
	 * name with an upper case character and continue only with lower case characters
51
	 * or numbers. Avoid chamel case names like "MySitemap"!
52
	 *
53
	 * @param string Last part of the class name
54
	 * @since 2019.02
55
	 * @category Developer
56
	 */
57
58
	/** controller/jobs/catalog/export/sitemap/decorators/excludes
59
	 * Excludes decorators added by the "common" option from the catalog export sitemap job controller
60
	 *
61
	 * Decorators extend the functionality of a class by adding new aspects
62
	 * (e.g. log what is currently done), executing the methods of the underlying
63
	 * class only in certain conditions (e.g. only for logged in users) or
64
	 * modify what is returned to the caller.
65
	 *
66
	 * This option allows you to remove a decorator added via
67
	 * "controller/jobs/common/decorators/default" before they are wrapped
68
	 * around the job controller.
69
	 *
70
	 *  controller/jobs/catalog/export/sitemap/decorators/excludes = array( 'decorator1' )
71
	 *
72
	 * This would remove the decorator named "decorator1" from the list of
73
	 * common decorators ("\Aimeos\Controller\Jobs\Common\Decorator\*") added via
74
	 * "controller/jobs/common/decorators/default" to the job controller.
75
	 *
76
	 * @param array List of decorator names
77
	 * @since 2019.02
78
	 * @category Developer
79
	 * @see controller/jobs/common/decorators/default
80
	 * @see controller/jobs/catalog/export/sitemap/decorators/global
81
	 * @see controller/jobs/catalog/export/sitemap/decorators/local
82
	 */
83
84
	/** controller/jobs/catalog/export/sitemap/decorators/global
85
	 * Adds a list of globally available decorators only to the catalog export sitemap job controller
86
	 *
87
	 * Decorators extend the functionality of a class by adding new aspects
88
	 * (e.g. log what is currently done), executing the methods of the underlying
89
	 * class only in certain conditions (e.g. only for logged in users) or
90
	 * modify what is returned to the caller.
91
	 *
92
	 * This option allows you to wrap global decorators
93
	 * ("\Aimeos\Controller\Jobs\Common\Decorator\*") around the job controller.
94
	 *
95
	 *  controller/jobs/catalog/export/sitemap/decorators/global = array( 'decorator1' )
96
	 *
97
	 * This would add the decorator named "decorator1" defined by
98
	 * "\Aimeos\Controller\Jobs\Common\Decorator\Decorator1" only to the job controller.
99
	 *
100
	 * @param array List of decorator names
101
	 * @since 2019.02
102
	 * @category Developer
103
	 * @see controller/jobs/common/decorators/default
104
	 * @see controller/jobs/catalog/export/sitemap/decorators/excludes
105
	 * @see controller/jobs/catalog/export/sitemap/decorators/local
106
	 */
107
108
	/** controller/jobs/catalog/export/sitemap/decorators/local
109
	 * Adds a list of local decorators only to the catalog export sitemap job controller
110
	 *
111
	 * Decorators extend the functionality of a class by adding new aspects
112
	 * (e.g. log what is currently done), executing the methods of the underlying
113
	 * class only in certain conditions (e.g. only for logged in users) or
114
	 * modify what is returned to the caller.
115
	 *
116
	 * This option allows you to wrap local decorators
117
	 * ("\Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Decorator\*") around the job
118
	 * controller.
119
	 *
120
	 *  controller/jobs/catalog/export/sitemap/decorators/local = array( 'decorator2' )
121
	 *
122
	 * This would add the decorator named "decorator2" defined by
123
	 * "\Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Decorator\Decorator2"
124
	 * only to the job controller.
125
	 *
126
	 * @param array List of decorator names
127
	 * @since 2019.02
128
	 * @category Developer
129
	 * @see controller/jobs/common/decorators/default
130
	 * @see controller/jobs/catalog/export/sitemap/export/sitemap/decorators/excludes
131
	 * @see controller/jobs/catalog/export/sitemap/export/sitemap/decorators/global
132
	 */
133
134
135
	/**
136
	 * Returns the localized name of the job.
137
	 *
138
	 * @return string Name of the job
139
	 */
140
	public function getName() : string
141
	{
142
		return $this->context()->translate( 'controller/jobs', 'Catalog site map' );
143
	}
144
145
146
	/**
147
	 * Returns the localized description of the job.
148
	 *
149
	 * @return string Description of the job
150
	 */
151
	public function getDescription() : string
152
	{
153
		return $this->context()->translate( 'controller/jobs', 'Creates a catalog site map for search engines' );
154
	}
155
156
157
	/**
158
	 * Executes the job.
159
	 *
160
	 * @throws \Aimeos\Controller\Jobs\Exception If an error occurs
161
	 */
162
	public function run()
163
	{
164
		/** controller/jobs/catalog/export/sitemap/hidden
165
		 * Export hidden categories in site map
166
		 *
167
		 * The catalog site map contains no hidden categories by default. If they
168
		 * should be part of the export, set this configuration option to TRUE.
169
		 *
170
		 * @param bool TRUE to export hidden categories, FALSE if not
171
		 * @since 2022.01
172
		 * @see controller/jobs/catalog/export/sitemap/container/options
173
		 * @see controller/jobs/catalog/export/sitemap/location
174
		 * @see controller/jobs/catalog/export/sitemap/max-items
175
		 * @see controller/jobs/catalog/export/sitemap/max-query
176
		 * @see controller/jobs/catalog/export/sitemap/changefreq
177
		 */
178
		$hidden = $this->context()->config()->get( 'controller/jobs/catalog/export/sitemap/hidden', false );
179
180
		$container = $this->createContainer();
181
182
		$files = $this->export( $container, $hidden ? null : true );
183
		$this->createSitemapIndex( $container, $files );
184
185
		$container->close();
186
	}
187
188
189
	/**
190
	 * Adds the given catalogs to the content object for the site map file
191
	 *
192
	 * @param \Aimeos\MW\Container\Content\Iface $content File content object
193
	 * @param \Aimeos\Map $items List of catalog items implementing \Aimeos\MShop\Catalog\Item\Iface
194
	 */
195
	protected function addItems( \Aimeos\MW\Container\Content\Iface $content, \Aimeos\Map $items )
196
	{
197
		$config = $this->context()->config();
198
199
		/** controller/jobs/catalog/export/sitemap/changefreq
200
		 * Change frequency of the catalog
201
		 *
202
		 * Depending on how often the catalog content changes
203
		 * and the site map files are generated you can give search engines a
204
		 * hint how often they should reindex your site. The site map schema
205
		 * allows a few pre-defined strings for the change frequency:
206
		 *
207
		 * * always
208
		 * * hourly
209
		 * * daily
210
		 * * weekly
211
		 * * monthly
212
		 * * yearly
213
		 * * never
214
		 *
215
		 * More information can be found at
216
		 * {@link http://www.sitemaps.org/protocol.html#xmlTagDefinitions sitemap.org}
217
		 *
218
		 * @param string One of the pre-defined strings (see description)
219
		 * @since 2019.02
220
		 * @category User
221
		 * @category Developer
222
		 * @see controller/jobs/catalog/export/sitemap/container/options
223
		 * @see controller/jobs/catalog/export/sitemap/location
224
		 * @see controller/jobs/catalog/export/sitemap/max-items
225
		 * @see controller/jobs/catalog/export/sitemap/max-query
226
		 */
227
		$changefreq = $config->get( 'controller/jobs/catalog/export/sitemap/changefreq', 'daily' );
228
229
		/** controller/jobs/catalog/export/sitemap/template-items
230
		 * Relative path to the XML items template of the catalog site map job controller.
231
		 *
232
		 * The template file contains the XML code and processing instructions
233
		 * to generate the site map files. The configuration string is the path
234
		 * to the template file relative to the templates directory (usually in
235
		 * controller/jobs/templates).
236
		 *
237
		 * You can overwrite the template file configuration in extensions and
238
		 * provide alternative templates. These alternative templates should be
239
		 * named like the default one but with the string "standard" replaced by
240
		 * an unique name. You may use the name of your project for this. If
241
		 * you've implemented an alternative client class as well, "standard"
242
		 * should be replaced by the name of the new class.
243
		 *
244
		 * @param string Relative path to the template creating XML code for the site map items
245
		 * @since 2019.02
246
		 * @category Developer
247
		 * @see controller/jobs/catalog/export/sitemap/template-header
248
		 * @see controller/jobs/catalog/export/sitemap/template-footer
249
		 * @see controller/jobs/catalog/export/sitemap/template-index
250
		 */
251
		$tplconf = 'controller/jobs/catalog/export/sitemap/template-items';
252
		$default = 'catalog/export/sitemap-items-body-standard';
253
254
		$context = $this->context();
255
		$view = $context->view();
256
257
		$view->siteItems = $items;
258
		$view->siteFreq = $changefreq;
259
		$view->siteLocales = $this->locales();
260
261
		$content->add( $view->render( $context->config()->get( $tplconf, $default ) ) );
262
	}
263
264
265
	/**
266
	 * Creates a new container for the site map file
267
	 *
268
	 * @return \Aimeos\MW\Container\Iface Container object
269
	 */
270
	protected function createContainer() : \Aimeos\MW\Container\Iface
271
	{
272
		$config = $this->context()->config();
273
274
		/** controller/jobs/catalog/export/sitemap/location
275
		 * Directory where the generated site maps should be placed into
276
		 *
277
		 * The site maps must be publically available for download by the search
278
		 * engines. Therefore, you have to configure a directory for the site
279
		 * maps in your web space that is writeable by the process generating
280
		 * the files, e.g.
281
		 *
282
		 * /var/www/yourshop/your/sitemap/path
283
		 *
284
		 * The location of the site map index file should then be
285
		 * added to the robots.txt in the document root of your domain:
286
		 *
287
		 * Sitemap: https://www.yourshop.com/your/sitemap/path/aimeos-sitemap-index.xml
288
		 *
289
		 * The "sitemapindex-aimeos.xml" file is the site map index file that
290
		 * references the real site map files which contains the links to the
291
		 * catalogs. Please make sure that the protocol and domain
292
		 * (https://www.yourshop.com/) is the same as the ones used in the
293
		 * catalog links!
294
		 *
295
		 * More details about site maps can be found at
296
		 * {@link http://www.sitemaps.org/protocol.html sitemaps.org}
297
		 *
298
		 * @param string Absolute directory to store the site maps into
299
		 * @since 2019.02
300
		 * @category Developer
301
		 * @category User
302
		 * @see controller/jobs/catalog/export/sitemap/container/options
303
		 * @see controller/jobs/catalog/export/sitemap/max-items
304
		 * @see controller/jobs/catalog/export/sitemap/max-query
305
		 * @see controller/jobs/catalog/export/sitemap/changefreq
306
		 */
307
		$location = $config->get( 'controller/jobs/catalog/export/sitemap/location' );
308
309
		/** controller/jobs/catalog/export/sitemap/container/options
310
		 * List of file container options for the site map files
311
		 *
312
		 * The directory and the generated site map files are stored using
313
		 * container/content objects from the core, namely the "Directory"
314
		 * container and the "Binary" content classes. Both implementations
315
		 * support some options:
316
		 *
317
		 * * dir-perm (default: 0755): Permissions if the directory must be created
318
		 * * gzip-level (default: 5): GZip compression level from 0 to 9 (0 = fast, 9 = best)
319
		 * * gzip-mode (default: "wb"): Overwrite existing files in binary mode
320
		 *
321
		 * @param array Associative list of option name/value pairs
322
		 * @since 2019.02
323
		 * @category Developer
324
		 * @see controller/jobs/catalog/export/sitemap/location
325
		 * @see controller/jobs/catalog/export/sitemap/max-items
326
		 * @see controller/jobs/catalog/export/sitemap/max-query
327
		 * @see controller/jobs/catalog/export/sitemap/changefreq
328
		 */
329
		$default = array( 'gzip-mode' => 'wb' );
330
		$options = $config->get( 'controller/jobs/catalog/export/sitemap/container/options', $default );
331
332
		if( $location == null )
333
		{
334
			$msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/catalog/export/sitemap/location' );
335
			throw new \Aimeos\Controller\Jobs\Exception( $msg );
336
		}
337
338
		return \Aimeos\MW\Container\Factory::getContainer( $location, 'Directory', 'Gzip', $options );
339
	}
340
341
342
	/**
343
	 * Creates a new site map content object
344
	 *
345
	 * @param \Aimeos\MW\Container\Iface $container Container object
346
	 * @param int $filenum New file number
347
	 * @return \Aimeos\MW\Container\Content\Iface New content object
348
	 */
349
	protected function createContent( \Aimeos\MW\Container\Iface $container, int $filenum ) : \Aimeos\MW\Container\Content\Iface
350
	{
351
		/** controller/jobs/catalog/export/sitemap/template-header
352
		 * Relative path to the XML site map header template of the catalog site map job controller.
353
		 *
354
		 * The template file contains the XML code and processing instructions
355
		 * to generate the site map header. The configuration string is the path
356
		 * to the template file relative to the templates directory (usually in
357
		 * controller/jobs/templates).
358
		 *
359
		 * You can overwrite the template file configuration in extensions and
360
		 * provide alternative templates. These alternative templates should be
361
		 * named like the default one but with the string "standard" replaced by
362
		 * an unique name. You may use the name of your project for this. If
363
		 * you've implemented an alternative client class as well, "standard"
364
		 * should be replaced by the name of the new class.
365
		 *
366
		 * @param string Relative path to the template creating XML code for the site map header
367
		 * @since 2019.02
368
		 * @category Developer
369
		 * @see controller/jobs/catalog/export/sitemap/template-items
370
		 * @see controller/jobs/catalog/export/sitemap/template-footer
371
		 * @see controller/jobs/catalog/export/sitemap/template-index
372
		 */
373
		$tplconf = 'controller/jobs/catalog/export/sitemap/template-header';
374
		$default = 'catalog/export/sitemap-items-header-standard';
375
376
		$context = $this->context();
377
		$view = $context->view();
378
379
		$content = $container->create( $this->getFilename( $filenum ) );
380
		$content->add( $view->render( $context->config()->get( $tplconf, $default ) ) );
381
		$container->add( $content );
382
383
		return $content;
384
	}
385
386
387
	/**
388
	 * Closes the site map content object
389
	 *
390
	 * @param \Aimeos\MW\Container\Content\Iface $content
391
	 */
392
	protected function closeContent( \Aimeos\MW\Container\Content\Iface $content )
393
	{
394
		/** controller/jobs/catalog/export/sitemap/template-footer
395
		 * Relative path to the XML site map footer template of the catalog site map job controller.
396
		 *
397
		 * The template file contains the XML code and processing instructions
398
		 * to generate the site map footer. The configuration string is the path
399
		 * to the template file relative to the templates directory (usually in
400
		 * controller/jobs/templates).
401
		 *
402
		 * You can overwrite the template file configuration in extensions and
403
		 * provide alternative templates. These alternative templates should be
404
		 * named like the default one but with the string "standard" replaced by
405
		 * an unique name. You may use the name of your project for this. If
406
		 * you've implemented an alternative client class as well, "standard"
407
		 * should be replaced by the name of the new class.
408
		 *
409
		 * @param string Relative path to the template creating XML code for the site map footer
410
		 * @since 2019.02
411
		 * @category Developer
412
		 * @see controller/jobs/catalog/export/sitemap/template-header
413
		 * @see controller/jobs/catalog/export/sitemap/template-items
414
		 * @see controller/jobs/catalog/export/sitemap/template-index
415
		 */
416
		$tplconf = 'controller/jobs/catalog/export/sitemap/template-footer';
417
		$default = 'catalog/export/sitemap-items-footer-standard';
418
419
		$context = $this->context();
420
		$view = $context->view();
421
422
		$content->add( $view->render( $context->config()->get( $tplconf, $default ) ) );
423
	}
424
425
426
	/**
427
	 * Adds the content for the site map index file
428
	 *
429
	 * @param \Aimeos\MW\Container\Iface $container File container object
430
	 * @param array $files List of generated site map file names
431
	 */
432
	protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files )
433
	{
434
		$context = $this->context();
435
		$config = $context->config();
436
		$view = $context->view();
437
438
		/** controller/jobs/catalog/export/sitemap/template-index
439
		 * Relative path to the XML site map index template of the catalog site map job controller.
440
		 *
441
		 * The template file contains the XML code and processing instructions
442
		 * to generate the site map index files. The configuration string is the path
443
		 * to the template file relative to the templates directory (usually in
444
		 * controller/jobs/templates).
445
		 *
446
		 * You can overwrite the template file configuration in extensions and
447
		 * provide alternative templates. These alternative templates should be
448
		 * named like the default one but with the string "standard" replaced by
449
		 * an unique name. You may use the name of your project for this. If
450
		 * you've implemented an alternative client class as well, "standard"
451
		 * should be replaced by the name of the new class.
452
		 *
453
		 * @param string Relative path to the template creating XML code for the site map index
454
		 * @since 2019.02
455
		 * @category Developer
456
		 * @see controller/jobs/catalog/export/sitemap/template-header
457
		 * @see controller/jobs/catalog/export/sitemap/template-items
458
		 * @see controller/jobs/catalog/export/sitemap/template-footer
459
		 */
460
		$tplconf = 'controller/jobs/catalog/export/sitemap/template-index';
461
		$default = 'catalog/export/sitemap-index-standard';
462
463
		/** controller/jobs/catalog/export/sitemap/baseurl
464
		 * URL to the folder where the site maps can be accessed, without the filenames.
465
		 *
466
		 * The site maps must be publically available for download by the search
467
		 * engines. Individual site map files need a fully qualified URL in the index file.
468
		 *
469
		 * https://www.yourshop.com/your/sitemap/path/
470
		 *
471
		 * The location of the site map index file should then be
472
		 * added to the robots.txt in the document root of your domain:
473
		 *
474
		 * Sitemap: https://www.yourshop.com/your/sitemap/path/aimeos-catalog-sitemap-index.xml
475
		 *
476
		 * More details about site maps can be found at
477
		 * {@link http://www.sitemaps.org/protocol.html sitemaps.org}
478
		 *
479
		 * @param string Absolute URL
480
		 * @since 2019.06
481
		 * @category Developer
482
		 * @category User
483
		 * @see controller/jobs/catalog/export/sitemap/container/options
484
		 * @see controller/jobs/catalog/export/sitemap/max-items
485
		 * @see controller/jobs/catalog/export/sitemap/max-query
486
		 * @see controller/jobs/catalog/export/sitemap/changefreq
487
		 * @see controller/jobs/catalog/export/sitemap/location
488
		 */
489
		$baseUrl = $config->get( 'controller/jobs/catalog/export/sitemap/baseurl' );
490
491
		if( $baseUrl == null )
492
		{
493
			$msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/catalog/export/sitemap/baseurl' );
494
			throw new \Aimeos\Controller\Jobs\Exception( $msg );
495
		}
496
497
		$view->baseUrl = rtrim( $baseUrl, '/' ) . '/';
498
		$view->siteFiles = $files;
499
500
		$content = $container->create( 'aimeos-catalog-sitemap-index.xml' );
501
		$content->add( $view->render( $config->get( $tplconf, $default ) ) );
502
		$container->add( $content );
503
	}
504
505
506
	/**
507
	 * Exports the catalogs into the given container
508
	 *
509
	 * @param \Aimeos\MW\Container\Iface $container Container object
510
	 * @param bool|null $default TRUE to use default criteria, NULL for relaxed criteria
511
	 * @return array List of content (file) names
512
	 */
513
	protected function export( \Aimeos\MW\Container\Iface $container, ?bool $default = true ) : array
514
	{
515
		$config = $this->context()->config();
516
		/** controller/jobs/catalog/export/sitemap/domains
517
		 * List of associated items from other domains that should be fetched for the sitemap
518
		 *
519
		 * Catalogs consist not only of the base data but also of texts, media and
520
		 * other details. Those information is associated to the catalog via their lists.
521
		 * Using the "domains" option you can make more or less associated items available
522
		 * in the template.
523
		 *
524
		 * @param array List of domain names
525
		 * @since 2019.02
526
		 * @category Developer
527
		 * @category User
528
		 * @see controller/jobs/catalog/export/sitemap/container/options
529
		 * @see controller/jobs/catalog/export/sitemap/location
530
		 * @see controller/jobs/catalog/export/sitemap/max-items
531
		 * @see controller/jobs/catalog/export/sitemap/max-query
532
		 * @see controller/jobs/catalog/export/sitemap/changefreq
533
		 */
534
		$domains = $config->get( 'controller/jobs/catalog/export/sitemap/domains', ['text'] );
535
536
		/** controller/jobs/catalog/export/sitemap/max-items
537
		 * Maximum number of categories per site map
538
		 *
539
		 * Each site map file must not contain more than 50,000 links and it's
540
		 * size must be less than 10MB. If your catalog URLs are rather long
541
		 * and one of your site map files is bigger than 10MB, you should set
542
		 * the number of categories per file to a smaller value until each file
543
		 * is less than 10MB.
544
		 *
545
		 * More details about site maps can be found at
546
		 * {@link http://www.sitemaps.org/protocol.html sitemaps.org}
547
		 *
548
		 * @param integer Number of categories per file
549
		 * @since 2019.02
550
		 * @category Developer
551
		 * @category User
552
		 * @see controller/jobs/catalog/export/sitemap/container/options
553
		 * @see controller/jobs/catalog/export/sitemap/location
554
		 * @see controller/jobs/catalog/export/sitemap/max-query
555
		 * @see controller/jobs/catalog/export/sitemap/changefreq
556
		 * @see controller/jobs/catalog/export/sitemap/domains
557
		 */
558
		$maxItems = $config->get( 'controller/jobs/catalog/export/sitemap/max-items', 50000 );
559
560
		/** controller/jobs/catalog/export/sitemap/max-query
561
		 * Maximum number of categories per query
562
		 *
563
		 * The catalogs are fetched from the database in bunches for efficient
564
		 * retrieval. The higher the value, the lower the total time the database
565
		 * is busy finding the records. Higher values also means that record
566
		 * updates in the tables need to wait longer and the memory consumption
567
		 * of the PHP process is higher.
568
		 *
569
		 * Note: The value of max-query must be smaller than or equal to
570
		 * {@see controller/jobs/catalog/export/sitemap/max-items max-items}
571
		 *
572
		 * @param integer Number of categories per query
573
		 * @since 2019.02
574
		 * @category Developer
575
		 * @see controller/jobs/catalog/export/sitemap/container/options
576
		 * @see controller/jobs/catalog/export/sitemap/location
577
		 * @see controller/jobs/catalog/export/sitemap/max-items
578
		 * @see controller/jobs/catalog/export/sitemap/changefreq
579
		 * @see controller/jobs/catalog/export/sitemap/domains
580
		 */
581
		$maxQuery = $config->get( 'controller/jobs/catalog/export/sitemap/max-query', 1000 );
582
583
		$start = 0;
584
		$filenum = 1;
585
		$names = [];
586
587
		$manager = \Aimeos\MShop::create( $this->context(), 'catalog' );
588
589
		$search = $manager->filter( $default );
590
		$search->setSortations( array( $search->sort( '+', 'catalog.id' ) ) );
591
		$search->slice( 0, $maxQuery );
592
593
		$content = $this->createContent( $container, $filenum );
594
		$names[] = $content->getResource();
595
596
		do
597
		{
598
			$items = $manager->search( $search, $domains );
599
			$free = $maxItems * $filenum - $start;
600
			$count = count( $items );
601
602
			if( $free < $count )
603
			{
604
				$this->addItems( $content, $items->slice( 0, $free ) );
605
				$items = $items->slice( $free );
606
607
				$this->closeContent( $content );
608
				$content = $this->createContent( $container, ++$filenum );
609
				$names[] = $content->getResource();
610
			}
611
612
			$this->addItems( $content, $items );
613
614
			$start += $count;
615
			$search->slice( $start, $maxQuery );
616
		}
617
		while( $count >= $search->getLimit() );
618
619
		$this->closeContent( $content );
620
621
		return $names;
622
	}
623
624
625
	/**
626
	 * Returns the file name for the new content file
627
	 *
628
	 * @param int $number Current file number
629
	 * @return string New file name
630
	 */
631
	protected function getFilename( int $number ) : string
632
	{
633
		return sprintf( 'aimeos-catalog-sitemap-%d.xml', $number );
634
	}
635
636
637
	/**
638
	 * Returns the available locale items for the current site
639
	 *
640
	 * @return \Aimeos\Map List of locale items
641
	 */
642
	protected function locales() : \Aimeos\Map
643
	{
644
		if( !isset( $this->locales ) )
645
		{
646
			$manager = \Aimeos\MShop::create( $this->context(), 'locale' );
647
			$filter = $manager->filter()->add( ['locale.siteid' => $this->context()->locale()->getSiteId()] );
648
649
			$this->locales = $manager->search( $filter->order( 'locale.position' )->slice( 0, 10000 ) );
0 ignored issues
show
Bug Best Practice introduced by
The property locales does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
650
		}
651
652
		return $this->locales;
653
	}
654
}
655