Passed
Push — master ( a8f043...2c00e3 )
by Aimeos
19:33 queued 03:42
created

JobsCommand::addConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 11
rs 10
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
		$this->addOption( 'option', null, InputOption::VALUE_REQUIRED, 'Optional setup configuration, name and value are separated by ":" like "setup/default/demo:1"', [] );
0 ignored issues
show
Bug introduced by
The type Aimeos\ShopBundle\Command\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
	}
51
52
53
	/**
54
	 * Executes the job controllers.
55
	 *
56
	 * @param InputInterface $input Input object
57
	 * @param OutputInterface $output Output object
58
	 */
59
	protected function execute( InputInterface $input, OutputInterface $output )
60
	{
61
		$context = $this->context();
62
		$process = $context->process();
63
		$aimeos = $this->container->get( 'aimeos' )->get();
64
65
		$jobs = explode( ' ', $input->getArgument( 'jobs' ) );
66
		$localeManager = \Aimeos\MShop::create( $context, 'locale' );
67
68
		foreach( $this->getSiteItems( $context, $input ) as $siteItem )
69
		{
70
			\Aimeos\MShop::cache( true );
71
			\Aimeos\MAdmin::cache( true );
72
73
			$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false );
0 ignored issues
show
Bug introduced by
The method bootstrap() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Group\Manager\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MShop\Common\Manager\Type\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Basket\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
			/** @scrutinizer ignore-call */ 
74
   $localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false );
Loading history...
74
			$localeItem->setLanguageId( null );
75
			$localeItem->setCurrencyId( null );
76
			$context->setLocale( $localeItem );
77
78
			$config = $context->config();
79
			foreach( $localeItem->getSiteItem()->getConfig() as $key => $value ) {
80
				$config->set( $key, $value );
81
			}
82
83
			$output->writeln( sprintf( 'Executing the Aimeos jobs for "<info>%s</info>"', $siteItem->getCode() ) );
84
85
			foreach( $jobs as $jobname )
86
			{
87
				$fcn = function( $context, $aimeos, $jobname ) {
88
					\Aimeos\Controller\Jobs::create( $context, $aimeos, $jobname )->run();
89
				};
90
91
				$process->start( $fcn, [$context, $aimeos, $jobname], false );
92
			}
93
		}
94
95
		$process->wait();
96
		return 0;
97
	}
98
99
100
	/**
101
	 * Adds the configuration options from the input object to the given context
102
	 *
103
	 * @param \Aimeos\MShop\ContextIface $ctx Context object
104
	 * @param InputInterface $input Input object
105
	 */
106
	protected function addConfig( \Aimeos\MShop\ContextIface $ctx, InputInterface $input ) : \Aimeos\MShop\ContextIface
107
	{
108
		$config = $ctx->config();
109
110
		foreach( (array) $input->getOption( 'option' ) as $option )
111
		{
112
			list( $name, $value ) = explode( ':', $option );
113
			$config->set( $name, $value );
114
		}
115
116
		return $ctx;
117
	}
118
119
120
	/**
121
	 * Returns a context object
122
	 *
123
	 * @return \Aimeos\MShop\ContextIface Context object
124
	 */
125
	protected function context() : \Aimeos\MShop\ContextIface
126
	{
127
		$container = $this->container;
128
		$aimeos = $container->get( 'aimeos' )->get();
129
		$context = $container->get( 'aimeos.context' )->get( false, 'command' );
130
131
		$tmplPaths = $aimeos->getTemplatePaths( 'controller/jobs/templates' );
132
		$view = $container->get( 'aimeos.view' )->create( $context, $tmplPaths );
133
134
		$langManager = \Aimeos\MShop::create( $context, 'locale/language' );
135
		$langids = $langManager->search( $langManager->filter( true ) )->keys()->toArray();
136
		$i18n = $this->container->get( 'aimeos.i18n' )->get( $langids );
137
138
		$context->setSession(new \Aimeos\Base\Session\None());
139
		$context->setCache(new \Aimeos\Base\Cache\None());
140
141
		$context->setEditor( 'aimeos:jobs' );
142
		$context->setView( $view );
143
		$context->setI18n( $i18n );
144
145
		return $this->addConfig( $context );
0 ignored issues
show
Bug introduced by
The call to Aimeos\ShopBundle\Command\JobsCommand::addConfig() has too few arguments starting with input. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

145
		return $this->/** @scrutinizer ignore-call */ addConfig( $context );

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
146
	}
147
}
148