Issues (153)

Classes/Scheduler/Base.php (2 issues)

Labels
Severity
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;
0 ignored issues
show
The type TYPO3\CMS\Core\Utility\GeneralUtility 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...
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);
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 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\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Price\Manager\Property\Type\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\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Media\Manager\Lists\Type\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\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\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\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\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\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MShop\Common\Manager\Type\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Customer\Manager\Group\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\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Media\Manager\Property\Type\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\MShop\Attribute\Manager\Lists\Type\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\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Index\Manager\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\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

51
            /** @scrutinizer ignore-call */ 
52
            $localeItem = $manager->bootstrap($siteItem->getCode(), '', '', false);
Loading history...
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