1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||
5 | * @copyright Aimeos (aimeos.org), 2015-2023 |
||
6 | */ |
||
7 | |||
8 | |||
9 | namespace Aimeos\Shop\Command; |
||
10 | |||
11 | use Illuminate\Console\Command; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * Common base class for all commands |
||
16 | */ |
||
17 | abstract class AbstractCommand extends Command |
||
18 | { |
||
19 | /** |
||
20 | * Executes the function for all given sites |
||
21 | * |
||
22 | * @param \Aimeos\MShop\ContextIface $context Context object |
||
23 | * @param \Closure $fcn Function to execute |
||
24 | * @param array|string|null $sites Site codes |
||
25 | */ |
||
26 | protected function exec( \Aimeos\MShop\ContextIface $context, \Closure $fcn, $sites ) |
||
27 | { |
||
28 | $process = $context->process(); |
||
29 | $aimeos = $this->getLaravel()->make( 'aimeos' )->get(); |
||
30 | |||
31 | $siteManager = \Aimeos\MShop::create( $context, 'locale/site' ); |
||
32 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||
33 | $filter = $siteManager->filter(); |
||
34 | $start = 0; |
||
35 | |||
36 | if( !empty( $sites ) ) { |
||
37 | $filter->add( ['locale.site.code' => !is_array( $sites ) ? explode( ' ', (string) $sites ) : $sites] ); |
||
38 | } |
||
39 | |||
40 | do |
||
41 | { |
||
42 | $siteItems = $siteManager->search( $filter->slice( $start ) ); |
||
43 | |||
44 | foreach( $siteItems as $siteItem ) |
||
45 | { |
||
46 | \Aimeos\MShop::cache( true ); |
||
47 | \Aimeos\MAdmin::cache( true ); |
||
48 | |||
49 | $localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
50 | $localeItem->setLanguageId( null ); |
||
51 | $localeItem->setCurrencyId( null ); |
||
52 | |||
53 | $lcontext = clone $context; |
||
54 | $lcontext->setLocale( $localeItem ); |
||
55 | |||
56 | $tmplPaths = $aimeos->getTemplatePaths( 'controller/jobs/templates', $siteItem->getTheme() ); |
||
57 | $view = $this->getLaravel()->make( 'aimeos.view' )->create( $lcontext, $tmplPaths ); |
||
58 | $lcontext->setView( $view ); |
||
59 | |||
60 | $config = $lcontext->config(); |
||
61 | $config->apply( $siteItem->getConfig() ); |
||
62 | |||
63 | $process->start( $fcn, [$lcontext, $aimeos], false ); |
||
64 | } |
||
65 | |||
66 | $count = count( $siteItems ); |
||
67 | $start += $count; |
||
68 | } |
||
69 | while( $count === $filter->getLimit() ); |
||
70 | |||
71 | $process->wait(); |
||
72 | } |
||
73 | } |