Commit ee4a40c9 authored by Stefan Busemann's avatar Stefan Busemann

Merge branch 'task/provide-json-file-with-composer-names' into 'develop'

Use service to check and update static JSON file

See merge request !652
parents eec3771d 1f3ccae3
Pipeline #10571 passed with stages
in 7 minutes and 30 seconds
<?php
namespace T3o\TerFe2\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use T3o\TerFe2\Service\ValidComposerNameFileService;
class UpdateValidComposerNameFileCommand extends Command
{
protected function configure()
{
$this->setDescription('Checks if JSON file needs to be updated');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if (ValidComposerNameFileService::issetRegistryFlag()) {
ValidComposerNameFileService::updateFile();
}
}
}
......@@ -14,19 +14,15 @@ namespace T3o\TerFe2\Controller\Eid;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use T3o\TerFe2\Service\ValidComposerNameFileService;
/**
* Class ExtensionController
*
* @deprecated Use ValidComposerNameFileService::output()
*/
class ExtensionController
{
/**
* @var array
*/
protected $jsonArray = [
'meta' => null,
'data' => null
];
/**
* @param $action
*/
......@@ -41,49 +37,9 @@ class ExtensionController
}
}
/**
*/
protected function findAllWithValidComposerName()
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_terfe2_domain_model_extension');
$expr = $queryBuilder->expr();
$result = $queryBuilder->select(
'ext_key',
'composer_name'
)
->from('tx_terfe2_domain_model_extension')
->where(
$expr->neq(
'composer_name',
$queryBuilder->createNamedParameter('')
)
)
->execute();
while ($extension = $result->fetch()) {
$this->jsonArray['data'][$extension['ext_key']] = [
'composer_name' => $extension['composer_name'],
];
}
$json = json_encode($this->jsonArray, true);
if (JSON_ERROR_NONE !== ($jsonErrorCode = json_last_error())) {
$this->jsonArray['meta'] = [
'error' => [
'type' => 'json encoding error',
'code' => $jsonErrorCode
]
];
$this->jsonArray['data'] = null;
$json = json_encode($this->jsonArray);
}
header('Content-Type: application/json');
echo $json;
exit();
ValidComposerNameFileService::output();
}
}
......
......@@ -19,11 +19,13 @@ use T3o\Ter\Api\ExtensionKey;
use T3o\Ter\Api\ExtensionVersion;
use T3o\TerFe2\Domain\Model\Extension;
use T3o\TerFe2\Provider\FileProvider;
use T3o\TerFe2\Service\ValidComposerNameFileService;
use T3o\TerFe2\Utility\ExtensionUtility;
use T3o\TerFe2\Utility\VersionUtility;
use T3o\TerFe2\Validation\Validator\ComposerNameValidator;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/**
* Controller for the extension object
......@@ -130,7 +132,7 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager $persistenceManager
*/
public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager $persistenceManager)
public function injectPersistenceManager(PersistenceManager $persistenceManager)
{
$this->persistenceManager = $persistenceManager;
}
......@@ -312,7 +314,13 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
$this->addFlashMessage('Tag "' . htmlspecialchars($tag) . '" added to extension');
}
}
$this->extensionRepository->update($extension);
if ($extension->_isDirty('composerName')) {
ValidComposerNameFileService::setRegistryFlag(1);
}
if (!empty($save)) {
$this->redirectWithMessage(
$this->translate('msg.extension_updated'),
......
<?php
namespace T3o\TerFe2\Service;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ValidComposerNameFileService
{
protected static string $fileName = 'currentvalidcomposernames.json';
public static function output(): void
{
$fileName = self::getFullPathOfFile();
if (!file_exists($fileName) || self::issetRegistryFlag()) {
self::updateFile();
}
header('Content-Type: application/json');
echo file_get_contents($fileName);
exit();
}
public static function updateFile(): void
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_terfe2_domain_model_extension');
$expr = $queryBuilder->expr();
$result = $queryBuilder
->select(
'ext_key',
'composer_name'
)
->from('tx_terfe2_domain_model_extension')
->where(
$expr->neq(
'composer_name',
$queryBuilder->createNamedParameter('')
)
)
->execute();
$extensionArray = [
'meta' => null,
'data' => null,
];
while ($extension = $result->fetch()) {
$extensionArray['data'][$extension['ext_key']] = [
'composer_name' => $extension['composer_name'],
];
}
if (JSON_ERROR_NONE !== ($jsonErrorCode = json_last_error())) {
$extensionArray['meta'] = [
'error' => [
'type' => 'json encoding error',
'code' => $jsonErrorCode
]
];
$extensionArray['data'] = null;
}
file_put_contents(
self::getFullPathOfFile(),
json_encode($extensionArray)
);
self::setRegistryFlag(0);
}
public static function setRegistryFlag(int $flag): void
{
$registry = GeneralUtility::makeInstance(Registry::class);
$registry->set('ter_fe2', 'validComposerNameUpdate', $flag);
}
public static function issetRegistryFlag(): bool
{
$registry = GeneralUtility::makeInstance(Registry::class);
return (int)$registry->get('ter_fe2', 'validComposerNameUpdate') === 1;
}
protected static function getFullPathOfFile(): string
{
return Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . '/' . self::$fileName;
}
}
......@@ -41,4 +41,7 @@ return [
'packagist:fetchdownloaddata' => [
'class' => \T3o\TerFe2\Command\PackagistCommand::class
],
'ter:updatevalidcomposernamefile' => [
'class' => \T3o\TerFe2\Command\UpdateValidComposerNameFileCommand::class
],
];
......@@ -16,6 +16,7 @@ use ApacheSolrForTypo3\Solr\GarbageCollector;
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
use T3o\TerFe2\Domain\Repository\ExtensionRepository as ExtbaseExtensionRepository;
use T3o\TerFe2\Service\ExtensionIndexService;
use T3o\TerFe2\Service\ValidComposerNameFileService;
use T3o\TerRest\Repository\ExtensionRepository;
use T3o\TerRest\Repository\FrontendUserRepository;
use T3o\TerRest\Service\ConfigurationService;
......@@ -56,6 +57,12 @@ abstract class AbstractService
return $this;
}
protected function requestUpdateOfValidComposerNamesFile(): self
{
ValidComposerNameFileService::setRegistryFlag(1);
return $this;
}
protected function flushCaches(): self
{
GeneralUtility::makeInstance(CacheManager::class)->flushCaches();
......
......@@ -107,7 +107,15 @@ class KeyService extends AbstractService
$fieldsToUpdate[$property->getName()] = $property->getValue();
}
return (bool)$this->extensionRepository->update($this->key, $fieldsToUpdate);
if (!$this->extensionRepository->update($this->key, $fieldsToUpdate)) {
return false;
}
if ($formDataStore->hasProperty('composer_name')) {
$this->requestUpdateOfValidComposerNamesFile();
}
return true;
}
public function delete(): bool
......
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