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

Feature/com joomlaupdate improvements #37911

Merged
merged 28 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7636321
Joomla Update extension compatibility improvements
nikosdion Jan 1, 2022
0c3872c
Joomla Update extension compatibility improvements
nikosdion Jan 1, 2022
9a67a6e
Joomla Update extension compatibility improvements
nikosdion Jan 1, 2022
609ca01
Joomla Update extension compatibility improvements
nikosdion Jan 1, 2022
7569aac
Update administrator/components/com_joomlaupdate/config.xml
Jan 2, 2022
fb55393
Joomla Update extension compatibility improvements
nikosdion Jan 3, 2022
9de1685
Joomla Update extension compatibility improvements
nikosdion Jan 3, 2022
232a097
Joomla Update extension compatibility improvements
nikosdion Jan 3, 2022
b522560
Joomla Update extension compatibility improvements
nikosdion Jan 3, 2022
f8e368a
Merge branch '4.1-dev' into feature/com_joomlaupdate_improvements
chmst Jan 31, 2022
fbae928
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
nikosdion May 27, 2022
305955a
Update administrator/language/en-GB/com_joomlaupdate.ini
nikosdion May 27, 2022
80cd98f
Update administrator/language/en-GB/com_joomlaupdate.ini
nikosdion May 27, 2022
48f7f57
Address changes in Joomla regarding the confirm checkbox
nikosdion Jun 3, 2022
9aa8b7f
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
nikosdion Jun 3, 2022
913bc67
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
roland-d Jun 4, 2022
2acec13
Pre-update check was not pushing JS library lang strings
nikosdion Jun 5, 2022
ba8da92
Merge remote-tracking branch 'nikosdion/feature/com_joomlaupdate_impr…
nikosdion Jun 5, 2022
e5bffa1
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
nikosdion Jun 5, 2022
3a57364
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
rdeutz Jun 9, 2022
6af571f
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
nikosdion Jun 13, 2022
ca04b38
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
nikosdion Jun 16, 2022
ef214e8
Update administrator/language/en-GB/com_joomlaupdate.ini
nikosdion Jun 16, 2022
ed60bce
Remove line
nikosdion Jun 16, 2022
cbdf825
Revert accidental commit
nikosdion Jun 16, 2022
a3a7c97
Make backupcheck 1 by default
nikosdion Jun 16, 2022
cc2c06b
Make backupcheck 1 by default
nikosdion Jun 16, 2022
c19a3fb
Merge branch '4.2-dev' into feature/com_joomlaupdate_improvements
roland-d Jun 16, 2022
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
24 changes: 24 additions & 0 deletions administrator/components/com_joomlaupdate/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,29 @@
showon="updatesource:custom"
/>

<field
name="versioncheck"
type="radio"
label="COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_LABEL"
description="COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>

<field
name="backupcheck"
type="radio"
label="COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_LABEL"
description="COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>

</fieldset>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Session\Session;
use Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel;

/**
* The Joomla! update controller for the Update view
Expand Down Expand Up @@ -472,7 +473,8 @@ public function finaliseconfirm()
* Prints a JSON string.
* Called from JS.
*
* @since 3.10.0
* @since 3.10.0
* @deprecated 5.0 Use batchextensioncompatibility instead.
*
* @return void
*/
Expand Down Expand Up @@ -580,6 +582,143 @@ public function fetchExtensionCompatibility()
$this->app->close();
}

/**
* Determines the compatibility information for a number of extensions.
*
* Called by the Joomla Update JavaScript (PreUpdateChecker.checkNextChunk).
*
* @return void
* @since __DEPLOY_VERSION__
*
*/
public function batchextensioncompatibility()
{
$joomlaTargetVersion = $this->input->post->get('joomla-target-version', '', 'DEFAULT');
$joomlaCurrentVersion = $this->input->post->get('joomla-current-version', JVERSION);
$extensionInformation = $this->input->post->get('extensions', []);

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

$extensionResults = [];
$leftover = [];
$startTime = microtime(true);

foreach ($extensionInformation as $information)
{
// Only process an extension if we have spent less than 5 seconds already
$currentTime = microtime(true);

if ($currentTime - $startTime > 5.0)
{
$leftover[] = $information;

continue;
}

// Get the extension information and fetch its compatibility information
$extensionID = $information['eid'] ?: '';
$extensionVersion = $information['version'] ?: '';
$upgradeCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaTargetVersion);
$currentCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaCurrentVersion);
$upgradeUpdateVersion = false;
$currentUpdateVersion = false;
$upgradeWarning = 0;

if ($upgradeCompatibilityStatus->state == 1 && !empty($upgradeCompatibilityStatus->compatibleVersions))
{
$upgradeUpdateVersion = end($upgradeCompatibilityStatus->compatibleVersions);
}

if ($currentCompatibilityStatus->state == 1 && !empty($currentCompatibilityStatus->compatibleVersions))
{
$currentUpdateVersion = end($currentCompatibilityStatus->compatibleVersions);
}

if ($upgradeUpdateVersion !== false)
{
$upgradeOldestVersion = $upgradeCompatibilityStatus->compatibleVersions[0];

if ($currentUpdateVersion !== false)
{
// If there are updates compatible with both CMS versions use these
$bothCompatibleVersions = array_values(
array_intersect($upgradeCompatibilityStatus->compatibleVersions, $currentCompatibilityStatus->compatibleVersions)
);

if (!empty($bothCompatibleVersions))
{
$upgradeOldestVersion = $bothCompatibleVersions[0];
$upgradeUpdateVersion = end($bothCompatibleVersions);
}
}

if (version_compare($upgradeOldestVersion, $extensionVersion, '>'))
{
// Installed version is empty or older than the oldest compatible update: Update required
$resultGroup = 2;
}
else
{
// Current version is compatible
$resultGroup = 3;
}

if ($currentUpdateVersion !== false && version_compare($upgradeUpdateVersion, $currentUpdateVersion, '<'))
{
// Special case warning when version compatible with target is lower than current
$upgradeWarning = 2;
}
}
elseif ($currentUpdateVersion !== false)
{
// No compatible version for target version but there is a compatible version for current version
$resultGroup = 1;
}
else
{
// No update server available
$resultGroup = 1;
}

// Do we need to capture
$extensionResults[] = [
'id' => $extensionID,
'upgradeCompatibilityStatus' => (object) [
'state' => $upgradeCompatibilityStatus->state,
'compatibleVersion' => $upgradeUpdateVersion
],
'currentCompatibilityStatus' => (object) [
'state' => $currentCompatibilityStatus->state,
'compatibleVersion' => $currentUpdateVersion
],
'resultGroup' => $resultGroup,
'upgradeWarning' => $upgradeWarning,
];
}

$this->app->mimeType = 'application/json';
$this->app->charSet = 'utf-8';
$this->app->setHeader('Content-Type', $this->app->mimeType . '; charset=' . $this->app->charSet);
$this->app->sendHeaders();

try
{
$return = [
'compatibility' => $extensionResults,
'extensions' => $leftover,
];

echo new JsonResponse($return);
}
catch (\Exception $e)
{
echo $e;
}

$this->app->close();
}

/**
* Fetch and report updates in \JSON format, for AJAX requests
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ class HtmlView extends BaseHtmlView
*/
protected $nonCoreCriticalPlugins = [];

/**
* Should I disable the confirmation checkbox for pre-update extension version checks?
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $noVersionCheck = false;

/**
* Should I disable the confirmation checkbox for taking a backup before updating?
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $noBackupCheck = false;

/**
* Renders the view
*
Expand Down Expand Up @@ -243,6 +259,9 @@ public function display($tpl = null)
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT');
}

$this->noVersionCheck = $params->get('versioncheck', 1) == 0;
$this->noBackupCheck = $params->get('backupcheck', 1) == 0;

// Remove temporary files
$this->getModel()->removePackageFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

\defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
Expand Down Expand Up @@ -50,6 +51,14 @@ class HtmlView extends BaseHtmlView
*/
protected $warnings = [];

