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
<?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
{
    /**
25
     * @var array
26 27 28 29 30 31 32 33
     */
    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);
34
        $this->coreData = json_decode($json, true);
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
    }

    /**
     * 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 = [];
71
        foreach ($this->coreData[$release]['releases'] as $release) {
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
            $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()
    {
95
        return (int)substr($this->coreData['latest_lts'], 0, 1);
96 97 98 99
    }

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