1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2016 |
6
|
|
|
* @package symfony |
7
|
|
|
* @subpackage Command |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\ShopBundle\Command; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\Container; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Executes the job controllers. |
22
|
|
|
* |
23
|
|
|
* @package symfony |
24
|
|
|
* @subpackage Command |
25
|
|
|
*/ |
26
|
|
|
#[AsCommand(name: 'aimeos:jobs', description: 'Executes the job controllers')] |
27
|
|
|
class JobsCommand extends Command |
28
|
|
|
{ |
29
|
|
|
private $container; |
30
|
|
|
protected static $defaultName = 'aimeos:jobs'; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function __construct( Container $container ) |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
$this->container = $container; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Configures the command name and description. |
42
|
|
|
*/ |
43
|
|
|
protected function configure() |
44
|
|
|
{ |
45
|
|
|
$this->setName( self::$defaultName ); |
46
|
|
|
$this->setDescription( 'Executes the job controllers' ); |
47
|
|
|
$this->addArgument( 'jobs', InputArgument::REQUIRED, 'One or more job controller names like "admin/job customer/email/watch"' ); |
48
|
|
|
$this->addArgument( 'site', InputArgument::OPTIONAL, 'Site codes to execute the jobs for like "default unittest" (none for all)' ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Executes the job controllers. |
54
|
|
|
* |
55
|
|
|
* @param InputInterface $input Input object |
56
|
|
|
* @param OutputInterface $output Output object |
57
|
|
|
*/ |
58
|
|
|
protected function execute( InputInterface $input, OutputInterface $output ) |
59
|
|
|
{ |
60
|
|
|
$context = $this->context(); |
61
|
|
|
$process = $context->process(); |
62
|
|
|
$aimeos = $this->container->get( 'aimeos' )->get(); |
63
|
|
|
|
64
|
|
|
$jobs = explode( ' ', $input->getArgument( 'jobs' ) ); |
65
|
|
|
$localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
66
|
|
|
|
67
|
|
|
foreach( $this->getSiteItems( $context, $input ) as $siteItem ) |
68
|
|
|
{ |
69
|
|
|
\Aimeos\MShop::cache( true ); |
70
|
|
|
\Aimeos\MAdmin::cache( true ); |
71
|
|
|
|
72
|
|
|
$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
|
|
|
|
73
|
|
|
$localeItem->setLanguageId( null ); |
74
|
|
|
$localeItem->setCurrencyId( null ); |
75
|
|
|
$context->setLocale( $localeItem ); |
76
|
|
|
|
77
|
|
|
$config = $context->config(); |
78
|
|
|
foreach( $localeItem->getSiteItem()->getConfig() as $key => $value ) { |
79
|
|
|
$config->set( $key, $value ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$output->writeln( sprintf( 'Executing the Aimeos jobs for "<info>%s</info>"', $siteItem->getCode() ) ); |
83
|
|
|
|
84
|
|
|
foreach( $jobs as $jobname ) |
85
|
|
|
{ |
86
|
|
|
$fcn = function( $context, $aimeos, $jobname ) { |
87
|
|
|
\Aimeos\Controller\Jobs::create( $context, $aimeos, $jobname )->run(); |
88
|
|
|
}; |
89
|
|
|
|
90
|
|
|
$process->start( $fcn, [$context, $aimeos, $jobname], false ); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$process->wait(); |
95
|
|
|
return 0; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns a context object |
101
|
|
|
* |
102
|
|
|
* @return \Aimeos\MShop\ContextIface Context object |
103
|
|
|
*/ |
104
|
|
|
protected function context() : \Aimeos\MShop\ContextIface |
105
|
|
|
{ |
106
|
|
|
$container = $this->container; |
107
|
|
|
$aimeos = $container->get( 'aimeos' )->get(); |
108
|
|
|
$context = $container->get( 'aimeos.context' )->get( false, 'command' ); |
109
|
|
|
|
110
|
|
|
$tmplPaths = $aimeos->getTemplatePaths( 'controller/jobs/templates' ); |
111
|
|
|
$view = $container->get( 'aimeos.view' )->create( $context, $tmplPaths ); |
112
|
|
|
|
113
|
|
|
$langManager = \Aimeos\MShop::create( $context, 'locale/language' ); |
114
|
|
|
$langids = $langManager->search( $langManager->filter( true ) )->keys()->toArray(); |
115
|
|
|
$i18n = $this->container->get( 'aimeos.i18n' )->get( $langids ); |
116
|
|
|
|
117
|
|
|
$context->setEditor( 'aimeos:jobs' ); |
118
|
|
|
$context->setView( $view ); |
119
|
|
|
$context->setI18n( $i18n ); |
120
|
|
|
|
121
|
|
|
return $context; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|