/**
* Should I disable the confirmation checkbox for taking a backup before updating?
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $noBackupCheck = false;

/**
* Renders the view.
*
Expand All @@ -74,6 +83,9 @@ public function display($tpl = null)
$this->warnings = $this->get('Items', 'warnings');
}

$params = ComponentHelper::getParams('com_joomlaupdate');
$this->noBackupCheck = $params->get('backupcheck', 1) == 0;

$this->addToolbar();

// Render the view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// Text::script doesn't have a sprintf equivalent so work around this
$this->document->addScriptOptions('nonCoreCriticalPlugins', $this->nonCoreCriticalPlugins);

// Push Joomla! Update client-side error messages
Text::script('COM_JOOMLAUPDATE_VIEW_DEFAULT_POTENTIALLY_DANGEROUS_PLUGIN_CONFIRM_MESSAGE');
Text::script('COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSION_NO_COMPATIBILITY_INFORMATION');
Text::script('COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSION_WARNING_UNKNOWN');
Expand All @@ -41,6 +42,13 @@
Text::script('COM_JOOMLAUPDATE_VIEW_DEFAULT_POTENTIALLY_DANGEROUS_PLUGIN_CONFIRM_MESSAGE');
Text::script('COM_JOOMLAUPDATE_VIEW_DEFAULT_HELP');

// Push Joomla! core Joomla.Request error messages
Text::script('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT');
Text::script('JLIB_JS_AJAX_ERROR_NO_CONTENT');
Text::script('JLIB_JS_AJAX_ERROR_OTHER');
Text::script('JLIB_JS_AJAX_ERROR_PARSE');
Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT');

$compatibilityTypes = array(
'COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_RUNNING_PRE_UPDATE_CHECKS' => array(
'class' => 'info',
Expand Down Expand Up @@ -301,7 +309,7 @@
<?php echo $extension->version; ?>
</td>
<td id="available-version-<?php echo $extension->extension_id; ?>" class="currcomp hidden"></td>
<td
<td id="preUpdateCheck_<?php echo $extension->extension_id; ?>"
class="extension-check upcomp hidden"
data-extension-id="<?php echo $extension->extension_id; ?>"
data-extension-current-version="<?php echo $extension->version; ?>"
Expand Down Expand Up @@ -331,6 +339,7 @@ class="extension-check upcomp hidden"

<form action="<?php echo Route::_('index.php?option=com_joomlaupdate&layout=update'); ?>" method="post" class="d-flex flex-column mb-5">

<?php if (!$this->noVersionCheck): ?>
<div id="preupdatecheckbox">
<div class="form-check d-flex justify-content-center mb-3">
<input type="checkbox" class="me-3" id="noncoreplugins" name="noncoreplugins" value="1" required />
Expand All @@ -339,8 +348,10 @@ class="extension-check upcomp hidden"
</label>
</div>
</div>
<?php endif; ?>

<button class="btn btn-lg btn-warning disabled submitupdate mx-auto" type="submit" disabled>
<button class="btn btn-lg btn-warning <?php echo $this->noVersionCheck ? '' : 'disabled' ?> submitupdate mx-auto"
type="submit" <?php echo $this->noVersionCheck ? '' : 'disabled' ?>>
<?php echo Text::_('COM_JOOMLAUPDATE_VIEW_DEFAULT_INSTALLUPDATE'); ?>
</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
endif;

// Confirm backup and check
$displayData['content'] .= '<div class="form-check d-flex justify-content-center">
<input class="form-check-input me-2" type="checkbox" value="" id="joomlaupdate-confirm-backup">
$classVisibility = $this->noBackupCheck ? 'd-none' : '';
$checked = $this->noBackupCheck ? 'checked' : '';
$displayData['content'] .= '<div class="form-check d-flex justify-content-center ' . $classVisibility . '">
<input class="form-check-input me-2" type="checkbox" value="" id="joomlaupdate-confirm-backup" ' . $checked . '>
<label class="form-check-label" for="joomlaupdate-confirm-backup">
' . Text::_('COM_JOOMLAUPDATE_UPDATE_CONFIRM_BACKUP') . '
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
</div>
</div>

<div class="form-check mb-3">
<input class="form-check-input me-2" type="checkbox" disabled value="" id="joomlaupdate-confirm-backup">
<div class="form-check mb-3 <?php echo $this->noBackupCheck ? 'd-none' : '' ?>">
<input class="form-check-input me-2 <?php echo $this->noBackupCheck ? 'd-none' : '' ?>"
type="checkbox" disabled value="" id="joomlaupdate-confirm-backup"
<?php echo $this->noBackupCheck ? 'checked' : '' ?>>
<label class="form-check-label" for="joomlaupdate-confirm-backup">
<?php echo Text::_('COM_JOOMLAUPDATE_UPDATE_CONFIRM_BACKUP'); ?>
</label>
Expand Down
6 changes: 5 additions & 1 deletion administrator/language/en-GB/com_joomlaupdate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

COM_JOOMLAUPDATE_CAPTIVE_HEADLINE="Confirm your credentials"
COM_JOOMLAUPDATE_CHECKED_UPDATES="Checked for updates."
COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_DESC="Shows the checkbox to confirm you have taken a backup and you're ready to update in the final step before the update is actually applied."
COM_JOOMLAUPDATE_CONFIG_BACKUPCHECK_LABEL="Confirm Backup Checkbox"
COM_JOOMLAUPDATE_CONFIG_CUSTOMURL_LABEL="Custom URL"
COM_JOOMLAUPDATE_CONFIG_SOURCES_DESC="Configure where Joomla gets its update information from."
COM_JOOMLAUPDATE_CONFIG_SOURCES_LABEL="Update Source"
Expand All @@ -14,6 +16,8 @@ COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT="Default"
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_LABEL="Update Channel"
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT="Joomla Next"
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING="Testing"
COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_DESC="Shows the checkbox in the pre–update check if any of the extensions installed on your site is potentially incompatible with the version of Joomla you are upgrading to. Note: the checkbox is displayed when upgrading to a new Joomla version family (minor or major version)."
COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_LABEL="Potentially incompatible extensions checkbox"
COM_JOOMLAUPDATE_CONFIGURATION="Joomla Update: Options"
COM_JOOMLAUPDATE_CONFIRM="Confirm"
COM_JOOMLAUPDATE_EMPTYSTATE_APPEND="Upload and Update"
Expand Down Expand Up @@ -114,7 +118,7 @@ COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_RUNNING_PRE_UPDATE_CHECKS_NOTES="<p>Ple
COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_SHOW_LESS_COMPATIBILITY_INFORMATION="Less Details"
COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_SHOW_MORE_COMPATIBILITY_INFORMATION="More Details"
COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_UPDATE_SERVER_OFFERS_NO_COMPATIBLE_VERSION="Update Information Unavailable"
COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_UPDATE_SERVER_OFFERS_NO_COMPATIBLE_VERSION_NOTES="Extension does not offer a compatible version for the selected target version of Joomla. This could mean the extension does not use the Joomla update system or the developer has not provided compatibility information for this Joomla version yet."
COM_JOOMLAUPDATE_VIEW_DEFAULT_EXTENSIONS_UPDATE_SERVER_OFFERS_NO_COMPATIBLE_VERSION_NOTES="Joomla cannot detect the extension's compatibility with the target version of Joomla."
COM_JOOMLAUPDATE_VIEW_DEFAULT_NON_CORE_BACKEND_TEMPLATE_USED_NOTICE="We detected that you are not using a core admin template. You might find the upgrade process smoother if you <a href='index.php?option=com_templates&view=styles&client_id=1'>switch</a> to use the %s template."
COM_JOOMLAUPDATE_VIEW_DEFAULT_HELP="More Information"
COM_JOOMLAUPDATE_VIEW_DEFAULT_INFOURL="Additional Information"
Expand Down
Loading