...
  View open merge request
Commits (5)
......@@ -21,6 +21,9 @@ use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
*/
class Version extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
const CODE_QUALITY_UNCHECKED = 0;
const CODE_QUALITY_BAD = 1;
const CODE_QUALITY_GOOD = 2;
/**
* Title of the extension
......@@ -277,6 +280,11 @@ class Version extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $composerInfo = '';
/**
* @var int
*/
protected $codeQuality = 0;
/**
* Constructor. Initializes all ObjectStorage instances.
*/
......@@ -1115,6 +1123,26 @@ class Version extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
$this->composerInfo = $composerInfo;
}
/**
* @return int
*/
public function getCodeQuality(): int
{
return $this->codeQuality;
}
/**
* @param int $codeQuality
*/
public function setCodeQuality(int $codeQuality)
{
if ($codeQuality < self::CODE_QUALITY_UNCHECKED || $codeQuality > self::CODE_QUALITY_GOOD) {
throw new \InvalidArgumentException('Code Quality value must be between 0 and 2, here: ' . $codeQuality, 1531379473);
}
$this->codeQuality = $codeQuality;
}
/** Helper functions */
/**
......
......@@ -188,4 +188,18 @@ class ExtensionRepository extends \T3o\TerFe2\Domain\Repository\AbstractReposito
return $query->execute();
}
/**
* @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|\T3o\TerFe2\Domain\Model\Extension[]
*/
public function findAllWithVersionAndWithoutQualityCheck()
{
$query = $this->createQuery();
$constraints = [];
$constraints[] = $query->greaterThan('versions', 0);
$constraints[] = $query->equals('versions.codeQuality', 0);
$query->setOrderings(['versions.uploadDate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING]);
return $query->matching($query->logicalAnd($constraints))->execute();
}
}
......@@ -99,6 +99,9 @@ class TerIndexer extends \ApacheSolrForTypo3\Solr\IndexQueue\Indexer
$document->setField('insecure_boolS', $extension->getLastVersion()->getReviewState() === -1);
$document->setField('outdated_boolS', $extension->getLastVersion()->getReviewState() === -2);
// code quality
$document->setField('codeQuality_tIntS', $extension->getLastVersion()->getCodeQuality());
// composer support
$document->setField('supportsComposer_boolS', false);
$document->setField('composerName_stringS', '');
......
......@@ -209,7 +209,7 @@ return [
],
'paypal_url' => [
'exclude' => 1,
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_domain_model_extension.paypal_url',
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_domain_model_extension.donate_url',
'config' => [
'type' => 'text',
'rows' => 10,
......
......@@ -21,10 +21,10 @@ return [
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('ter_fe2') . 'Resources/Public/Icons/version.gif',
],
'interface' => [
'showRecordFieldList' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,frontend_download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,has_manual,software_relations,author,file_hash,extension_provider,has_zip_file,has_images,composer_info',
'showRecordFieldList' => 'title,description,version_number,version_string,upload_date,upload_comment,code_quality,download_counter,frontend_download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,has_manual,software_relations,author,file_hash,extension_provider,has_zip_file,has_images,composer_info',
],
'types' => [
'1' => ['showitem' => 'title,description,version_number,version_string,upload_date,upload_comment,download_counter,frontend_download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,has_manual,software_relations,author,file_hash,extension_provider,has_zip_file,has_images,composer_info'],
'1' => ['showitem' => 'title,description,version_number,version_string,upload_date,upload_comment,code_quality,download_counter,frontend_download_counter,state,em_category,load_order,priority,shy,internal,do_not_load_in_fe,uploadfolder,clear_cache_on_load,module,create_dirs,modify_tables,lock_type,cgl_compliance,cgl_compliance_note,review_state,manual,has_manual,software_relations,author,file_hash,extension_provider,has_zip_file,has_images,composer_info'],
],
'palettes' => [
'1' => ['showitem' => ''],
......@@ -413,5 +413,23 @@ return [
'eval' => 'trim'
],
],
'code_quality' => [
'exclude' => 1,
'label' => 'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_domain_model_version.code_quality',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_domain_model_version.code_quality.0',
0
],
[
'LLL:EXT:ter_fe2/Resources/Private/Language/locallang_db.xlf:tx_terfe2_domain_model_version.code_quality.1',
1
],
]
]
],
],
];
......@@ -213,6 +213,15 @@
<trans-unit id="tx_terfe2_domain_model_version.has_images" xml:space="preserve">
<source>Has images</source>
</trans-unit>
<trans-unit id="tx_terfe2_domain_model_version.code_quality" xml:space="preserve">
<source>Code quality</source>
</trans-unit>
<trans-unit id="tx_terfe2_domain_model_version.code_quality.0" xml:space="preserve">
<source>Bad</source>
</trans-unit>
<trans-unit id="tx_terfe2_domain_model_version.code_quality.1" xml:space="preserve">
<source>Good</source>
</trans-unit>
<trans-unit id="tx_terfe2_domain_model_relation" xml:space="preserve">
<source>Relation</source>
</trans-unit>
......
......@@ -96,3 +96,5 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\T3o\TerFe2\Task
];
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['ter_fe2:extension'] = 'EXT:ter_fe2/Classes/Controller/Eid/ExtensionController.php';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \T3o\TerFe2\Command\CodeQualityCommandController::class;
......@@ -120,6 +120,7 @@ CREATE TABLE tx_terfe2_domain_model_version (
t3x_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
zip_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
composer_info text NOT NULL,
code_quality tinyint(4) unsigned default '0' NOT NULL,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
crdate int(11) unsigned DEFAULT '0' NOT NULL,
......
......@@ -75,6 +75,13 @@
</f:link.external>
</li>
</f:if>
<f:if condition="{document.codeQuality_tIntS} == 2">
<li class="list-inline-item">
<f:link.external class="badge badge-success" uri="https://ter-sonarqube.marketing-factory.de/dashboard?id={document.extensionKey_stringS}" rel="nofollow">
<i class="fa fa-thumbs-o-up"></i> Code Quality
</f:link.external>
</li>
</f:if>
</ul>
</div>
</div>
......
<?php
namespace T3o\TerFe2\Command;
use T3o\TerFe2\Domain\Model\Version;
use T3o\TerFe2\Service\CodeQualityService;
class CodeQualityCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
/**
* @var \T3o\TerFe2\Domain\Repository\ExtensionRepository
*/
protected $extensionRepository;
public function injectExtensionRepository(\T3o\TerFe2\Domain\Repository\ExtensionRepository $extensionRepository)
{
$this->extensionRepository = $extensionRepository;
}
/**
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function checkLastVersionsCommand()
{
$querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(false);
$this->extensionRepository->setDefaultQuerySettings($querySettings);
$solrIndexQueue = $this->objectManager->get(\ApacheSolrForTypo3\Solr\IndexQueue\Queue::class);
$extensionsWithVersion = $this->extensionRepository->findAllWithVersionAndWithoutQualityCheck();
foreach ($extensionsWithVersion as $key => $extension) {
if ($extension->getLastVersion() instanceof Version && $extension->getLastVersion()->getCodeQuality() === Version::CODE_QUALITY_UNCHECKED) {
$codeQuality = CodeQualityService::hasExtensionVersionGoodQuality($extension->getLastVersion());
if ($codeQuality !== Version::CODE_QUALITY_UNCHECKED) {
$extension->getLastVersion()->setCodeQuality($codeQuality);
$this->extensionRepository->update($extension);
$solrIndexQueue->updateItem('tx_terfe2_domain_model_extension', $extension->getUid());
}
}
if ($key % 50 === 0) {
$persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
$persistenceManager->persistAll();
}
}
$persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
$persistenceManager->persistAll();
}
}
<?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 T3o\TerFe2\Domain\Model\Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class CodeQualityService
{
/**
* @var string
*/
protected static $baseUrnSonarQube = 'https://ter-sonarqube.marketing-factory.de/';
/**
* Checks API for the extension key and returns true if quality green otherwise false
*
* @param \T3o\TerFe2\Domain\Model\Version $version
* @return int
*/
public static function hasExtensionVersionGoodQuality(Version $version)
{
$codeQuality = Version::CODE_QUALITY_UNCHECKED;
$projectAnalysesResult = json_decode(GeneralUtility::getUrl(self::$baseUrnSonarQube . 'api/project_analyses/search?project=' . $version->getExtension()->getExtKey() . '&category=QUALITY_GATE'), true);
if (isset($projectAnalysesResult['analyses'][0]['events'])) {
foreach ($projectAnalysesResult['analyses'][0]['events'] as $event) {
if ($event['category'] === 'QUALITY_GATE') {
$codeQuality = (stripos($event['name'], 'green') === 0) ? Version::CODE_QUALITY_GOOD : Version::CODE_QUALITY_BAD;
}
}
}
return $codeQuality;
}
/**
* @param \T3o\TerFe2\Domain\Model\Version $version
* @return bool
*/
public static function isExtensionVersionChecked(Version $version)
{
$projectAnalyses = json_decode(GeneralUtility::getUrl(self::$baseUrnSonarQube . 'api/project_analyses/search?project=' . $version->getExtension()->getExtKey()), true);
$lastVersionAnalysed = '';
if ($projectAnalyses['analyses'][0]['events']) {
foreach ($projectAnalyses['analyses'][0]['events'] as $event) {
if ($event['category'] === 'VERSION') {
$lastVersionAnalysed = $event['name'];
}
}
}
return $lastVersionAnalysed && $lastVersionAnalysed === $version->getVersionString();
}
}