1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package laravel |
7
|
|
|
* @subpackage Command |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Command; |
12
|
|
|
|
13
|
|
|
use Illuminate\Console\Command; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Command for executing the Aimeos job controllers |
19
|
|
|
* @package laravel |
20
|
|
|
* @subpackage Command |
21
|
|
|
*/ |
22
|
|
|
class JobsCommand extends AbstractCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The name and signature of the console command. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $signature = 'aimeos:jobs |
30
|
|
|
{jobs : One or more job controller names like "admin/job customer/email/watch"} |
31
|
|
|
{site? : Site codes to execute the jobs for like "default unittest" (none for all)} |
32
|
|
|
'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The console command description. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $description = 'Executes the job controllers'; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Execute the console command. |
44
|
|
|
* |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
public function handle() |
48
|
|
|
{ |
49
|
|
|
$aimeos = $this->getLaravel()->make( '\Aimeos\Shop\Base\Aimeos' )->get(); |
50
|
|
|
$context = $this->getContext(); |
51
|
|
|
|
52
|
|
|
$process = $context->getProcess(); |
53
|
|
|
$jobs = explode( ' ', $this->argument( 'jobs' ) ); |
54
|
|
|
$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context ); |
55
|
|
|
|
56
|
|
|
foreach( $this->getSiteItems( $context, $this->argument( 'site' ) ) as $siteItem ) |
57
|
|
|
{ |
58
|
|
|
$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
59
|
|
|
$localeItem->setLanguageId( null ); |
60
|
|
|
$localeItem->setCurrencyId( null ); |
61
|
|
|
|
62
|
|
|
$context->setLocale( $localeItem ); |
63
|
|
|
|
64
|
|
|
$this->info( sprintf( 'Executing the Aimeos jobs for "%s"', $siteItem->getCode() ) ); |
65
|
|
|
|
66
|
|
|
foreach( $jobs as $jobname ) |
67
|
|
|
{ |
68
|
|
|
$fcn = function( $context, $aimeos, $jobname ) { |
69
|
|
|
\Aimeos\Controller\Jobs\Factory::createController( $context, $aimeos, $jobname )->run(); |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
$process->start( $fcn, [$context, $aimeos, $jobname], true ); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$process->wait(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns a context object |
82
|
|
|
* |
83
|
|
|
* @return \Aimeos\MShop\Context\Item\Standard Context object |
84
|
|
|
*/ |
85
|
|
|
protected function getContext() |
86
|
|
|
{ |
87
|
|
|
$lv = $this->getLaravel(); |
88
|
|
|
$aimeos = $lv->make( '\Aimeos\Shop\Base\Aimeos' )->get(); |
89
|
|
|
$context = $lv->make( '\Aimeos\Shop\Base\Context' )->get( false, 'command' ); |
90
|
|
|
|
91
|
|
|
$tmplPaths = $aimeos->getCustomPaths( 'controller/jobs/templates' ); |
92
|
|
|
$view = $lv->make( '\Aimeos\Shop\Base\View' )->create( $context, $tmplPaths ); |
93
|
|
|
|
94
|
|
|
$langManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context )->getSubManager( 'language' ); |
95
|
|
|
$langids = array_keys( $langManager->searchItems( $langManager->createSearch( true ) ) ); |
96
|
|
|
$i18n = $lv->make( '\Aimeos\Shop\Base\I18n' )->get( $langids ); |
97
|
|
|
|
98
|
|
|
$context->setEditor( 'aimeos:jobs' ); |
99
|
|
|
$context->setView( $view ); |
100
|
|
|
$context->setI18n( $i18n ); |
101
|
|
|
|
102
|
|
|
return $context; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|