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

Improve Joomla! Update error state #38002

Merged
merged 4 commits into from
Jun 8, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions administrator/components/com_joomlaupdate/extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1942,8 +1942,44 @@ function getConfiguration(): ?array
$configuration = getConfiguration();
$enabled = !empty($configuration);

/**
* Sets the PHP timeout to 3600 seconds
*
* @return void
* @since __DEPLOY_VERSION__
*/
function setLongTimeout()
{
if (!function_exists('ini_set'))
{
return;
}

ini_set('max_execution_time', 3600);
}

/**
* Sets the memory limit to 1GiB
*
* @return void
* @since __DEPLOY_VERSION__
*/
function setHugeMemoryLimit()
{
if (!function_exists('ini_set'))
{
return;
}

ini_set('memory_limit', 1073741824);
}

if ($enabled)
{
// Try to set a very large memory and timeout limit
setLongTimeout();
setHugeMemoryLimit();

$sourcePath = $configuration['setup.sourcepath'] ?? '';
$sourceFile = $configuration['setup.sourcefile'] ?? '';
$destDir = ($configuration['setup.destdir'] ?? null) ?: __DIR__;
Expand Down
76 changes: 43 additions & 33 deletions administrator/components/com_joomlaupdate/tmpl/update/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Help\Help;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
Expand Down Expand Up @@ -56,36 +57,7 @@
$helpUrl = Help::createUrl('JHELP_COMPONENTS_JOOMLA_UPDATE', false);
?>

<div class="modal fade"
id="errorDialog"
tabindex="-1"
role="dialog"
aria-labelledby="errorDialogLabel"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="errorDialogLabel"></h3>
<button type="button" class="btn-close novalidate" data-bs-dismiss="modal"
aria-label="<?php echo Text::_('JLIB_HTML_BEHAVIOR_CLOSE') ?>">
</div>
<div class="modal-body p-3">
<div id="errorDialogMessage"></div>
<div>
<a href="<?php echo $helpUrl ?>"
target="_blank"
class="btn btn-info">
<span class="fa fa-info-circle" aria-hidden="true"></span>
<?php echo Text::_('COM_JOOMLAUPDATE_ERRORMODAL_BTN_HELP') ?>
</a>
</div>
</div>
</div>
</div>
</div>

<div class="px-4 py-5 my-5 text-center">
<div class="px-4 py-5 my-5 text-center" id="joomlaupdate-progress">
<span class="fa-8x mb-4 icon-loop joomlaupdate" aria-hidden="true"></span>
<h1 class="display-5 fw-bold"><?php echo Text::_('COM_JOOMLAUPDATE_UPDATING_HEAD') ?></h1>
<div class="col-lg-6 mx-auto">
Expand Down Expand Up @@ -116,9 +88,47 @@ class="btn btn-info">
</div>
</div>
</div>
<div class="d-none justify-content-sm-center" id="update-help">
<a href="<?php echo $helpUrl; ?>" target="_blank"
class="btn btn-outline-secondary btn-lg px-4"><?php echo Text::_('JGLOBAL_LEARN_MORE'); ?></a>
</div>
</div>

<div class="px-4 d-none" id="joomlaupdate-error">
<div class="card border-danger">
<h1 class="card-header bg-danger text-white" id="errorDialogLabel"></h1>
<div class="card-body">
<div id="errorDialogMessage"></div>
</div>
<div class="card-footer">
<div class="d-flex flex-row flex-wrap gap-2 align-items-center">
<div>
<a href="<?php echo $helpUrl ?>"
target="_blank"
class="btn btn-info">
<span class="fa fa-info-circle" aria-hidden="true"></span>
<?php echo Text::_('COM_JOOMLAUPDATE_ERRORMODAL_BTN_HELP') ?>
</a>
</div>
<div>
<button type="button" id="joomlaupdate-resume"
class="btn btn-primary">
<span class="fa fa-play" aria-hidden="true"></span>
<?php echo Text::_('COM_JOOMLAUPDATE_ERRORSTATE_BTN_RETRY') ?>
</button>
</div>
<div>
<button type="button" id="joomlaupdate-restart"
class="btn btn-warning">
<span class="fa fa-redo" aria-hidden="true"></span>
<?php echo Text::_('COM_JOOMLAUPDATE_ERRORSTATE_BTN_RESTART') ?>
</button>
</div>
<div class="flex-grow-1"></div>
<div>
<a href="<?php echo Route::_('index.php?option=com_joomlaupdate') ?>"
class="btn btn-danger btn-sm ms-3">
<?php echo Text::_('JCANCEL') ?>
</a>
</div>
</div>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_joomlaupdate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ COM_JOOMLAUPDATE_ERRORMODAL_HEAD_FORBIDDEN="Access forbidden"
COM_JOOMLAUPDATE_ERRORMODAL_HEAD_GENERIC="An error occurred"
COM_JOOMLAUPDATE_ERRORMODAL_HEAD_SERVERERROR="Server error"
COM_JOOMLAUPDATE_ERRORMODAL_BTN_HELP="Get help with this error"
COM_JOOMLAUPDATE_ERRORSTATE_BTN_RETRY="Resume Update"
COM_JOOMLAUPDATE_ERRORSTATE_BTN_RESTART="Restart Update"
COM_JOOMLAUPDATE_FAILED_TO_CHECK_UPDATES="Failed to check for updates."
COM_JOOMLAUPDATE_MINIMUM_STABILITY_ALPHA="Alpha"
COM_JOOMLAUPDATE_MINIMUM_STABILITY_BETA="Beta"
Expand Down
72 changes: 45 additions & 27 deletions build/media_source/com_joomlaupdate/js/admin-update-default.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ Joomla.Update = window.Joomla.Update || {
totalsize: 0,
ajax_url: null,
return_url: null,
cached_instance: null,
genericErrorMessage: (message) => {
const headerDiv = document.getElementById('errorDialogLabel');
const messageDiv = document.getElementById('errorDialogMessage');
const progressDiv = document.getElementById('progress-bar');
const titleDiv = document.getElementById('update-title');
const helpDiv = document.getElementById('update-help');

progressDiv.classList.add('bg-danger');
progressDiv.classList.remove('bg-success');
titleDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_UPDATING_FAIL');
helpDiv.classList.remove('d-none');
helpDiv.classList.add('d-grid');
const progressDiv = document.getElementById('joomlaupdate-progress');
const errorDiv = document.getElementById('joomlaupdate-error');

headerDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_HEAD_GENERIC');
messageDiv.innerHTML = message;
Expand All @@ -36,25 +30,16 @@ Joomla.Update = window.Joomla.Update || {
messageDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_BODY_INVALIDLOGIN');
}

const myModal = new bootstrap.Modal(document.getElementById('errorDialog'), {
keyboard: true,
backdrop: true,
});
myModal.show();
progressDiv.classList.add('d-none');
errorDiv.classList.remove('d-none');
},
handleErrorResponse: (xhr) => {
const isForbidden = xhr.status === 403;
const headerDiv = document.getElementById('errorDialogLabel');
const messageDiv = document.getElementById('errorDialogMessage');
const progressDiv = document.getElementById('progress-bar');
const titleDiv = document.getElementById('update-title');
const helpDiv = document.getElementById('update-help');

progressDiv.classList.add('bg-danger');
progressDiv.classList.remove('bg-success');
titleDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_UPDATING_FAIL');
helpDiv.classList.remove('d-none');
helpDiv.classList.add('d-grid');
const progressDiv = document.getElementById('joomlaupdate-progress');
const errorDiv = document.getElementById('joomlaupdate-error');

if (isForbidden) {
headerDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_HEAD_FORBIDDEN');
Expand All @@ -64,17 +49,15 @@ Joomla.Update = window.Joomla.Update || {
messageDiv.innerHTML = Joomla.Text._('COM_JOOMLAUPDATE_ERRORMODAL_BODY_SERVERERROR');
}

const myModal = new bootstrap.Modal(document.getElementById('errorDialog'), {
keyboard: true,
backdrop: true,
});
myModal.show();
progressDiv.classList.add('d-none');
errorDiv.classList.remove('d-none');
},
startExtract: () => {
// Reset variables
Joomla.Update.stat_files = 0;
Joomla.Update.stat_inbytes = 0;
Joomla.Update.stat_outbytes = 0;
Joomla.Update.cached_instance = null;

document.getElementById('extbytesin').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_inbytes);
document.getElementById('extbytesout').innerText = Joomla.Update.formatBytes(Joomla.Update.stat_outbytes);
Expand Down Expand Up @@ -158,6 +141,8 @@ Joomla.Update = window.Joomla.Update || {
}, 50);
},
delayedStepExtract: (instance) => {
Joomla.Update.cached_instance = instance;

const postData = new FormData();
postData.append('task', 'stepExtract');
postData.append('password', Joomla.Update.password);
Expand Down Expand Up @@ -218,8 +203,41 @@ Joomla.Update = window.Joomla.Update || {

return `${parseFloat((bytes / (k ** i)).toFixed(dm))} ${sizes[i]}`;
},
resumeButtonHandler: (e) => {
e.preventDefault();

document.getElementById('joomlaupdate-progress').classList.remove('d-none');
document.getElementById('joomlaupdate-error').classList.add('d-none');

if (Joomla.Update.cached_instance === false) {
Joomla.Update.startExtract();
} else {
Joomla.Update.delayedStepExtract(Joomla.Update.cached_instance);
}
},
restartButtonHandler: (e) => {
e.preventDefault();

document.getElementById('joomlaupdate-progress').classList.remove('d-none');
document.getElementById('joomlaupdate-error').classList.add('d-none');

Joomla.Update.startExtract();
},
};

// Add click handlers for the Resume and Restart Update buttons in the error pane.
const elResume = document.getElementById('joomlaupdate-resume');
const elRestart = document.getElementById('joomlaupdate-restart');

if (elResume) {
elResume.addEventListener('click', Joomla.Update.resumeButtonHandler);
}

if (elRestart) {
elRestart.addEventListener('click', Joomla.Update.restartButtonHandler);
}

// Start the update
const JoomlaUpdateOptions = Joomla.getOptions('joomlaupdate');

if (JoomlaUpdateOptions && Object.keys(JoomlaUpdateOptions).length) {
Expand Down