Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin app - catch exceptions thrown by JLog::add() #13504

Merged
merged 1 commit into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions administrator/components/com_admin/helpers/html/phpsetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ public static function string($val)
*/
public static function integer($val)
{
JLog::add(
'JHtmlPhpSetting::integer() is deprecated. Use intval() or casting instead.',
JLog::WARNING,
'deprecated'
);
try
{
JLog::add(sprintf('%s() is deprecated. Use intval() or casting instead.', __METHOD__), JLog::WARNING, 'deprecated');
}
catch (RuntimeException $exception)
{
// Informational log only
}

return (int) $val;
}
Expand Down
12 changes: 11 additions & 1 deletion administrator/components/com_admin/models/sysinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,17 @@ public function getExtensions()
}
catch (Exception $e)
{
JLog::add(JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()), JLog::WARNING, 'jerror');
try
{
JLog::add(JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not better to call setError here? Especially given this is largely being used for non-html dumps and the view can format handle appropriately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well remember, most views have a if $this->get('Errors') style check which basically turns the view into an error page if there are errors found. The current handling of this method doesn't seem to indicate it should cause that to happen.

JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()),
'warning'
);
}

return $installed;
}
Expand Down
10 changes: 9 additions & 1 deletion administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ public function update($installer)
$options['text_file'] = 'joomla_update.php';

JLog::addLogger($options, JLog::INFO, array('Update', 'databasequery', 'jerror'));
JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_DELETE_FILES'), JLog::INFO, 'Update');

try
{
JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_DELETE_FILES'), JLog::INFO, 'Update');
}
catch (RuntimeException $exception)
{
// Informational log only
}

// This needs to stay for 2.5 update compatibility
$this->deleteUnexistingFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ public function saveorder()
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

JLog::add('CategoriesControllerCategories::saveorder() is deprecated. Function will be removed in 4.0', JLog::WARNING, 'deprecated');
try
{
JLog::add(sprintf('%s() is deprecated. Function will be removed in 4.0.', __METHOD__), JLog::WARNING, 'deprecated');
}
catch (RuntimeException $exception)
{
// Informational log only
}

// Get the arrays from the Request
$order = $this->input->post->get('order', null, 'array');
Expand Down
13 changes: 12 additions & 1 deletion administrator/components/com_categories/helpers/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ public static function addSubmenu($extension)
public static function getActions($extension, $categoryId = 0)
{
// Log usage of deprecated function
JLog::add(__METHOD__ . '() is deprecated, use JHelperContent::getActions() with new arguments order instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated, use JHelperContent::getActions() with new arguments order instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

// Get list of actions
return JHelperContent::getActions($extension, 'category', $categoryId);
Expand Down
17 changes: 12 additions & 5 deletions administrator/components/com_config/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@ public function display($cachable = false, $urlparams = array())
// Set the default view name and format from the Request.
$vName = $this->input->get('view', 'application');

JLog::add(
'ConfigController is deprecated. Use ConfigControllerApplicationDisplay or ConfigControllerComponentDisplay instead.',
JLog::WARNING,
'deprecated'
);
try
{
JLog::add(
sprintf('%s is deprecated. Use ConfigControllerApplicationDisplay or ConfigControllerComponentDisplay instead.', __CLASS__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

if (ucfirst($vName) == 'Application')
{
Expand Down
39 changes: 36 additions & 3 deletions administrator/components/com_config/controllers/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ public function __construct($config = array())
*/
public function save()
{
JLog::add('ConfigControllerApplication is deprecated. Use ConfigControllerApplicationSave instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use ConfigControllerApplicationSave instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

$controller = new ConfigControllerApplicationSave;

Expand All @@ -59,7 +70,18 @@ public function save()
*/
public function cancel()
{
JLog::add('ConfigControllerApplication is deprecated. Use ConfigControllerApplicationCancel instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use ConfigControllerApplicationCancel instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

$controller = new ConfigControllerApplicationCancel;

Expand All @@ -76,7 +98,18 @@ public function cancel()
*/
public function removeroot()
{
JLog::add('ConfigControllerApplication is deprecated. Use ConfigControllerApplicationRemoveroot instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use ConfigControllerApplicationRemoveroot instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

$controller = new ConfigControllerApplicationRemoveroot;

Expand Down
26 changes: 24 additions & 2 deletions administrator/components/com_config/controllers/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ public function __construct($config = array())
*/
public function cancel()
{
JLog::add('ConfigControllerComponent is deprecated. Use ConfigControllerComponentCancel instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use ConfigControllerComponentCancel instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

$controller = new ConfigControllerComponentCancel;

Expand All @@ -59,7 +70,18 @@ public function cancel()
*/
public function save()
{
JLog::add('ConfigControllerComponent is deprecated. Use ConfigControllerComponentSave instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use ConfigControllerComponentSave instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

$controller = new ConfigControllerComponentSave;

Expand Down
10 changes: 9 additions & 1 deletion administrator/components/com_config/model/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,15 @@ public function save($data)

if ($error)
{
JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror');
try
{
JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
$app->enqueueMessage(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), 'warning');
}

$data['caching'] = 0;
}
}
Expand Down
17 changes: 12 additions & 5 deletions administrator/components/com_config/models/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

defined('_JEXEC') or die;

JLog::add(
'ConfigModelApplication has moved from ' . __DIR__ . '/application.php to ' . dirname(__DIR__) . '/model/application.',
JLog::WARNING,
'deprecated'
);
try
{
JLog::add(
sprintf('ConfigModelApplication has moved from %1$s to %2$s', __FILE__, dirname(__DIR__) . '/model/application.php'),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

include_once JPATH_ADMINISTRATOR . '/components/com_config/model/application.php';
17 changes: 12 additions & 5 deletions administrator/components/com_config/models/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

defined('_JEXEC') or die;

JLog::add(
'ConfigModelComponent has moved from ' . __FILE__ . ' to ' . dirname(__DIR__) . '/model/component.php.',
JLog::WARNING,
'deprecated'
);
try
{
JLog::add(
sprintf('ConfigModelComponent has moved from %1$s to %2$s', __FILE__, dirname(__DIR__) . '/model/component.php'),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

include_once JPATH_ADMINISTRATOR . '/components/com_config/model/component.php';
13 changes: 12 additions & 1 deletion administrator/components/com_content/helpers/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@ public static function addSubmenu($vName)
*/
public static function filterText($text)
{
JLog::add('ContentHelper::filterText() is deprecated. Use JComponentHelper::filterText() instead.', JLog::WARNING, 'deprecated');
try
{
JLog::add(
sprintf('%s() is deprecated. Use JComponentHelper::filterText() instead', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}

return JComponentHelper::filterText($text);
}
Expand Down
36 changes: 32 additions & 4 deletions administrator/components/com_contenthistory/models/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,27 @@ public function delete(&$pks)

if ($error)
{
JLog::add($error, JLog::WARNING, 'jerror');
try
{
JLog::add($error, JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage($error, 'warning');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one already has an error set, look above; the $error value comes from $this->getError()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then do we need to do anything other than pass here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this weren't logging to the jerror category I'd just leave a no-op comment. But since the app bootstrap sets up a logger for that category to throw messages in the message queue, I'm doing the same thing in this (and others doing the same) catch case.

}

return false;
}
else
{
JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
try
{
JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 'warning');
}

return false;
}
Expand Down Expand Up @@ -264,13 +278,27 @@ public function keep(&$pks)

if ($error)
{
JLog::add($error, JLog::WARNING, 'jerror');
try
{
JLog::add($error, JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage($error, 'warning');
}

return false;
}
else
{
JLog::add(JText::_('COM_CONTENTHISTORY_ERROR_KEEP_NOT_PERMITTED'), JLog::WARNING, 'jerror');
try
{
JLog::add(JText::_('COM_CONTENTHISTORY_ERROR_KEEP_NOT_PERMITTED'), JLog::WARNING, 'jerror');
}
catch (RuntimeException $exception)
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_CONTENTHISTORY_ERROR_KEEP_NOT_PERMITTED'), 'warning');
}

return false;
}
Expand Down