Skip to content

Commit

Permalink
More error collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Aug 16, 2023
1 parent baff877 commit 22fdb3d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 40 deletions.
20 changes: 9 additions & 11 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected function clearStatsCache()
->where($db->quoteName('element') . ' = ' . $db->quote('stats'))
)->loadResult();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
$this->collectError(__METHOD__, $e);

return;
}
Expand All @@ -213,7 +213,7 @@ protected function clearStatsCache()
try {
$db->setQuery($query)->execute();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
$this->collectError(__METHOD__, $e);

return;
}
Expand Down Expand Up @@ -8080,6 +8080,8 @@ public function updateAssets($installer)
$asset->setLocation(1, 'last-child');

if (!$asset->store()) {
$this->collectError(__METHOD__, new \Exception($asset->getError(true)));

// Install failed, roll back changes
$installer->abort(Text::sprintf('JLIB_INSTALLER_ABORT_COMP_INSTALL_ROLLBACK', $asset->getError(true)));

Expand Down Expand Up @@ -8113,8 +8115,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
try {
$rows = $db->loadRowList(0);
} catch (Exception $e) {
// Render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
$this->collectError(__METHOD__, $e);

if ($doDbFixMsg) {
// Show an error message telling to check database problems
Expand All @@ -8141,8 +8142,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
try {
$convertedDB = $db->loadResult();
} catch (Exception $e) {
// Render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
$this->collectError(__METHOD__, $e);

if ($doDbFixMsg) {
// Show an error message telling to check database problems
Expand Down Expand Up @@ -8174,8 +8174,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
} catch (Exception $e) {
$converted = $convertedDB;

// Still render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
$this->collectError(__METHOD__, $e);
}
}
}
Expand Down Expand Up @@ -8209,8 +8208,7 @@ public function convertTablesToUtf8mb4($doDbFixMsg = false)
} catch (Exception $e) {
$converted = 99;

// Still render the error message from the Exception object
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
$this->collectError(__METHOD__, $e);
}
}
}
Expand Down Expand Up @@ -8863,7 +8861,7 @@ protected function addUserAuthProviderColumn(): void
try {
$db->setQuery($query)->execute();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
$this->collectError(__METHOD__, $e);

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Controller\BaseController;
Expand Down Expand Up @@ -41,19 +42,16 @@ public function download()
{
$this->checkToken();

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
Log::addLogger($options, Log::INFO, ['Update', 'databasequery', 'jerror']);
$user = $this->app->getIdentity();
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');
$user = $this->app->getIdentity();

try {
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_START', $user->id, $user->name, \JVERSION), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
}

/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');
$result = $model->download();
$file = $result['basename'];

Expand Down Expand Up @@ -109,19 +107,15 @@ public function install()
$this->checkToken('get');
$this->app->setUserState('com_joomlaupdate.oldversion', JVERSION);

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
Log::addLogger($options, Log::INFO, ['Update', 'databasequery', 'jerror']);
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

try {
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_INSTALL'), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
}

/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

$file = $this->app->getUserState('com_joomlaupdate.file', null);
$model->createRestorationFile($file);

Expand Down Expand Up @@ -150,7 +144,22 @@ public function finalise()
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

$model->finaliseUpgrade();
try {
$model->finaliseUpgrade();
} catch (\Throwable $e) {
$model->collectError('finaliseUpgrade', $e);
}

// Check for update errors
if ($model->getErrors()) {
$this->app->setUserState('com_joomlaupdate.update_finished_with_error', true);
}

// Check for captured output messages in the installer
$msg = Installer::getInstance()->get('extension_message');
if ($msg) {
$this->app->setUserState('com_joomlaupdate.extension_message', $msg);
}

$url = 'index.php?option=com_joomlaupdate&task=update.cleanup&' . Session::getFormToken() . '=1';
$this->setRedirect($url);
Expand All @@ -175,29 +184,28 @@ public function cleanup()
return;
}

$options['format'] = '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}';
$options['text_file'] = 'joomla_update.php';
Log::addLogger($options, Log::INFO, ['Update', 'databasequery', 'jerror']);
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

try {
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP'), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
$model->cleanUp();
} catch (\Throwable $e) {
$model->collectError('cleanUp', $e);
}

/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');

$model->cleanUp();
// Check for update errors
if ($model->getErrors()) {
$this->app->setUserState('com_joomlaupdate.update_finished_with_error', true);
}

$url = 'index.php?option=com_joomlaupdate&view=joomlaupdate&layout=complete';
$this->setRedirect($url);

try {
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', \JVERSION), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
// In case for errored update, redirect to component view
if ($this->app->getUserState('com_joomlaupdate.update_finished_with_error')) {
$url .= '&tmpl=component';
}

$this->setRedirect($url);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,12 @@ public function finaliseUpgrade()
*/
public function cleanUp()
{
try {
Log::add(Text::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP'), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
}

// Load overrides plugin.
PluginHelper::importPlugin('installer');

Expand Down Expand Up @@ -911,6 +917,12 @@ public function cleanUp()
// Trigger event after joomla update.
$app->triggerEvent('onJoomlaAfterUpdate', [$oldVersion]);
$app->setUserState('com_joomlaupdate.oldversion', null);

try {
Log::add(Text::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', \JVERSION), Log::INFO, 'Update');
} catch (\RuntimeException $exception) {
// Informational log only
}
}

/**
Expand Down Expand Up @@ -1763,7 +1775,7 @@ function ($value) {
*
* @since __DEPLOY_VERSION__
*/
protected function collectError(string $context, \Throwable $error)
public function collectError(string $context, \Throwable $error)
{
// Store error for further processing by controller
$this->setError($error);
Expand Down

0 comments on commit 22fdb3d

Please sign in to comment.