Issues (153)

Classes/Command/JobsCommand.php (3 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * @license GPLv3, http://www.gnu.org/copyleft/gpl.html
5
 * @copyright Aimeos (aimeos.org), 2018-2019
6
 * @package TYPO3
7
 */
8
9
10
namespace Aimeos\Aimeos\Command;
11
12
13
use TYPO3\CMS\Core\Site\SiteFinder;
14
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...
15
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
The type Symfony\Component\Console\Command\Command 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
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
22
/**
23
 * Executes the job controllers
24
 *
25
 * @package TYPO3
26
 */
27
class JobsCommand extends Command
28
{
29
    protected static $defaultName = 'aimeos:jobs';
30
31
32
    /**
33
     * Configures the command name and description
34
     */
35
    protected function configure()
36
    {
37
        $this->setName(self::$defaultName);
38
        $this->setDescription('Executes the job controllers');
39
        $this->addArgument('jobs', InputArgument::REQUIRED, 'One or more job controller names like "admin/job customer/email/watch"');
40
        $this->addArgument('site', InputArgument::OPTIONAL, 'Site codes to execute the jobs for like "default unittest" (none for all)');
41
        $this->addOption('pid', null, InputOption::VALUE_REQUIRED, 'Page ID of the catalog detail page for jobs generating URLs');
42
    }
43
44
45
    /**
46
     * Executes the job controllers
47
     *
48
     * @param InputInterface $input Input object
49
     * @param OutputInterface $output Output object
50
     */
51
    protected function execute(InputInterface $input, OutputInterface $output)
52
    {
53
        $context = $this->context($input->getOption('pid'));
54
        $process = $context->process();
55
56
        $aimeos = \Aimeos\Aimeos\Base::aimeos();
57
        $jobs = explode(' ', $input->getArgument('jobs'));
58
        $localeManager = \Aimeos\MShop::create($context, 'locale');
59
60
        foreach ($this->getSiteItems($context, $input) as $siteItem) {
61
            $localeItem = $localeManager->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

61
            /** @scrutinizer ignore-call */ 
62
            $localeItem = $localeManager->bootstrap($siteItem->getCode(), '', '', false);
Loading history...
62
            $localeItem->setLanguageId(null);
63
            $localeItem->setCurrencyId(null);
64
            $context->setLocale($localeItem);
65
66
            $config = $context->config();
67
            foreach ($localeItem->getSiteItem()->getConfig() as $key => $value) {
68
                $config->set($key, $value);
69
            }
70
71
            $output->writeln(sprintf('Executing the Aimeos jobs for "<info>%s</info>"', $siteItem->getCode()));
72
73
            // Reset before child processes are spawned to avoid lost DB connections afterwards (TYPO3 9.4 and above)
74
            if (method_exists('\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections')) {
75
                GeneralUtility::makeInstance('TYPO3\CMS\Core\Database\ConnectionPool')->resetConnections();
76
            }
77
78
            foreach ($jobs as $jobname) {
79
                $fcn = function($context, $aimeos, $jobname) {
80
                    \Aimeos\Controller\Jobs::create($context, $aimeos, $jobname)->run();
81
                };
82
83
                $process->start($fcn, [$context, $aimeos, $jobname], true);
84
            }
85
        }
86
87
        $process->wait();
88
89
        return 0;
90
    }
91
92
93
    /**
94
     * Returns a context object
95
     *
96
     * @param string|null $pid Page ID if available
97
     * @return \Aimeos\MShop\ContextIface Context object containing only the most necessary dependencies
98
     */
99
    protected function context(?string $pid) : \Aimeos\MShop\ContextIface
100
    {
101
        $aimeos = \Aimeos\Aimeos\Base::aimeos();
102
        $tmplPaths = $aimeos->getTemplatePaths('controller/jobs/templates');
103
104
        $config = \Aimeos\Aimeos\Base::config();
105
        $context = \Aimeos\Aimeos\Base::context($config);
106
107
        $langManager = \Aimeos\MShop::create($context, 'locale/language');
108
        $langids = $langManager->search($langManager->filter(true))->keys()->toArray();
109
110
        $i18n = \Aimeos\Aimeos\Base::i18n($langids, $config->get('i18n', []));
111
        $context->setI18n($i18n);
112
113
        $view = \Aimeos\Aimeos\Base::view($context, $this->getRouter($pid), $tmplPaths);
114
        $context->setView($view);
115
116
        $context->setSession(new \Aimeos\Base\Session\None());
117
        $context->setCache(new \Aimeos\Base\Cache\None());
118
119
        return $context->setEditor('aimeos:jobs');
120
    }
121
122
123
    /**
124
     * Returns the enabled site items which may be limited by the input arguments.
125
     *
126
     * @param \Aimeos\MShop\ContextIface $context Context item object
127
     * @param InputInterface $input Input object
128
     * @return \Aimeos\Map List of site items implementing \Aimeos\MShop\Locale\Item\Site\Iface
129
     */
130
    protected function getSiteItems(\Aimeos\MShop\ContextIface $context, InputInterface $input) : \Aimeos\Map
131
    {
132
        $manager = \Aimeos\MShop::create($context, 'locale/site');
133
        $search = $manager->filter();
134
135
        if (($codes = (string) $input->getArgument('site')) !== '') {
136
            $search->setConditions($search->compare('==', 'locale.site.code', explode(' ', $codes)));
137
        }
138
139
        return $manager->search($search);
140
    }
141
142
143
    /**
144
     * Returns the page router
145
     *
146
     * @param string|null $pid Page ID
147
     * @return \TYPO3\CMS\Core\Routing\RouterInterface Page router
148
     * @throws \RuntimeException If no site configuraiton is available
149
     */
150
    protected function getRouter(?string $pid) : \TYPO3\CMS\Core\Routing\RouterInterface
151
    {
152
        $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
153
        $site = $pid ? $siteFinder->getSiteByPageId($pid) : current($siteFinder->getAllSites());
154
155
        if ($site) {
156
            return $site->getRouter();
157
        }
158
159
        throw new \RuntimeException('No site configuration found');
160
    }
161
}
162