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