Completed
Push — master ( 6787d3...0ff3a3 )
by Aimeos
02:36
created

JobsCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 104
rs 10
c 2
b 0
f 0
wmc 6
lcom 1
cbo 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
B fire() 0 31 3
A getArguments() 0 7 1
A getOptions() 0 4 1
A getContext() 0 19 1
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 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 fire()
45
	{
46
		$aimeos = $this->getLaravel()->make( '\Aimeos\Shop\Base\Aimeos' )->get();
47
		$context = $this->getContext();
48
49
		$process = $context->getProcess();
0 ignored issues
show
Bug introduced by
The method getProcess() does not seem to exist on object<Aimeos\MShop\Context\Item\Standard>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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()
83
	{
84
		return array(
85
			array( 'jobs', InputArgument::REQUIRED, 'One or more job controller names like "admin/job customer/email/watch"' ),
86
			array( 'site', InputArgument::OPTIONAL, 'Site codes to execute the jobs for like "default unittest" (none for all)' ),
87
		);
88
	}
89
90
	/**
91
	 * Get the console command options.
92
	 *
93
	 * @return array
94
	 */
95
	protected function getOptions()
96
	{
97
		return array();
98
	}
99
100
101
	/**
102
	 * Returns a context object
103
	 *
104
	 * @return \Aimeos\MShop\Context\Item\Standard Context object
105
	 */
106
	protected function getContext()
107
	{
108
		$lv = $this->getLaravel();
109
		$aimeos = $lv->make( '\Aimeos\Shop\Base\Aimeos' )->get();
110
		$context = $lv->make( '\Aimeos\Shop\Base\Context' )->get( false, 'command' );
111
112
		$tmplPaths = $aimeos->getCustomPaths( 'controller/jobs/templates' );
113
		$view = $lv->make( '\Aimeos\Shop\Base\View' )->create( $context, $tmplPaths );
114
115
		$langManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context )->getSubManager( 'language' );
116
		$langids = array_keys( $langManager->searchItems( $langManager->createSearch( true ) ) );
117
		$i18n = $lv->make( '\Aimeos\Shop\Base\I18n' )->get( $langids );
118
119
		$context->setEditor( 'aimeos:jobs' );
120
		$context->setView( $view );
121
		$context->setI18n( $i18n );
122
123
		return $context;
124
	}
125
}
126