Commit 579faa08 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Merge branch 'feature/encapsulate-core-versions-fetching' into 'develop'

[TASK] Migrate get.typo3.org cache file fetching into separate CLI command

See merge request t3o/ter!560
parents 8a10ec8a 7c4dbc9d
Pipeline #9574 failed with stages
in 4 minutes and 12 seconds
......@@ -36,5 +36,6 @@ test:unit:
- composer install --ignore-platform-reqs
- composer test:unit
artifacts:
expire_in: 15 mins
reports:
junit: build/*-report.xml
<?php
namespace T3o\Ter\Task;
/*
* 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 T3o\TerFe2\Domain\Repository\CombinedExtensionRepository;
use T3o\TerFe2\Service\ExtensionIndexService;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Update json file with information of core versions
*/
class UpdateCurrentVersionListTask extends \TYPO3\CMS\Extbase\Scheduler\Task
{
/**
* Public method, usually called by scheduler
*
* @return bool TRUE on success
*/
public function execute()
{
$resultCoreData = $this->fetchCurrentCoreData();
$resultDocsData = $this->fetchCurrentDocumentationData();
$resultExtensionFiles = $this->generateExtensionFilesForExtensionManager();
return $resultCoreData && $resultDocsData && $resultExtensionFiles;
}
/**
* @return bool
*/
protected function fetchCurrentCoreData()
{
$result = false;
$targetFile = Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json';
$sourceData = GeneralUtility::getUrl('http://get.typo3.org/json');
if (json_decode($sourceData, true) !== null) {
$result = GeneralUtility::writeFile($targetFile, $sourceData);
}
return $result;
}
/**
* @return bool
*/
protected function fetchCurrentDocumentationData()
{
$result = false;
$targetFile = Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentdocumentationdata.json';
$sourceData = GeneralUtility::getUrl('https://intercept.typo3.com/assets/docs/manuals.json');
if (json_decode($sourceData, true) !== null) {
$result = GeneralUtility::writeFile($targetFile, $sourceData);
}
return $result;
}
/**
* This command generates the central extensions.xml.gz file to run
* with every Extension Manager in TYPO3 installations
*
* @return bool
* @throws \Exception
*/
protected function generateExtensionFilesForExtensionManager(): bool
{
$indexCreator = GeneralUtility::makeInstance(ExtensionIndexService::class);
if ($indexCreator->isOldUpdateRequested()) {
return false;
}
$startTime = microtime();
$extensionDetails = GeneralUtility::makeInstance(CombinedExtensionRepository::class)->getExtensionDetailsWithVersionsAndDownloadNumbers();
$dom = $indexCreator->compileXmlStructure($extensionDetails, $startTime);
// Write new extensions xml file
$indexCreator->writeXmlToFile($dom);
$indexCreator->writeSerializedExtensionInformationToFile($extensionDetails);
return true;
}
}
......@@ -3,13 +3,7 @@ if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
// Register core version update task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\Ter\Task\UpdateCurrentVersionListTask::class] = [
'extension' => 'ter',
'title' => 'LLL:EXT:ter/locallang.xml:tx_ter_updateCurrentVersionListTask.name',
'description' => 'LLL:EXT:ter/locallang.xml:tx_ter_updateCurrentVersionListTask.description',
'additionalFields' => ''
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPItoST43('ter', '', '_pi1', 'list_type', false);
$apiConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\T3o\Ter\Api\Configuration::class);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants('
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<description>language labels for ter extension</description>
<type>plugin</type>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="tx_ter_updateExtensionIndexTask.name">Publish extension updates</label>
<label index="tx_ter_updateExtensionIndexTask.description">Write new extension details into TER Frontend tables</label>
<label index="tx_ter_updateCurrentVersionListTask.name">Update core version info</label>
<label index="tx_ter_updateCurrentVersionListTask.description">Update the stored information about TYPO3 core versions</label>
<label index="tx_ter_updateExtensionIndexTask.clearCachePages">Clear cache of these pages after running task</label>
</languageKey>
</data>
</T3locallang>
<?php
declare(strict_types = 1);
/*
* This file is part of TYPO3 CMS-extension "ter_fe2", created by Benni Mack.
*
* 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.
*/
namespace T3o\TerFe2\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use T3o\TerFe2\Service\LTSVersionService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Updates the current core information data from get.typo3.org
*/
class FetchCoreVersionCommand extends Command
{
/**
* @var LTSVersionService
*/
protected $ltsVersionService;
public function __construct(string $name = null, LTSVersionService $ltsVersionService = null)
{
$this->ltsVersionService = $ltsVersionService ?? GeneralUtility::makeInstance(LTSVersionService::class);
parent::__construct($name);
}
protected function configure()
{
$this->setDescription('Updates the current TYPO3 core release metadata from get.typo3.org.');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section('Downloading Core API from get.typo3.org');
$ltsVersionService = GeneralUtility::makeInstance(LTSVersionService::class);
$ltsVersionService->reloadCacheFile();
$io->success('Core API file downloaded on ' . date('d-m-Y H:i:s'));
return 0;
}
}
......@@ -16,6 +16,7 @@ namespace T3o\TerFe2\Service;
use T3o\TerFe2\Utility\VersionUtility;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
......@@ -27,6 +28,11 @@ class LTSVersionService
const FACTOR_MINOR_VERSION = 1000;
const FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER = 7;
/**
* @var string
*/
protected string $cacheFile;
/**
* @var array
*/
......@@ -41,15 +47,37 @@ class LTSVersionService
public function __construct()
{
// Will be automatically update with UpdateCurrentVersionListTask see T3o\Ter\Task\UpdateCurrentVersionListTask
$sourceFile = Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json';
$json = file_get_contents($sourceFile);
$this->cacheFile = Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json';
// If the file does not exist, fetch the data from the remote at any time
if (!is_file($this->cacheFile)) {
$this->reloadCacheFile();
}
$this->extractData();
}
/**
* Loads the JSON file from get.typo3.org / currentcoredata.json into $this->coreData and release information.
*/
protected function extractData()
{
$json = file_get_contents($this->cacheFile);
$this->coreData = json_decode($json, true);
if (!empty($this->coreData)) {
$this->buildReleases();
}
}
/**
* Fetch the contents from get.typo3.org (used from the CLI command)
*/
public function reloadCacheFile(): void
{
$sourceData = GeneralUtility::getUrl('https://get.typo3.org/json');
if (json_decode($sourceData, true) !== null) {
GeneralUtility::writeFile($this->cacheFile, $sourceData);
}
}
public function buildReleases()
{
foreach ($this->coreData as $release) {
......
......@@ -23,6 +23,9 @@ return [
'ter:fetchDocumentationStatus' => [
'class' => \T3o\TerFe2\Command\FetchDocumentationStatus::class
],
'ter:fetchCoreVersion' => [
'class' => \T3o\TerFe2\Command\FetchCoreVersionCommand::class
],
'ter:checkForOutdatedExtensions' => [
'class' => \T3o\TerFe2\Command\CheckForOutdatedExtensions::class
],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment