Issues (153)

Classes/Command/JobsCommand.php (2 issues)

Checks if used types are declared or listed as dependencies.

Bug Major
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);
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