29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-25 23:02:55 +00:00

[4.0] Remove JException (#16967)

* Replace JException with Exception class

* Delete JException class

* Replace in doc blocks

* CS

* Remove traces to legacy folder which doesn't exist anymore

* Fix return types

* Check return types
This commit is contained in:
Allon Moritz 2018-02-03 23:12:02 +01:00 committed by George Wilson
parent 58e19566a1
commit 568bf18fcb
19 changed files with 41 additions and 449 deletions

View File

@ -24,7 +24,7 @@ class HtmlView extends BaseHtmlView
/**
* True, if FTP settings should be shown, or an exception.
*
* @var boolean|\JException
* @var boolean|\Exception
*/
protected $ftp = null;

View File

@ -142,7 +142,7 @@ class MenusController extends BaseController
/**
* Temporary method. This should go into the 1.5 to 1.6 upgrade routines.
*
* @return \JException|void \JException instance on error
* @return void
*
* @since 1.6
*/

View File

@ -1263,7 +1263,7 @@ class ItemModel extends AdminModel
/**
* Method rebuild the entire nested set tree.
*
* @return boolean|\JException Boolean true on success, boolean false or \JException instance on error
* @return boolean Boolean true on success, boolean false
*
* @since 1.6
*/
@ -1304,7 +1304,9 @@ class ItemModel extends AdminModel
}
catch (\RuntimeException $e)
{
return \JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
foreach ($items as &$item)
@ -1323,7 +1325,9 @@ class ItemModel extends AdminModel
}
catch (\RuntimeException $e)
{
return \JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
unset($registry);

View File

@ -384,7 +384,7 @@ class ModuleModel extends AdminModel
*
* @param array &$pks An array of primary key IDs.
*
* @return boolean|\JException Boolean true on success, \JException instance on error
* @return boolean Boolean true on success
*
* @since 1.6
* @throws \Exception
@ -463,7 +463,9 @@ class ModuleModel extends AdminModel
}
catch (\RuntimeException $e)
{
return \JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
\JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
return false;
}
}

View File

