Commit 79ab1165 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Cleanup TER API code

This patch adds some minor cleanup areas for the API code.
parent 8e172a24
Pipeline #9129 passed with stages
in 7 minutes
......@@ -10,5 +10,6 @@
/auth.json
/assets/
sequelpro.spf
.php_cs.cache
.ddev/db_snapshots/
.idea/
......@@ -256,7 +256,7 @@ class tx_ter_api
* @param string $extensionKey : Extension key of the extension version to delete
* @param string $version : Version string of the extension version to delete
*
* @return object simpleResult object if extension could be deleted, otherwise an exception is thrown.
* @return array|object simpleResult object if extension could be deleted, otherwise an exception is thrown.
* @throws \T3o\Ter\Exception\UnauthorizedException
* @throws \T3o\Ter\Exception\NotFoundException
* @access public
......@@ -285,11 +285,7 @@ class tx_ter_api
$this->deleteExtension_deleteFromDBAndRemoveFiles($extensionKey, $version);
$this->requestUpdateOfExtensionIndexFile();
return [
'resultCode' => ResultCodes::RESULT_EXTENSIONSUCCESSFULLYDELETED,
'resultMessages' => []
];
return $this->formatAsSimpleResult(ResultCodes::RESULT_EXTENSIONSUCCESSFULLYDELETED);
}
/**
......@@ -314,11 +310,7 @@ class tx_ter_api
} else {
$resultCode = ResultCodes::RESULT_EXTENSIONKEYNOTVALID;
}
return [
'resultCode' => $resultCode,
'resultMessages' => [],
];
return $this->formatAsSimpleResult($resultCode);
}
/**
......@@ -353,11 +345,7 @@ class tx_ter_api
} catch (\T3o\Ter\Exception\ExtensionKeyAlreadyInUseException $e) {
$resultCode = ResultCodes::RESULT_EXTENSIONKEYALREADYEXISTS;
}
return [
'resultCode' => $resultCode,
'resultMessages' => [],
];
return $this->formatAsSimpleResult($resultCode);
}
/**
......@@ -368,7 +356,7 @@ class tx_ter_api
* @param object $extensionKeyFilterOptions : Result will be filtered by fields set in these filter options
*
* @return array getExtensionKeyRepsonse-object if key(s) could be fetched (might also be an empty result). An exception
* is thrown if an error ocurred.
* is thrown if an error occurred.
* @access public
* @since 2.0.0
*/
......@@ -381,10 +369,7 @@ class tx_ter_api
$extensionKeyFilterOptions->extensionKey ?? null
);
return [
'simpleResult' => [
'resultCode' => ResultCodes::RESULT_GENERAL_OK,
'resultMessages' => []
],
'simpleResult' => $this->formatAsSimpleResult(ResultCodes::RESULT_GENERAL_OK),
'extensionKeyData' => $extensionKeyDataArr
];
}
......@@ -395,7 +380,7 @@ class tx_ter_api
* @param object $accountData : A valid username and password
* @param string $extensionKey : The extension key to delete
*
* @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 occurred.
* @access public
* @since 2.0.0
* @throws \T3o\Ter\Exception\InternalServerErrorException
......@@ -451,10 +436,7 @@ class tx_ter_api
$resultCode = ResultCodes::ERROR_DELETEEXTENSIONKEY_KEYDOESNOTEXIST;
}
return [
'resultCode' => $resultCode,
'resultMessages' => []
];
return $this->formatAsSimpleResult($resultCode);
}
/**
......@@ -463,7 +445,7 @@ class tx_ter_api
* @param object $accountData : A valid username and password
* @param object $modifyExtensionKeyData : Fields which should be changed, "extensionKey" is mandatory.
*
* @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 occurred.
* @access public
* @since 2.0.0
* @throws \T3o\Ter\Exception\UnauthorizedException
......@@ -494,10 +476,7 @@ class tx_ter_api
}
}
return [
'resultCode' => $resultCode,
'resultMessages' => []
];
return $this->formatAsSimpleResult($resultCode);
}
/**
......@@ -506,7 +485,7 @@ class tx_ter_api
* @param object $accountData : A valid username and password
* @param object $setReviewStateData : The extension key, version number and the new review state (integer)
*
* @return array simpleResponse-object. An exception is thrown if a fatal error ocurred.
* @return array simpleResponse-object. An exception is thrown if a fatal error occurred.
* @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
* @throws \T3o\Ter\Exception\UnauthorizedException
......@@ -525,10 +504,7 @@ class tx_ter_api
//Regeneration of index file is currently deactived:
//$this->requestUpdateOfExtensionIndexFile();
return [
'resultCode' => ResultCodes::RESULT_GENERAL_OK,
'resultMessages' => []
];
return $this->formatAsSimpleResult(ResultCodes::RESULT_GENERAL_OK);
}
/**
......@@ -539,16 +515,13 @@ class tx_ter_api
* @param object $accountData : A valid username and password
* @param object $extensionVersionsAndIncrementors : An array of extension keys, version numbers and the incrementor
*
* @return array|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 occurred.
* @access public
* @since 2.0.0
*/
public function increaseExtensionDownloadCounters($accountData, $extensionVersionsAndIncrementors)
{
return [
'resultCode' => ResultCodes::RESULT_GENERAL_OK,
'resultMessages' => []
];
return $this->formatAsSimpleResult(ResultCodes::RESULT_GENERAL_OK);
}
/*********************************************************
......@@ -983,7 +956,7 @@ class tx_ter_api
{
$result = ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYCHECKFAILED;
$coreVersionData = GeneralUtility::getUrl(
PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'
\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'
);
$currentCores = json_decode($coreVersionData, true);
if ($currentCores !== null) {
......@@ -1156,11 +1129,7 @@ class tx_ter_api
// Load environment
if (empty($this->tce)) {
$this->helperObj->loadBackendUser();
$this->helperObj->loadLang();
$this->initializeDataHandler();
// Due to the lack of existence of this needed array we define it here to be able to write
$GLOBALS['PAGES_TYPES']['default']['allowedTables'] = '*';
}
// Check if the record already exists and get UID if not given
......@@ -1203,9 +1172,13 @@ class tx_ter_api
*/
protected function initializeDataHandler()
{
$this->helperObj->loadBackendUser();
$this->helperObj->loadLang();
$this->tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$this->tce->bypassWorkspaceRestrictions = true;
$this->tce->start([], []);
// Due to the lack of existence of this needed array we define it here to be able to write
$GLOBALS['PAGES_TYPES']['default']['allowedTables'] = '*';
}
/**
......@@ -1257,4 +1230,18 @@ class tx_ter_api
{
GeneralUtility::makeInstance(\T3o\TerFe2\Service\ExtensionIndexService::class)->requestUpdate();
}
/**
* Returns the structure of th simple SOAP result.
*
* @param string $resultCode
* @return array
*/
protected function formatAsSimpleResult(string $resultCode): array
{
return [
'resultCode' => $resultCode,
'resultMessages' => []
];
}
}
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