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
|
|
|
* Executes the command |
23
|
|
|
* |
24
|
|
|
* @param array $argv Associative array from $_SERVER['argv'] |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
public static function usage() |
27
|
|
|
{ |
28
|
|
|
return "Usage: php job.php [--extdir=<path>]* [--config=<path>|<file>]* \"job1 [job2]*\" [\"sitecode1 [sitecode2]*\"]\n"; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns the command usage and options |
34
|
|
|
* |
35
|
|
|
* @return string Command usage and options |
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
|
|
|
|
53
|
|
|
$container = $app->getContainer(); |
54
|
|
|
$context = self::getContext( $container ); |
55
|
|
|
|
56
|
|
|
$siteItems = self::getSiteItems( $context, $sites ); |
57
|
|
|
self::execute( $container->get( 'aimeos' ), $context, $siteItems, $jobs ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the configuration based on the given options |
63
|
|
|
* |
64
|
|
|
* @param array $options Associative list of given options |
65
|
|
|
* @return array Multi-dimensional array of configuration settings |
66
|
|
|
*/ |
67
|
|
|
protected static function getConfig( array $options ) |
68
|
|
|
{ |
69
|
|
|
$config = array(); |
70
|
|
|
|
71
|
|
View Code Duplication |
if( isset( $options['config'] ) ) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
foreach( (array) $options['config'] as $path ) |
74
|
|
|
{ |
75
|
|
|
if( is_file( $path ) ) { |
76
|
|
|
$config = array_replace_recursive( $config, require $path ); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $config; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns a new context object |
87
|
|
|
* |
88
|
|
|
* @param \Interop\Container\ContainerInterface $container Dependency injection container |
89
|
|
|
* @return \Aimeos\MShop\Context\Item\Standard Context object |
90
|
|
|
*/ |
91
|
|
|
protected static function getContext( \Interop\Container\ContainerInterface $container ) |
92
|
|
|
{ |
93
|
|
|
$aimeos = $container->get( 'aimeos' ); |
94
|
|
|
$context = $container->get( 'aimeos_context' )->get( false ); |
95
|
|
|
|
96
|
|
|
$env = \Slim\Http\Environment::mock(); |
97
|
|
|
$request = \Slim\Http\Request::createFromEnvironment( $env ); |
98
|
|
|
$response = new \Slim\Http\Response(); |
99
|
|
|
|
100
|
|
|
$tmplPaths = $aimeos->getCustomPaths( 'controller/jobs/templates' ); |
101
|
|
|
$view = $container->get( 'aimeos_view' )->create( $request, $response, array(), $tmplPaths ); |
102
|
|
|
|
103
|
|
|
$langManager = \Aimeos\MShop\Factory::createManager( $context, 'locale/language' ); |
104
|
|
|
$langids = array_keys( $langManager->searchItems( $langManager->createSearch( true ) ) ); |
105
|
|
|
$i18n = $container->get( 'aimeos_i18n' )->get( $langids ); |
106
|
|
|
|
107
|
|
|
$context->setEditor( 'aimeos:jobs' ); |
108
|
|
|
$context->setView( $view ); |
109
|
|
|
$context->setI18n( $i18n ); |
110
|
|
|
|
111
|
|
|
return $context; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Removes the cached data for the given sites |
117
|
|
|
* |
118
|
|
|
* @param \Aimeos\Bootstrap $aimeos Aimeos bootstrap object |
119
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $ctx Context object |
120
|
|
|
* @param array $siteItems List of site items implementing \Aimeos\MShop\Locale\Site\Iface |
121
|
|
|
*/ |
122
|
|
|
protected static function execute( \Aimeos\Bootstrap $aimeos, \Aimeos\MShop\Context\Item\Iface $ctx, array $siteItems, $jobs ) |
123
|
|
|
{ |
124
|
|
|
$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx ); |
125
|
|
|
|
126
|
|
|
foreach( $siteItems as $siteItem ) |
127
|
|
|
{ |
128
|
|
|
$localeItem = $localeManager->bootstrap( $siteItem->getCode(), 'en', '', false ); |
129
|
|
|
$ctx->setLocale( $localeItem ); |
130
|
|
|
|
131
|
|
|
printf( "Executing the Aimeos jobs for \"%s\"\n", $siteItem->getCode() ); |
132
|
|
|
|
133
|
|
|
foreach( (array) explode( ' ', $jobs ) as $jobname ) { |
134
|
|
|
\Aimeos\Controller\Jobs\Factory::createController( $ctx, $aimeos, $jobname )->run(); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.