• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tomasnorre / crawler / 11237471329

08 Oct 2024 02:20PM UTC coverage: 68.586% (-1.3%) from 69.862%
11237471329

push

github

web-flow
ci: Update coveralls workflow (#1109)

1834 of 2674 relevant lines covered (68.59%)

3.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.38
/Classes/Service/ProcessService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace AOE\Crawler\Service;
6

7
/*
8
 * (c) 2022 Tomas Norre Mikkelsen <tomasnorre@gmail.com>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21

22
use AOE\Crawler\Domain\Repository\ProcessRepository;
23
use AOE\Crawler\Exception\ProcessException;
24
use AOE\Crawler\Helper\Sleeper\SleeperInterface;
25
use AOE\Crawler\Utility\PhpBinaryUtility;
26
use TYPO3\CMS\Core\Core\Environment;
27
use TYPO3\CMS\Core\Utility\CommandUtility;
28

29
/**
30
 * @package AOE\Crawler\Service
31
 * @ignoreAnnotation("noRector")
32
 *
33
 * @internal since v9.2.5
34
 */
35
class ProcessService
36
{
37
    public function __construct(
38
        private readonly ProcessRepository $processRepository,
39
        private readonly SleeperInterface $sleeper
40
    ) {
41
    }
3✔
42

43
    /**
44
     * starts new process
45
     * @throws ProcessException if no crawler process was started
46
     */
47
    public function startProcess(int $timeToLive = 300): bool
48
    {
49
        $ttl = (time() + $timeToLive - 1);
2✔
50
        $current = $this->processRepository->countNotTimeouted($ttl);
2✔
51

52
        // Check whether OS is Windows
53
        if (Environment::isWindows()) {
2✔
54
            $completePath = 'start ' . $this->getCrawlerCliPath();
×
55
        } else {
56
            $completePath = '(' . $this->getCrawlerCliPath() . ' &) > /dev/null';
2✔
57
        }
58

59
        $output = null;
2✔
60
        $returnValue = 0;
2✔
61
        CommandUtility::exec($completePath, $output, $returnValue);
2✔
62
        if ($returnValue !== 0) {
2✔
63
            throw new ProcessException('could not start process!');
×
64
        }
65
        for ($i = 0; $i < 10; $i++) {
2✔
66
            if ($this->processRepository->countNotTimeouted($ttl) > $current) {
2✔
67
                return true;
1✔
68
            }
69
            $this->sleeper->sleep(1);
1✔
70
        }
71
        throw new ProcessException('Something went wrong: process did not appear within 10 seconds.');
1✔
72
    }
73

74
    /**
75
     * Returns the path to start the crawler from the command line
76
     */
77
    public function getCrawlerCliPath(): string
78
    {
79
        $phpPath = PhpBinaryUtility::getPhpBinary();
1✔
80
        $typo3BinaryPath = $this->getComposerBinPath();
1✔
81

82
        $cliPart = 'typo3 crawler:processQueue';
1✔
83
        // Don't like the spacing, but don't have an better idea for now
84
        $scriptPath = $phpPath . ' ' . $typo3BinaryPath . $cliPart;
1✔
85

86
        if (Environment::isWindows()) {
1✔
87
            $scriptPath = str_replace('/', '\\', $scriptPath);
×
88
        }
89

90
        return ltrim($scriptPath);
1✔
91
    }
92

93
    private function getComposerBinPath(): ?string
94
    {
95
        // copied and modified from @see
96
        // https://github.com/TYPO3/typo3/blob/8a9c80b9d85ef986f5f369f1744fc26a6b607dda/typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php#L402
97
        $composerJsonFile = getenv('TYPO3_PATH_COMPOSER_ROOT') . '/composer.json';
1✔
98
        if (!file_exists($composerJsonFile) || !($jsonContent = file_get_contents($composerJsonFile))) {
1✔
99
            return null;
×
100
        }
101
        $jsonConfig = @json_decode($jsonContent, true);
1✔
102
        if (empty($jsonConfig) || !is_array($jsonConfig)) {
1✔
103
            return null;
×
104
        }
105
        $vendorDir = trim($jsonConfig['config']['vendor-dir'] ?? 'vendor', '/');
1✔
106
        $binDir = trim($jsonConfig['config']['bin-dir'] ?? $vendorDir . '/bin', '/');
1✔
107

108
        return sprintf('%s/%s/', getenv('TYPO3_PATH_COMPOSER_ROOT'), $binDir);
1✔
109
    }
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc