Commit 9d79814b authored by Stefan Froemken's avatar Stefan Froemken

Move exception classes to namespace versins

parent 79a4bb95
Pipeline #2243 passed with stages
in 1 minute and 27 seconds
<?php <?php
/** namespace T3o\Ter\Exception;
/*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
* It is free software; you can redistribute it and/or modify it under * It is free software; you can redistribute it and/or modify it under
...@@ -12,6 +14,7 @@ ...@@ -12,6 +14,7 @@
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
class tx_ter_exception extends Exception
{ class Exception extends \Exception {
} }
<?php <?php
/**
namespace T3o\Ter\Exception;
/*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
* It is free software; you can redistribute it and/or modify it under * It is free software; you can redistribute it and/or modify it under
...@@ -12,9 +15,6 @@ ...@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
/** class FailedDependencyException extends Exception {
* an exception when user authentication is required (HTTP-Status-Code 401)
*/
class tx_ter_exception_unauthorized extends tx_ter_exception
{
} }
<?php <?php
/**
namespace T3o\Ter\Exception;
/*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
* It is free software; you can redistribute it and/or modify it under * It is free software; you can redistribute it and/or modify it under
...@@ -12,9 +15,6 @@ ...@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
/** class InternalServerErrorException extends Exception {
* Exception reflecting that version exists in repository (HTTP error code 424)
*/
class tx_ter_exception_versionExists extends tx_ter_exception
{
} }
<?php <?php
/**
namespace T3o\Ter\Exception;
/*
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
* It is free software; you can redistribute it and/or modify it under * It is free software; you can redistribute it and/or modify it under
...@@ -12,9 +15,6 @@ ...@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
/** class NotFoundException extends Exception {
* Exception reflecting that required dependencies are not met (HTTP error code 424)
*/
class tx_ter_exception_failedDependency extends tx_ter_exception
{
} }
<?php
namespace T3o\Ter\Exception;
/*
* 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!
*/
class UnauthorizedException extends Exception {
}
<?php
namespace T3o\Ter\Exception;
/*
* 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!
*/
class VersionExistsException extends Exception {
}
This diff is collapsed.
...@@ -131,11 +131,12 @@ class tx_ter_helper ...@@ -131,11 +131,12 @@ class tx_ter_helper
* @param object $accountData : Account data information with username, password and upload password * @param object $accountData : Account data information with username, password and upload password
* @return mixed If success, returns array of fe_users, otherwise error string. * @return mixed If success, returns array of fe_users, otherwise error string.
* @access public * @access public
* @throws \T3o\Ter\Exception\UnauthorizedException
*/ */
public function getValidUser($accountData) public function getValidUser($accountData)
{ {
if (!strlen($accountData->username) || (!strlen($accountData->password))) { if (!strlen($accountData->username) || (!strlen($accountData->password))) {
throw new tx_ter_exception_unauthorized('No user or no password submitted.', TX_TER_ERROR_GENERAL_NOUSERORPASSWORD); throw new \T3o\Ter\Exception\UnauthorizedException('No user or no password submitted.', TX_TER_ERROR_GENERAL_NOUSERORPASSWORD);
} }
$res = $this->getDatabaseConnection()->exec_SELECTquery( $res = $this->getDatabaseConnection()->exec_SELECTquery(
...@@ -149,10 +150,10 @@ class tx_ter_helper ...@@ -149,10 +150,10 @@ class tx_ter_helper
if (!$this->userIsAlreadyLoggedIn( $accountData if (!$this->userIsAlreadyLoggedIn( $accountData
) && !$this->ldapValidationSucceeded($accountData) ) && !$this->ldapValidationSucceeded($accountData)
) { ) {
throw new tx_ter_exception_unauthorized ('Wrong password.', TX_TER_ERROR_GENERAL_WRONGPASSWORD); throw new \T3o\Ter\Exception\UnauthorizedException('Wrong password.', TX_TER_ERROR_GENERAL_WRONGPASSWORD);
} }
} else { } else {
throw new tx_ter_exception_unauthorized('The specified user does not exist. You need to login first on extensions.typo3.org.', TX_TER_ERROR_GENERAL_USERNOTFOUND); throw new \T3o\Ter\Exception\UnauthorizedException('The specified user does not exist. You need to login first on extensions.typo3.org.', TX_TER_ERROR_GENERAL_USERNOTFOUND);
} }
$row['admin'] = (intval($this->pluginObj->conf['adminFrontendUsergroupUid']) && GeneralUtility::inList( $row['admin'] = (intval($this->pluginObj->conf['adminFrontendUsergroupUid']) && GeneralUtility::inList(
...@@ -341,12 +342,13 @@ class tx_ter_helper ...@@ -341,12 +342,13 @@ class tx_ter_helper
* *
* @return void * @return void
* @access public * @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
*/ */
public function writeExtensionIndexfile() public function writeExtensionIndexfile()
{ {
GeneralUtility::devLog('writing extension index!', 'tx_ter_helper', 0); GeneralUtility::devLog('writing extension index!', 'tx_ter_helper', 0);
if (!@is_dir($this->pluginObj->repositoryDir)) { if (!@is_dir($this->pluginObj->repositoryDir)) {
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Extension repository directory does not exist.', 'Extension repository directory does not exist.',
TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST
); );
...@@ -452,7 +454,7 @@ class tx_ter_helper ...@@ -452,7 +454,7 @@ class tx_ter_helper
// Write XML data to disk: // Write XML data to disk:
$fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.xml.gz', 'wb'); $fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.xml.gz', 'wb');
if (!$fh) { if (!$fh) {
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Write error while writing extensions index file: ' . $this->pluginObj->repositoryDir . 'extensions.xml', 'Write error while writing extensions index file: ' . $this->pluginObj->repositoryDir . 'extensions.xml',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
); );
...@@ -462,7 +464,7 @@ class tx_ter_helper ...@@ -462,7 +464,7 @@ class tx_ter_helper
if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.xml.gz') > 0) { if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.xml.gz') > 0) {
GeneralUtility::devLog('Newly created extension index is zero bytes!', 'tx_ter_helper', 0); GeneralUtility::devLog('Newly created extension index is zero bytes!', 'tx_ter_helper', 0);
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Write error while writing extensions index file (zero bytes): ' . $this->pluginObj->repositoryDir . 'extensions.xml', 'Write error while writing extensions index file (zero bytes): ' . $this->pluginObj->repositoryDir . 'extensions.xml',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
); );
...@@ -479,7 +481,7 @@ class tx_ter_helper ...@@ -479,7 +481,7 @@ class tx_ter_helper
// Write serialized array file to disk: // Write serialized array file to disk:
$fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.bin', 'wb'); $fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.bin', 'wb');
if (!$fh) { if (!$fh) {
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Write error while writing extensions index file: ' . $this->pluginObj->repositoryDir . 'extensions.bin', 'Write error while writing extensions index file: ' . $this->pluginObj->repositoryDir . 'extensions.bin',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
); );
...@@ -489,7 +491,7 @@ class tx_ter_helper ...@@ -489,7 +491,7 @@ class tx_ter_helper
if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.bin') > 0) { if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.bin') > 0) {
GeneralUtility::devLog('Newly created extension index is zero bytes!', 'tx_ter_helper', 0); GeneralUtility::devLog('Newly created extension index is zero bytes!', 'tx_ter_helper', 0);
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Write error while writing extensions index file (zero bytes): ' . $this->pluginObj->repositoryDir . 'extensions.bin', 'Write error while writing extensions index file (zero bytes): ' . $this->pluginObj->repositoryDir . 'extensions.bin',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
); );
......
...@@ -497,13 +497,14 @@ function versionConv($input, $rev = false) ...@@ -497,13 +497,14 @@ function versionConv($input, $rev = false)
* *
* @return void * @return void
* @access public * @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
*/ */
function writeExtensionIndexfile() function writeExtensionIndexfile()
{ {
global $TYPO3_DB; global $TYPO3_DB;
if (!@is_dir($GLOBALS['repositoryDir'])) { if (!@is_dir($GLOBALS['repositoryDir'])) {
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Extension repository directory does not exist.', 'Extension repository directory does not exist.',
TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST
); );
...@@ -580,7 +581,7 @@ function writeExtensionIndexfile() ...@@ -580,7 +581,7 @@ function writeExtensionIndexfile()
// Write XML data to disc: // Write XML data to disc:
$fh = fopen($GLOBALS['repositoryDir'] . 'cli-extensions.xml.gz', 'wb'); $fh = fopen($GLOBALS['repositoryDir'] . 'cli-extensions.xml.gz', 'wb');
if (!$fh) { if (!$fh) {
throw new tx_ter_exception_internalServerError( throw new \T3o\Ter\Exception\InternalServerErrorException(
'Write error while writing extensions index file: ' . $GLOBALS['repositoryDir'] . 'extensions.xml', 'Write error while writing extensions index file: ' . $GLOBALS['repositoryDir'] . 'extensions.xml',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
); );
......
<?php
/**
* 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!
*/
/**
* an exception when some internal configuration causes an error (HTTP-Status-Code 500)
*/
class tx_ter_exception_internalServerError extends tx_ter_exception
{
}
<?php
/**
* 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!
*/
/**
* an exception when some resource was not found - usually do to some
* wrong parameters from the user (HTTP-Status-Code 404)
*/
class tx_ter_exception_notFound extends tx_ter_exception
{
}
...@@ -10,10 +10,4 @@ return [ ...@@ -10,10 +10,4 @@ return [
'tx_ter_updatecurrentversionlisttask' => $extensionPath . 'task/class.tx_ter_updateCurrentVersionListTask.php', 'tx_ter_updatecurrentversionlisttask' => $extensionPath . 'task/class.tx_ter_updateCurrentVersionListTask.php',
'tx_ter_updateextensionindextask' => $extensionPath . 'task/class.tx_ter_updateExtensionIndexTask.php', 'tx_ter_updateextensionindextask' => $extensionPath . 'task/class.tx_ter_updateExtensionIndexTask.php',
'tx_ter_updateextensionindextask_additionalfieldprovider' => $extensionPath . 'task/class.tx_ter_updateExtensionIndexTask_additionalFieldProvider.php', 'tx_ter_updateextensionindextask_additionalfieldprovider' => $extensionPath . 'task/class.tx_ter_updateExtensionIndexTask_additionalFieldProvider.php',
'tx_ter_exception' => $extensionPath . 'class.tx_ter_exception.php',
'tx_ter_exception_unauthorized' => $extensionPath . 'exception/class.tx_ter_exception_unauthorized.php',
'tx_ter_exception_faileddependency' => $extensionPath . 'exception/class.tx_ter_exception_failedDependency.php',
'tx_ter_exception_versionexists' => $extensionPath . 'exception/class.tx_ter_exception_versionExists.php',
'tx_ter_exception_internalservererror' => $extensionPath . 'exception/class.tx_ter_exception_internalServerError.php',
'tx_ter_exception_notfound' => $extensionPath . 'exception/class.tx_ter_exception_notFound.php',
]; ];
...@@ -74,7 +74,7 @@ class tx_ter_pi1 extends AbstractPlugin ...@@ -74,7 +74,7 @@ class tx_ter_pi1 extends AbstractPlugin
$server->handle(file_get_contents("php://input")); $server->handle(file_get_contents("php://input"));
// Due to different behaviour on stage and prod server we need this exit to prevent wrong XML response // Due to different behaviour on stage and prod server we need this exit to prevent wrong XML response
exit(); exit();
} catch (tx_ter_exception $e) { } catch (\T3o\Ter\Exception\Exception $e) {
/** /**
* @author Christian Zenker <christian.zenker@599media.de> * @author Christian Zenker <christian.zenker@599media.de>
* @see http://forge.typo3.org/issues/44135 * @see http://forge.typo3.org/issues/44135
...@@ -86,13 +86,13 @@ class tx_ter_pi1 extends AbstractPlugin ...@@ -86,13 +86,13 @@ class tx_ter_pi1 extends AbstractPlugin
* That's why there is an own set of exceptions defined that basically stand for a status code. * That's why there is an own set of exceptions defined that basically stand for a status code.
*/ */
$statusCode = 404; $statusCode = 404;
if ($e instanceof tx_ter_exception_unauthorized) { if ($e instanceof \T3o\Ter\Exception\UnauthorizedException) {
$statusCode = 401; $statusCode = 401;
} elseif ($e instanceof tx_ter_exception_notFound) { } elseif ($e instanceof \T3o\Ter\Exception\NotFoundException) {
$statusCode = 404; $statusCode = 404;
} elseif ($e instanceof tx_ter_exception_failedDependency) { } elseif ($e instanceof \T3o\Ter\Exception\FailedDependencyException) {
$statusCode = 424; $statusCode = 424;
} elseif ($e instanceof tx_ter_exception_internalServerError) { } elseif ($e instanceof \T3o\Ter\Exception\InternalServerErrorException) {
$statusCode = 500; $statusCode = 500;
error_log(sprintf('TER Server internal error occurred. Error message is: "%s"', $e->getMessage())); error_log(sprintf('TER Server internal error occurred. Error message is: "%s"', $e->getMessage()));
} }
......
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