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 | * Adds the configuration options from the input object to the given context |
||
21 | * |
||
22 | * @param \Aimeos\MShop\ContextIface $ctx Context object |
||
23 | */ |
||
24 | protected function addConfig( \Aimeos\MShop\ContextIface $ctx ) : \Aimeos\MShop\ContextIface |
||
25 | { |
||
26 | $config = $ctx->config(); |
||
27 | |||
28 | foreach( (array) $this->option( 'option' ) as $option ) |
||
29 | { |
||
30 | list( $name, $value ) = explode( ':', $option ); |
||
31 | $config->set( $name, $value ); |
||
32 | } |
||
33 | |||
34 | return $ctx; |
||
35 | } |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Executes the function for all given sites |
||
40 | * |
||
41 | * @param \Aimeos\MShop\ContextIface $context Context object |
||
42 | * @param \Closure $fcn Function to execute |
||
43 | * @param array|string|null $sites Site codes |
||
44 | */ |
||
45 | protected function exec( \Aimeos\MShop\ContextIface $context, \Closure $fcn, $sites ) |
||
46 | { |
||
47 | $process = $context->process(); |
||
48 | $aimeos = $this->getLaravel()->make( 'aimeos' )->get(); |
||
49 | |||
50 | $siteManager = \Aimeos\MShop::create( $context, 'locale/site' ); |
||
51 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||
52 | $filter = $siteManager->filter(); |
||
53 | $start = 0; |
||
54 | |||
55 | if( !empty( $sites ) ) { |
||
56 | $filter->add( ['locale.site.code' => !is_array( $sites ) ? explode( ' ', (string) $sites ) : $sites] ); |
||
57 | } |
||
58 | |||
59 | do |
||
60 | { |
||
61 | $siteItems = $siteManager->search( $filter->slice( $start ) ); |
||
62 | |||
63 | foreach( $siteItems as $siteItem ) |
||
64 | { |
||
65 | \Aimeos\MShop::cache( true ); |
||
66 | \Aimeos\MAdmin::cache( true ); |
||
67 | |||
68 | $localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
69 | $localeItem->setLanguageId( null ); |
||
70 | $localeItem->setCurrencyId( null ); |
||
71 | |||
72 | $lcontext = clone $context; |
||
73 | $lcontext->setLocale( $localeItem ); |
||
74 | |||
75 | $tmplPaths = $aimeos->getTemplatePaths( 'controller/jobs/templates', $siteItem->getTheme() ); |
||
76 | $view = $this->getLaravel()->make( 'aimeos.view' )->create( $lcontext, $tmplPaths ); |
||
77 | $lcontext->setView( $view ); |
||
78 | |||
79 | $config = $lcontext->config(); |
||
80 | $config->apply( $siteItem->getConfig() ); |
||
81 | |||
82 | $process->start( $fcn, [$lcontext, $aimeos], false ); |
||
83 | } |
||
84 | |||
85 | $count = count( $siteItems ); |
||
86 | $start += $count; |
||
87 | } |
||
88 | while( $count === $filter->getLimit() ); |
||
89 | |||
90 | $process->wait(); |
||
91 | } |
||
92 | } |