Issues (66)

src/Command/Jobs.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package Slim
7
 * @subpackage Command
8
 */
9
10
namespace Aimeos\Slim\Command;
11
12
13
/**
14
 * Aimeos cache command class
15
 *
16
 * @package Slim
17
 * @subpackage Command
18
 */
19
class Jobs extends Base implements Iface
20
{
21
	/**
22
	 * Returns the command usage and options
23
	 *
24
	 * @return string Command usage and options
25
	 */
26
	public static function usage() : string
27
	{
28
		return "Usage: php job.php [--extdir=<path>]* [--config=<path>|<file>]* [--routes=<file>] \"job1 [job2]*\" [\"sitecode1 [sitecode2]*\"]\n";
29
	}
30
31
32
	/**
33
	 * Executes the command
34
	 *
35
	 * @param array $argv Associative array from $_SERVER['argv']
36
	 */
37
	public static function run( array $argv )
38
	{
39
		array_shift( $argv );
40
		$options = self::getOptions( $argv );
41
42
		if( ( $jobs = array_shift( $argv ) ) === null ) {
43
			throw new \Aimeos\Slim\Command\Exception();
44
		}
45
		$sites = array_shift( $argv );
46
47
		$config = self::getConfig( $options );
48
49
		$app = new \Slim\App( $config );
50
		$aimeos = new \Aimeos\Slim\Bootstrap( $app, $config );
51
		$aimeos->setup( ( isset( $options['extdir'] ) ? $options['extdir'] : './ext' ) )
52
			->routes( ( isset( $options['routes'] ) ? $options['routes'] : './src/aimeos-routes.php' ) );
53
54
		$container = $app->getContainer();
55
		$context = self::getContext( $container );
56
57
		$siteItems = self::getSiteItems( $context, $sites );
58
		self::execute( $container->get( 'aimeos' ), $context, $siteItems, $jobs );
59
	}
60
61
62
	/**
63
	 * Returns the configuration based on the given options
64
	 *
65
	 * @param array $options Associative list of given options
66
	 * @return array Multi-dimensional array of configuration settings
67
	 */
68
	protected static function getConfig( array $options ) : array
69
	{
70
		$config = array();
71
72
		if( isset( $options['config'] ) )
73
		{
74
			foreach( (array) $options['config'] as $path )
75
			{
76
				if( is_file( $path ) ) {
77
					$config = array_replace_recursive( $config, require $path );
78
				}
79
			}
80
		}
81
82
		return $config;
83
	}
84
85
86
	/**
87
	 * Returns a new context object
88
	 *
89
	 * @param \Psr\Container\ContainerInterface $container Dependency injection container
90
	 * @return \Aimeos\MShop\Context\Item\Iface Context object
91
	 */
92
	protected static function getContext( \Psr\Container\ContainerInterface $container ) : \Aimeos\MShop\Context\Item\Iface
93
	{
94
		$aimeos = $container->get( 'aimeos' );
95
		$context = $container->get( 'aimeos.context' )->get( false, array(), 'command' );
96
97
		$env = \Slim\Http\Environment::mock();
98
		$request = \Slim\Http\Request::createFromEnvironment( $env );
99
		$response = new \Slim\Http\Response();
100
101
		$tmplPaths = $aimeos->getCustomPaths( 'controller/jobs/templates' );
102
		$view = $container->get( 'aimeos.view' )->create( $context, $request, $response, array(), $tmplPaths );
103
104
		$langManager = \Aimeos\MShop::create( $context, 'locale/language' );
105
		$langids = $langManager->searchItems( $langManager->createSearch( true ) )->keys()->toArray();
106
		$i18n = $container->get( 'aimeos.i18n' )->get( $langids );
107
108
		$context->setEditor( 'aimeos:jobs' );
109
		$context->setView( $view );
110
		$context->setI18n( $i18n );
111
112
		return $context;
113
	}
114
115
116
	/**
117
	 * Removes the cached data for the given sites
118
	 *
119
	 * @param \Aimeos\Bootstrap $aimeos Aimeos bootstrap object
120
	 * @param \Aimeos\MShop\Context\Item\Iface $ctx Context object
121
	 * @param \Aimeos\Map $siteItems List of site items implementing \Aimeos\MShop\Locale\Site\Iface
122
	 */
123
	protected static function execute( \Aimeos\Bootstrap $aimeos, \Aimeos\MShop\Context\Item\Iface $ctx, \Aimeos\Map $siteItems, $jobs )
124
	{
125
		$process = $ctx->getProcess();
126
		$localeManager = \Aimeos\MShop::create( $ctx, 'locale' );
127
128
		foreach( $siteItems as $siteItem )
129
		{
130
			$localeItem = $localeManager->bootstrap( $siteItem->getCode(), 'en', '', false );
0 ignored issues
show
The method bootstrap() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Locale\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Index\Manager\DBBase or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Price\Manager\Property\Type\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Price\Manager\Property\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

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

130
			/** @scrutinizer ignore-call */ 
131
   $localeItem = $localeManager->bootstrap( $siteItem->getCode(), 'en', '', false );
Loading history...
131
			$localeItem->setLanguageId( null );
132
			$localeItem->setCurrencyId( null );
133
134
			$ctx->setLocale( $localeItem );
135
136
			printf( "Executing the Aimeos jobs for \"%s\"\n", $siteItem->getCode() );
137
138
			foreach( (array) explode( ' ', $jobs ) as $jobname )
139
			{
140
				$fcn = function( $ctx, $aimeos, $jobname ) {
141
					\Aimeos\Controller\Jobs::create( $ctx, $aimeos, $jobname )->run();
142
				};
143
144
				$process->start( $fcn, [$ctx, $aimeos, $jobname], true );
145
			}
146
		}
147
148
		$process->wait();
149
	}
150
}
151