@ -181,7 +181,7 @@ class LevelsModel extends ListModel
* @param array $pks An array of primary key ids.
* @param integer $order Order position
*
* @return boolean|\JException Boolean true on success, boolean false or \JException instance on error
* @return boolean Boolean true on success, boolean false
*/
public function saveorder($pks, $order)
{
@ -191,7 +191,9 @@ class LevelsModel extends ListModel
if (empty($pks))
{
return \JFactory::getApplication()->enqueueMessage(\JText::_('COM_USERS_ERROR_LEVELS_NOLEVELS_SELECTED'), 'error');
\JFactory::getApplication()->enqueueMessage(\JText::_('COM_USERS_ERROR_LEVELS_NOLEVELS_SELECTED'), 'error');
return false;
}
// Update ordering values

View File

@ -70,7 +70,7 @@ class ArticleModel extends ItemModel
*
* @param integer $pk The id of the article.
*
* @return object|boolean|\JException Menu item data object on success, boolean false or JException instance on error
* @return object|boolean Menu item data object on success, boolean false
*/
public function getItem($pk = null)
{

View File

@ -137,7 +137,7 @@ class ResetModel extends FormModel
*
* @param array $data The data expected for the form.
*
* @return mixed \Exception | \JException | boolean
* @return mixed \Exception | boolean
*
* @since 1.6
*/
@ -183,7 +183,7 @@ class ResetModel extends FormModel
// Check the token and user id.
if (empty($token) || empty($userId))
{
return new \JException(\JText::_('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403);
return new \Exception(\JText::_('COM_USERS_RESET_COMPLETE_TOKENS_MISSING'), 403);
}
// Get the user object.
@ -221,7 +221,7 @@ class ResetModel extends FormModel
// Save the user to the database.
if (!$user->save(true))
{
return new \JException(\JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
return new \Exception(\JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
}
// Flush the user data from the session.
@ -236,7 +236,7 @@ class ResetModel extends FormModel
*
* @param array $data The data expected for the form.
*
* @return mixed \Exception | \JException | boolean
* @return mixed \Exception | boolean
*
* @since 1.6
*/
@ -292,7 +292,7 @@ class ResetModel extends FormModel
}
catch (\RuntimeException $e)
{
return new \JException(\JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
return new \Exception(\JText::sprintf('COM_USERS_DATABASE_ERROR', $e->getMessage()), 500);
}
// Check for a user.
@ -339,7 +339,7 @@ class ResetModel extends FormModel
*
* @param array $data The data expected for the form.
*
* @return mixed \Exception | \JException | boolean
* @return mixed \Exception | boolean
*
* @since 1.6
*/
@ -446,7 +446,7 @@ class ResetModel extends FormModel
// Save the user to the database.
if (!$user->save(true))
{
return new \JException(\JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
return new \Exception(\JText::sprintf('COM_USERS_USER_SAVE_FAILED', $user->getError()), 500);
}
// Assemble the password reset confirmation link.

View File

@ -156,7 +156,6 @@ class LanguageController extends JSONController
}
// Add menus
\JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy');
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables/');
$siteLanguages = $model->getInstalledlangsFrontend();

View File

@ -851,7 +851,6 @@ class LanguagesModel extends BaseInstallationModel
public function addMenuGroup($itemLanguage)
{
// Add menus.
\JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy');
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables/');
// Add Menu Group.

View File

@ -33,9 +33,6 @@ if (!class_exists('JLoader'))
// Setup the autoloaders.
JLoader::setup();
// Register the library base path for the legacy libraries.
JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy');
// Register the library base path for CMS libraries.
JLoader::registerPrefix('J', JPATH_PLATFORM . '/cms', false, true);

View File

@ -52,8 +52,6 @@ if (!class_exists('JLoader'))
// Setup the autoloaders.
JLoader::setup();
JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy');
// Check if the JsonSerializable interface exists already
if (!interface_exists('JsonSerializable'))
{

View File

@ -1,409 +0,0 @@
<?php
/**
* @package Joomla.Legacy
* @subpackage Exception
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Exception object.
*
* @since 1.5
* @deprecated 1.7
*/
class JException extends Exception
{
/**
* Error level.
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $level = null;
/**
* Error code.
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $code = null;
/**
* Error message.
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $message = null;
/**
* Additional info about the error relevant to the developer,
* for example, if a database connect fails, the dsn used
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $info = '';
/**
* Name of the file the error occurred in [Available if backtrace is enabled]
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $file = null;
/**
* Line number the error occurred in [Available if backtrace is enabled]
*
* @var integer
* @since 1.5
* @deprecated 1.7
*/
protected $line = 0;
/**
* Name of the method the error occurred in [Available if backtrace is enabled]
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $function = null;
/**
* Name of the class the error occurred in [Available if backtrace is enabled]
*
* @var string
* @since 1.5
* @deprecated 1.7
*/
protected $class = null;
/**
* @var string Error type.
* @since 1.5
* @deprecated 1.7
*/
protected $type = null;
/**
* Arguments received by the method the error occurred in [Available if backtrace is enabled]
*
* @var array
* @since 1.5
* @deprecated 1.7
*/
protected $args = array();
/**
* Backtrace information.
*
* @var mixed
* @since 1.5
* @deprecated 1.7
*/
protected $backtrace = null;
/**
* Container holding the error messages
*
* @var string[]
* @since 1.6
* @deprecated 1.7
*/
protected $_errors = array();
/**
* Constructor
* - used to set up the error with all needed error details.
*
* @param string $msg The error message
* @param integer $code The error code from the application
* @param integer $level The error level (use the PHP constants E_ALL, E_NOTICE etc.).
* @param string $info Optional: The additional error information.
* @param boolean $backtrace True if backtrace information is to be collected
*
* @since 1.5
* @deprecated 1.7
*/
public function __construct($msg, $code = 0, $level = null, $info = null, $backtrace = false)
{
JLog::add('JException is deprecated.', JLog::WARNING, 'deprecated');
$this->level = $level;
$this->code = $code;
$this->message = $msg;
if ($info != null)
{
$this->info = $info;
}
if ($backtrace && function_exists('debug_backtrace'))
{
$this->backtrace = debug_backtrace();
for ($i = count($this->backtrace) - 1; $i >= 0; --$i)
{
++$i;
if (isset($this->backtrace[$i]['file']))
{
$this->file = $this->backtrace[$i]['file'];
}
if (isset($this->backtrace[$i]['line']))
{
$this->line = $this->backtrace[$i]['line'];
}
if (isset($this->backtrace[$i]['class']))
{
$this->class = $this->backtrace[$i]['class'];
}
if (isset($this->backtrace[$i]['function']))
{
$this->function = $this->backtrace[$i]['function'];
}
if (isset($this->backtrace[$i]['type']))
{
$this->type = $this->backtrace[$i]['type'];
}
$this->args = false;
if (isset($this->backtrace[$i]['args']))
{
$this->args = $this->backtrace[$i]['args'];
}
break;
}
}
parent::__construct($msg, (int) $code);
}
/**
* Returns to error message
*
* @return string Error message
*
* @since 1.6
* @deprecated 1.7
*/
public function __toString()
{
JLog::add('JException::__toString is deprecated.', JLog::WARNING, 'deprecated');
return $this->message;
}
/**
* Returns to error message
*
* @return string Error message
*
* @since 1.5
* @deprecated 1.7
*/
public function toString()
{
JLog::add('JException::toString is deprecated.', JLog::WARNING, 'deprecated');
return (string) $this;
}
/**
* Returns a property of the object or the default value if the property is not set.
*
* @param string $property The name of the property
* @param mixed $default The default value
*
* @return mixed The value of the property or null
*
* @since 1.6
* @deprecated 1.7
* @see JException::getProperties()
*/
public function get($property, $default = null)
{
JLog::add('JException::get is deprecated.', JLog::WARNING, 'deprecated');
if (isset($this->$property))
{
return $this->$property;
}
return $default;
}
/**
* Returns an associative array of object properties
*
* @param boolean $public If true, returns only the public properties
*
* @return array Object properties
*
* @since 1.6
* @deprecated 1.7
* @see JException::get()
*/
public function getProperties($public = true)
{
JLog::add('JException::getProperties is deprecated.', JLog::WARNING, 'deprecated');
$vars = get_object_vars($this);
if ($public)
{
foreach ($vars as $key => $value)
{
if (strpos($key, '_') === 0)
{
unset($vars[$key]);
}
}
}
return $vars;
}
/**
* Get the most recent error message
*
* @param integer $i Option error index
* @param boolean $toString Indicates if Exception objects should return their error message
*
* @return string Error message
*
* @since 1.6
* @deprecated 1.7
*/
public function getError($i = null, $toString = true)
{
JLog::add('JException::getError is deprecated.', JLog::WARNING, 'deprecated');
// Find the error
if ($i === null)
{
// Default, return the last message
$error = end($this->_errors);
}
elseif (!array_key_exists($i, $this->_errors))
{
// If $i has been specified but does not exist, return false
return false;
}
else
{
$error = $this->_errors[$i];
}
// Check if only the string is requested
if ($error instanceof Exception && $toString)
{
return (string) $error;
}
return $error;
}
/**
* Return all errors, if any
*
* @return array Array of error messages or Exception objects
*
* @since 1.6
* @deprecated 1.7
*/
public function getErrors()
{
JLog::add('JException::getErrors is deprecated.', JLog::WARNING, 'deprecated');
return $this->_errors;
}
/**
* Modifies a property of the object, creating it if it does not already exist.
*
* @param string $property The name of the property
* @param mixed $value The value of the property to set
*
* @return mixed Previous value of the property
*
* @since 1.6
* @deprecated 1.7
* @see JException::setProperties()
*/
public function set($property, $value = null)
{
JLog::add('JException::set is deprecated.', JLog::WARNING, 'deprecated');
$previous = $this->$property ?? null;
$this->$property = $value;
return $previous;
}
/**
* Set the object properties based on a named array/hash
*
* @param mixed $properties Either and associative array or another object
*
* @return boolean
*
* @since 1.6
* @deprecated 1.7
* @see JException::set()
*/
public function setProperties($properties)
{
JLog::add('JException::setProperties is deprecated.', JLog::WARNING, 'deprecated');
// Cast to an array
$properties = (array) $properties;
if (is_array($properties))
{
foreach ($properties as $k => $v)
{
$this->$k = $v;
}
return true;
}
return false;
}
/**
* Add an error message
*
* @param string $error Error message
*
* @return void
*
* @since 1.6
* @deprecated 1.7
*/
public function setError($error)
{
JLog::add('JException::setErrors is deprecated.', JLog::WARNING, 'deprecated');
$this->_errors[] = $error;
}
}

View File

@ -845,7 +845,7 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
* @param array $credentials Array('username' => string, 'password' => string)
* @param array $options Array('remember' => boolean)
*
* @return boolean|\JException True on success, false if failed or silent handling is configured, or a \JException object on authentication error.
* @return boolean|\Exception True on success, false if failed or silent handling is configured, or a \Exception object on authentication error.
*
* @since 3.2
*/
@ -884,13 +884,19 @@ abstract class CMSApplication extends WebApplication implements ContainerAwareIn
switch ($authorisation->status)
{
case Authentication::STATUS_EXPIRED:
return \JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_EXPIRED'), 'error');
\JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_EXPIRED'), 'error');
return false;
case Authentication::STATUS_DENIED:
return \JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_DENIED'), 'error');
\JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_DENIED'), 'error');
return false;
default:
return \JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_AUTHORISATION'), 'error');
\JFactory::getApplication()->enqueueMessage(\JText::_('JLIB_LOGIN_AUTHORISATION'), 'error');
return false;
}
}
}

View File

@ -70,7 +70,7 @@ class CaptchaRule extends FormRule
}
else
{
return new \JException($error);
return new \Exception($error);
}
}

View File

@ -1296,7 +1296,7 @@ abstract class AdminModel extends FormModel
* @param array $pks An array of primary key ids.
* @param integer $order +1 or -1
*
* @return boolean|\JException Boolean true on success, false on failure, or \JException if no items are selected
* @return boolean Boolean true on success, false on failure
*
* @since 1.6
*/
@ -1309,7 +1309,9 @@ abstract class AdminModel extends FormModel
if (empty($pks))
{
return \JFactory::getApplication()->enqueueMessage(\JText::_($this->text_prefix . '_ERROR_NO_ITEMS_SELECTED'), 'error');
\JFactory::getApplication()->enqueueMessage(\JText::_($this->text_prefix . '_ERROR_NO_ITEMS_SELECTED'), 'error');
return false;
}
$orderingField = $this->table->getColumnAlias('ordering');

View File

@ -101,7 +101,7 @@ class CategoryView extends HtmlView
/**
* Method with common display elements used in category list displays
*
* @return boolean|\JException|void Boolean false or \JException instance on error, nothing otherwise
* @return void
*
* @since 3.2
*/

View File

@ -21,9 +21,6 @@
<testsuite name="libraries-platform">
<directory>tests/unit/suites/libraries/joomla</directory>
</testsuite>
<testsuite name="libraries-legacy">
<directory>tests/unit/suites/libraries/legacy</directory>
</testsuite>
<testsuite name="administrator">
<directory>tests/unit/suites/administrator</directory>
</testsuite>
@ -45,7 +42,6 @@
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">libraries/cms</directory>
<directory suffix=".php">libraries/joomla</directory>
<directory suffix=".php">libraries/legacy</directory>
<directory suffix=".php">libraries/src</directory>
<directory suffix=".php">administrator/components/com_finder/helpers/indexer</directory>
<directory suffix=".php">plugins</directory>

View File

@ -555,7 +555,6 @@ class JLoaderTest extends \PHPUnit\Framework\TestCase
// Add the libraries/joomla and libraries/legacy folders to the array
JLoader::registerPrefix('J', JPATH_PLATFORM . '/joomla');
JLoader::registerPrefix('J', JPATH_PLATFORM . '/legacy');
// Get the current prefixes array
$prefixes = TestReflection::getValue('JLoader', 'prefixes');

View File

@ -14,9 +14,6 @@
<testsuite name="libraries-platform">
<directory>tests/unit/suites/libraries/joomla</directory>
</testsuite>
<testsuite name="libraries-legacy">
<directory>tests/unit/suites/libraries/legacy</directory>
</testsuite>
<testsuite name="FinderIndexer">
<directory>tests/unit/suites/finderIndexer</directory>
</testsuite>