Commit b1e3460f authored by Benni Mack's avatar Benni Mack
Browse files

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

The downloading of the current corejson file is happening in an
outdated scheduler task, which is now needed anymore,
as all jobs within the task are now handled through a CLI command, the
latest being added is "ter:fetchCoreVersion".

This way, the original "UpdateCurrentVersionListTask" can be removed,
and in addition, the actual path of the cache file is now located in
one single PHP class and encapsulated there.
parent f9037696
Pipeline #9414 passed with stages
in 9 minutes and 26 seconds
<?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;
}
}
......@@ -5,14 +5,6 @@ if (!defined('TYPO3_MODE')) {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPItoST43('ter', '', '_pi1', 'list_type', false);
// 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' => ''
];
$apiConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\T3o\Ter\Api\Configuration::class);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants('
plugin.tx_ter_pi1 {
......
<?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;
}
}
......@@ -15,6 +15,7 @@ namespace T3o\TerFe2\Service;
*/
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
......@@ -26,6 +27,11 @@ class LTSVersionService
const FACTOR_MINOR_VERSION = 1000;
const FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER = 7;
/**
* @var string
*/
protected string $cacheFile;
/**
* @var array
*/
......@@ -40,15 +46,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) {
......
......@@ -17,7 +17,7 @@ namespace T3o\TerFe2\Task;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Core\Environment;
use T3o\TerFe2\Service\LTSVersionService;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -87,10 +87,8 @@ class CheckForOutdatedExtensions extends Task
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
$this->session = $this->objectManager->get(Session::class);
$this->versionRepository = $this->objectManager->get(\T3o\TerFe2\Domain\Repository\VersionRepository::class);
$this->coreVersions = json_decode(
GeneralUtility::getURL(Environment::getPublicPath() . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'),
true
);
$ltsVersionService = GeneralUtility::makeInstance(LTSVersionService::class);
$this->coreVersions = $ltsVersionService->coreData;
$this->solrIndexQueue = $this->objectManager->get(Queue::class);
}
......
......@@ -23,4 +23,7 @@ return [
'ter:fetchDocumentationStatus' => [
'class' => \T3o\TerFe2\Command\FetchDocumentationStatus::class
],
'ter:fetchCoreVersion' => [
'class' => \T3o\TerFe2\Command\FetchCoreVersionCommand::class
],
];
Markdown is supported
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