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

Merge branch 'feature/mirrors-download-counter-removal' into 'develop'

[!!!][TASK] Remove code for download counter via SOAP API

See merge request t3o/ter!492
parents 5e2c33bd 92c1dce0
Pipeline #9054 passed with stages
in 10 minutes and 28 seconds
......@@ -24,7 +24,6 @@ Configuration
pid = 1320
repositoryDir = /var/www/sites/typo3.org/fileadmin/ter/
reviewersFrontendUsergroupUid = 123
mirrorsFrontendUsergroupUid = 123
}
page = PAGE
......
......@@ -620,102 +620,23 @@ class tx_ter_api
}
/**
* Increases the download counters of several extension version
* Increases the download counters of several extension version.
* This was previously used for TER mirrors to update the download counter, but this was never implemented
* since 2016, so this method is kept for compatibility reasons but does not do anything anymore.
*
* @param object $accountData : A valid username and password
* @param object $extensionVersionsAndIncrementors : An array of extension keys, version numbers and the incrementor
*
* @return object simpleResponse-object. An exception is thrown if a fatal error ocurred.
* @return array|object simpleResponse-object. An exception is thrown if a fatal error ocurred.
* @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
* @throws \T3o\Ter\Exception\UnauthorizedException
* @since 2.0.0
*/
public function increaseExtensionDownloadCounters($accountData, $extensionVersionsAndIncrementors)
{
$errorMessages = [];
GeneralUtility::devLog(
'DownloadCounter: Trying to increase extension download counters - user "' . $accountData->username . '" connected from IP "' . GeneralUtility::getIndpEnv(
'REMOTE_ADDR'
) . '" - number of results: ' . count($extensionVersionsAndIncrementors->extensionVersionAndIncrementor),
'tx_ter_api',
0
);
$userRecordArr = $this->helperObj->getValidUser($accountData);
$mirrorsFrontendUsergroupUid = (int)$this->parentObj->conf['mirrorsFrontendUsergroupUid'];
if ($mirrorsFrontendUsergroupUid == 0) {
GeneralUtility::devLog(
'DownloadCounter: No usergroup for mirrors has been defined on the server side. Aborting ...',
'tx_ter_api',
3
);
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Warning: No usergroup for mirrors has been defined on the server side. Aborting ...',
TX_TER_ERROR_INCREASEEXTENSIONDOWNLOADCOUNTER_NOUSERGROUPDEFINED
);
}
if (!GeneralUtility::inList($userRecordArr['usergroup'], $mirrorsFrontendUsergroupUid)) {
GeneralUtility::devLog(
'DownloadCounter: Access denied for user ' . $accountData->username,
'tx_ter_api',
3,
$userRecordArr
);
throw new \T3o\Ter\Exception\UnauthorizedException('Access denied.', TX_TER_ERROR_INCREASEEXTENSIONDOWNLOADCOUNTER_ACCESSDENIED);
}
$counter = 0;
if (is_array($extensionVersionsAndIncrementors->extensionVersionAndIncrementor)) {
foreach ($extensionVersionsAndIncrementors->extensionVersionAndIncrementor as $extensionVersionAndIncrementor) {
try {
$this->increaseExtensionDownloadCounter_increaseCounterInDB($extensionVersionAndIncrementor);
$counter++;
} catch (Exception $exception) {
$errorMessages[] = '[' . $extensionVersionAndIncrementor->extensionKey . '][' . $extensionVersionAndIncrementor->version . '] ' . $exception->faultstring;
}
}
} else {
try {
$extensionVersionAndIncrementor = $extensionVersionsAndIncrementors->extensionVersionAndIncrementor;
$this->increaseExtensionDownloadCounter_increaseCounterInDB($extensionVersionAndIncrementor);
$counter++;
} catch (Exception $exception) {
$errorMessages[] = '[' . $extensionVersionAndIncrementor->extensionKey . '][' . $extensionVersionAndIncrementor->version . '] ' . $exception->faultstring;
}
}
GeneralUtility::devLog(
'DownloadCounter: Increased download counter for ' . $counter . ' extensions. User "' . $accountData->username . '".',
'tx_ter_api',
0
);
// Update extension index file
$this->helperObj->requestUpdateOfExtensionIndexFile();
// Return results including list of error messages if any
if (!empty($errorMessages)) {
GeneralUtility::devLog(
'DownloadCounter: Errors occured for user "' . $accountData->username . '".',
'tx_ter_api',
2,
$errorMessages
);
$result = [
'resultCode' => TX_TER_RESULT_ERRORS_OCCURRED,
'resultMessages' => $errorMessages
];
} else {
GeneralUtility::devLog('DownloadCounter: Everything OK. User "' . $accountData->username . '".', 'tx_ter_api', -1);
$result = [
'resultCode' => TX_TER_RESULT_GENERAL_OK,
'resultMessages' => []
];
}
return $result;
return [
'resultCode' => TX_TER_RESULT_GENERAL_OK,
'resultMessages' => []
];
}
/*********************************************************
......@@ -1445,107 +1366,6 @@ class tx_ter_api
}
}
/*********************************************************
*
* increaseExtensionDownloadCounter helper functions
*
*********************************************************/
/**
* Reads, increases and writes the download counter of an extension version
* into the database.
*
* @param object $extensionVersionDataAndIncrementor : Extension key and version number and the download count incrementor
*
* @throws \T3o\Ter\Exception\InternalServerErrorException
* @throws \T3o\Ter\Exception\NotFoundException
* @access protected
*/
protected function increaseExtensionDownloadCounter_increaseCounterInDB($extensionVersionDataAndIncrementor)
{
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid, downloadcounter',
'tx_ter_extensions',
'extensionkey =' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
$extensionVersionDataAndIncrementor->extensionKey,
'tx_ter_extensions'
) . ' AND ' . 'version =' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
$extensionVersionDataAndIncrementor->version,
'tx_ter_extensions'
)
);
if (!$res) {
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Database error while searching for extension record.',
TX_TER_ERROR_GENERAL_DATABASEERROR
);
}
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) != 1) {
throw new \T3o\Ter\Exception\NotFoundException(
'Extension version does not exist.',
TX_TER_ERROR_INCREASEEXTENSIONDOWNLOADCOUNTER_EXTENSIONVERSIONDOESNOTEXIST
);
}
$currentRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$incrementor = (int)$extensionVersionDataAndIncrementor->downloadCountIncrementor;
if ($incrementor !== abs($incrementor)) {
throw new \T3o\Ter\Exception\NotFoundException(
'The incrementor must be a positive integer value.',
TX_TER_ERROR_INCREASEEXTENSIONDOWNLOADCOUNTER_INCREMENTORNOTPOSITIVEINTEGER
);
}
$newCounter = $currentRow['downloadcounter'] + $incrementor;
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'tx_ter_extensions',
'uid=' . (int)$currentRow['uid'],
['downloadcounter' => $newCounter]
);
if (!$res) {
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Database error while updating extension download counter.',
TX_TER_ERROR_GENERAL_DATABASEERROR
);
}
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid, downloadcounter',
'tx_ter_extensionkeys',
'extensionkey =' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
$extensionVersionDataAndIncrementor->extensionKey,
'tx_ter_extensions'
)
);
if (!$res) {
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Database error while searching for extension key record.',
TX_TER_ERROR_GENERAL_DATABASEERROR
);
}
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) != 1) {
throw new \T3o\Ter\Exception\NotFoundException(
'Extension key does not exist.',
TX_TER_ERROR_INCREASEEXTENSIONDOWNLOADCOUNTER_EXTENSIONKEYDOESNOTEXIST
);
}
$currentRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$newCounter = $currentRow['downloadcounter'] + $incrementor;
$res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
'tx_ter_extensionkeys',
'uid=' . (int)$currentRow['uid'],
['downloadcounter' => $newCounter]
);
if (!$res) {
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Database error while updating extension total download counter.',
TX_TER_ERROR_GENERAL_DATABASEERROR
);
}
}
/**
* Update an existing or create a new database record
*
......
......@@ -3,6 +3,5 @@ plugin.tx_ter_pi1 {
reviewersFrontendUsergroupUid = 2
adminFrontendUsergroupUid = 3
securityTeamFrontendUsergroupUid = 22
mirrorsFrontendUsergroupUid =
wsdlNamespace =
}
......@@ -3,6 +3,5 @@ plugin.tx_ter_pi1 {
reviewersFrontendUsergroupUid = {$plugin.tx_ter_pi1.reviewersFrontendUsergroupUid}
adminFrontendUsergroupUid = {$plugin.tx_ter_pi1.adminFrontendUsergroupUid}
securityTeamFrontendUsergroupUid = {$plugin.tx_ter_pi1.securityTeamFrontendUsergroupUid}
mirrorsFrontendUsergroupUid = {$plugin.tx_ter_pi1.mirrorsFrontendUsergroupUid}
wsdlNamespace = {$plugin.tx_ter_pi1.wsdlNamespace}
}
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