1 | <?php |
||
22 | class JobsCommand extends AbstractCommand |
||
23 | { |
||
24 | /** |
||
25 | * The console command name. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $name = 'aimeos:jobs'; |
||
30 | |||
31 | /** |
||
32 | * The console command description. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $description = 'Executes the job controllers'; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Execute the console command. |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function handle() |
||
45 | { |
||
46 | $aimeos = $this->getLaravel()->make( '\Aimeos\Shop\Base\Aimeos' )->get(); |
||
47 | $context = $this->getContext(); |
||
48 | |||
49 | $process = $context->getProcess(); |
||
50 | $jobs = explode( ' ', $this->argument( 'jobs' ) ); |
||
51 | $localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context ); |
||
52 | |||
53 | foreach( $this->getSiteItems( $context, $this->argument( 'site' ) ) as $siteItem ) |
||
54 | { |
||
55 | $localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
||
56 | $localeItem->setLanguageId( null ); |
||
57 | $localeItem->setCurrencyId( null ); |
||
58 | |||
59 | $context->setLocale( $localeItem ); |
||
60 | |||
61 | $this->info( sprintf( 'Executing the Aimeos jobs for "%s"', $siteItem->getCode() ) ); |
||
62 | |||
63 | foreach( $jobs as $jobname ) |
||
64 | { |
||
65 | $fcn = function( $context, $aimeos, $jobname ) { |
||
66 | \Aimeos\Controller\Jobs\Factory::createController( $context, $aimeos, $jobname )->run(); |
||
67 | }; |
||
68 | |||
69 | $process->start( $fcn, [$context, $aimeos, $jobname], true ); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | $process->wait(); |
||
74 | } |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Get the console command arguments. |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | protected function getArguments() |
||
89 | |||
90 | /** |
||
91 | * Get the console command options. |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | protected function getOptions() |
||
99 | |||
100 | |||
101 | /** |
||
102 | * Returns a context object |
||
103 | * |
||
104 | * @return \Aimeos\MShop\Context\Item\Standard Context object |
||
105 | */ |
||
106 | protected function getContext() |
||
125 | } |
||
126 |