1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license GPLv3, http://www.gnu.org/copyleft/gpl.html |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2017 |
7
|
|
|
* @package TYPO3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Aimeos\Aimeos\Scheduler; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Aimeos\Aimeos; |
14
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
|
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Aimeos common scheduler class. |
20
|
|
|
* |
21
|
|
|
* @package TYPO3 |
22
|
|
|
*/ |
23
|
|
|
class Base |
24
|
|
|
{ |
25
|
|
|
protected static $router; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Execute the list of jobs for the given sites |
30
|
|
|
* |
31
|
|
|
* @param array $tsconf Multi-dimensional array of configuration options (replaced) |
32
|
|
|
* @param array $conf Multi-dimensional array of configuration options (merged) |
33
|
|
|
* @param array $jobs List of job names |
34
|
|
|
* @param array|string $sites List of site names |
35
|
|
|
*/ |
36
|
|
|
public static function execute(array $tsconf, array $conf, array $jobs, $sites, ?string $pid = null) |
37
|
|
|
{ |
38
|
|
|
$aimeos = Aimeos\Base::aimeos(); |
39
|
|
|
$context = self::context($tsconf, $conf, $pid); |
40
|
|
|
$process = $context->process(); |
41
|
|
|
|
42
|
|
|
// Reset before child processes are spawned to avoid lost DB connections afterwards |
43
|
|
|
GeneralUtility::makeInstance('TYPO3\CMS\Core\Database\ConnectionPool')->resetConnections(); |
44
|
|
|
|
45
|
|
|
$manager = \Aimeos\MShop::create($context, 'locale'); |
46
|
|
|
|
47
|
|
|
foreach (self::getSiteItems($context, $sites) as $siteItem) { |
48
|
|
|
\Aimeos\MShop::cache(true); |
49
|
|
|
\Aimeos\MAdmin::cache(true); |
50
|
|
|
|
51
|
|
|
$localeItem = $manager->bootstrap($siteItem->getCode(), '', '', false); |
|
|
|
|
52
|
|
|
$localeItem->setLanguageId(null); |
53
|
|
|
$localeItem->setCurrencyId(null); |
54
|
|
|
|
55
|
|
|
$context->setLocale($localeItem); |
56
|
|
|
|
57
|
|
|
foreach ($jobs as $jobname) { |
58
|
|
|
$fcn = function($context, $aimeos, $jobname) { |
59
|
|
|
\Aimeos\Controller\Jobs::create($context, $aimeos, $jobname)->run(); |
60
|
|
|
}; |
61
|
|
|
|
62
|
|
|
$process->start($fcn, [$context, $aimeos, $jobname], false); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$process->wait(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the current context. |
72
|
|
|
* |
73
|
|
|
* @param array $tsconf Multi-dimensional associative list of key/value pairs |
74
|
|
|
* @return \Aimeos\MShop\ContextIface Context object |
75
|
|
|
*/ |
76
|
|
|
public static function context(array $tsconf = [], array $conf = [], ?string $pid = null) : \Aimeos\MShop\ContextIface |
77
|
|
|
{ |
78
|
|
|
$config = Aimeos\Base::config($tsconf); |
79
|
|
|
$context = Aimeos\Base::context($config); |
80
|
|
|
$context->config()->apply($conf); |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
$langManager = \Aimeos\MShop::create($context, 'locale/language'); |
84
|
|
|
$search = $langManager->filter(true); |
85
|
|
|
|
86
|
|
|
$expr = []; |
87
|
|
|
$expr[] = $search->getConditions(); |
88
|
|
|
$expr[] = $search->compare('==', 'locale.language.id', 'en'); // default language |
89
|
|
|
|
90
|
|
|
if (isset($GLOBALS['BE_USER']->uc['lang']) && $GLOBALS['BE_USER']->uc['lang'] != '') { // BE language |
91
|
|
|
$expr[] = $search->compare('==', 'locale.language.id', $GLOBALS['BE_USER']->uc['lang']); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$search->setConditions($search->combine('||', $expr)); |
95
|
|
|
$langids = $langManager->search($search)->keys()->toArray(); |
96
|
|
|
|
97
|
|
|
$context->setI18n(Aimeos\Base::i18n($langids, (array) ($tsconf['i18n'] ?? []))); |
98
|
|
|
|
99
|
|
|
$tmplPaths = Aimeos\Base::aimeos()->getTemplatePaths('controller/jobs/templates'); |
100
|
|
|
$context->setView(Aimeos\Base::view($context, self::getRouter($pid), $tmplPaths)); |
101
|
|
|
|
102
|
|
|
$context->setEditor('scheduler'); |
103
|
|
|
|
104
|
|
|
return $context; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns the enabled site items which may be limited by the input arguments. |
110
|
|
|
* |
111
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context item object |
112
|
|
|
* @param array|string $sites Unique site codes |
113
|
|
|
* @return \Aimeos\Map List of site items implementing \Aimeos\MShop\Locale\Item\Site\Iface |
114
|
|
|
*/ |
115
|
|
|
public static function getSiteItems(\Aimeos\MShop\ContextIface $context, $sites) : \Aimeos\Map |
116
|
|
|
{ |
117
|
|
|
if (!is_array($sites)) { |
118
|
|
|
$sites = explode(' ', $sites); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$manager = \Aimeos\MShop::create($context, 'locale/site'); |
122
|
|
|
$search = $manager->filter(); |
123
|
|
|
|
124
|
|
|
if (!empty($sites)) { |
125
|
|
|
$search->setConditions($search->compare('==', 'locale.site.code', $sites)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $manager->search($search); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns the page router |
134
|
|
|
* |
135
|
|
|
* @param string|null $pid Page ID |
136
|
|
|
* @return \TYPO3\CMS\Core\Routing\RouterInterface Page router |
137
|
|
|
* @throws \RuntimeException If no site configuraiton is available |
138
|
|
|
*/ |
139
|
|
|
protected static function getRouter(?string $pid) : \TYPO3\CMS\Core\Routing\RouterInterface |
140
|
|
|
{ |
141
|
|
|
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class); |
142
|
|
|
$site = $pid ? $siteFinder->getSiteByPageId($pid) : current($siteFinder->getAllSites()); |
143
|
|
|
|
144
|
|
|
if ($site) { |
145
|
|
|
return $site->getRouter(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
throw new \RuntimeException('No site configuration found'); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths