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
/**
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
......@@ -12,6 +14,7 @@
*
* The TYPO3 project - inspiring people to share!
*/
class tx_ter_exception extends Exception
{
class Exception 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
......@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share!
*/
/**
* an exception when user authentication is required (HTTP-Status-Code 401)
*/
class tx_ter_exception_unauthorized extends tx_ter_exception
{
class FailedDependencyException 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
......@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share!
*/
/**
* Exception reflecting that version exists in repository (HTTP error code 424)
*/
class tx_ter_exception_versionExists extends tx_ter_exception
{
class InternalServerErrorException 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
......@@ -12,9 +15,6 @@
* The TYPO3 project - inspiring people to share!
*/
/**
* Exception reflecting that required dependencies are not met (HTTP error code 424)
*/
class tx_ter_exception_failedDependency extends tx_ter_exception
{
class NotFoundException 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 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
* @param object $accountData : Account data information with username, password and upload password
* @return mixed If success, returns array of fe_users, otherwise error string.
* @access public
* @throws \T3o\Ter\Exception\UnauthorizedException
*/
public function getValidUser($accountData)
{
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(
......@@ -149,10 +150,10 @@ class tx_ter_helper
if (!$this->userIsAlreadyLoggedIn( $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 {
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(
......@@ -341,12 +342,13 @@ class tx_ter_helper
*
* @return void
* @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
*/
public function writeExtensionIndexfile()
{
GeneralUtility::devLog('writing extension index!', 'tx_ter_helper', 0);
if (!@is_dir($this->pluginObj->repositoryDir)) {
throw new tx_ter_exception_internalServerError(
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Extension repository directory does not exist.',
TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST
);
......@@ -452,7 +454,7 @@ class tx_ter_helper
// Write XML data to disk:
$fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.xml.gz', 'wb');
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',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
);
......@@ -462,7 +464,7 @@ class tx_ter_helper
if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.xml.gz') > 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',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
);
......@@ -479,7 +481,7 @@ class tx_ter_helper
// Write serialized array file to disk:
$fh = fopen($this->pluginObj->repositoryDir . 'new-extensions.bin', 'wb');
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',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
);
......@@ -489,7 +491,7 @@ class tx_ter_helper
if (!@filesize($this->pluginObj->repositoryDir . 'new-extensions.bin') > 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',
TX_TER_ERROR_UPLOADEXTENSION_WRITEERRORWHILEWRITINGEXTENSIONSINDEX
);
......
......@@ -497,13 +497,14 @@ function versionConv($input, $rev = false)
*
* @return void
* @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
*/
function writeExtensionIndexfile()
{
global $TYPO3_DB;
if (!@is_dir($GLOBALS['repositoryDir'])) {
throw new tx_ter_exception_internalServerError(
throw new \T3o\Ter\Exception\InternalServerErrorException(
'Extension repository directory does not exist.',
TX_TER_ERROR_GENERAL_EXTREPDIRDOESNTEXIST
);
......@@ -580,7 +581,7 @@ function writeExtensionIndexfile()
// Write XML data to disc:
$fh = fopen($GLOBALS['repositoryDir'] . 'cli-extensions.xml.gz', 'wb');
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',
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 [
'tx_ter_updatecurrentversionlisttask' => $extensionPath . 'task/class.tx_ter_updateCurrentVersionListTask.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_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
$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
exit();
} catch (tx_ter_exception $e) {
} catch (\T3o\Ter\Exception\Exception $e) {
/**
* @author Christian Zenker <christian.zenker@599media.de>
* @see http://forge.typo3.org/issues/44135
......@@ -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.
*/
$statusCode = 404;
if ($e instanceof tx_ter_exception_unauthorized) {
if ($e instanceof \T3o\Ter\Exception\UnauthorizedException) {
$statusCode = 401;
} elseif ($e instanceof tx_ter_exception_notFound) {
} elseif ($e instanceof \T3o\Ter\Exception\NotFoundException) {
$statusCode = 404;
} elseif ($e instanceof tx_ter_exception_failedDependency) {
} elseif ($e instanceof \T3o\Ter\Exception\FailedDependencyException) {
$statusCode = 424;
} elseif ($e instanceof tx_ter_exception_internalServerError) {
} elseif ($e instanceof \T3o\Ter\Exception\InternalServerErrorException) {
$statusCode = 500;
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