LTSVersionService.php 2.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace T3o\TerFe2\Service;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
 * Class LTSVersionService
 */
class LTSVersionService
{
    /**
     * @var string
     */
    public $coreData = '';


    public function __construct()
    {
        // Will be automatically update with UpdateCurrentVersionListTask see T3o\Ter\Task\UpdateCurrentVersionListTask
        $sourceFile = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json';
        $json = file_get_contents($sourceFile);
        $this->coreData = json_decode($json, true);
    }

    /**
     * Get the current stable versions
     *
     * @return array
     */
    public function getCurrentStableVersions()
    {
        return [
            $this->getLatestOldLTS(),
            $this->getLatestLTS()
        ];
    }

    /**
     * Returns all maintained versions.
     *
     * @return array
     */
    public function getAllMaintainedVersions()
    {
        $versions = $this->getCurrentStableVersions();
        array_push($versions, $this->getLatestDevelopmentVersion());
        return $versions;
    }

    /**
     * Get latest version within a specific release
     *
     * @param int $release
     * @return string
     */
    public function getLatestVersionOfRelease($release)
    {
        $versions = [];
        foreach($this->coreData[$release]['releases'] as $release) {
            $versions[] = VersionNumberUtility::convertVersionNumberToInteger($release['version']);
        }
        sort($versions);
        return VersionNumberUtility::convertIntegerToVersionNumber(array_pop($versions));

    }

    /**
     * Get latest development version
     *
     * @return string
     */
    public function getLatestDevelopmentVersion()
    {
        return substr($this->coreData['latest_stable'], 0, 3);
    }

    /**
     * Get latest LTS Version
     *
     * @return int
     */
    private function getLatestLTS()
    {
        return (int) substr($this->coreData['latest_lts'], 0, 1);
    }

    /**
     * Get latest "old" LTS Version
     * 
     * @return int
     */
    private function getLatestOldLTS()
    {
        return (int) substr($this->coreData['latest_old_lts'], 0, 1);
    }
}