Skip to content

Commit

Permalink
[5.1] Add update channel reset to Joomla Update Component (#43717)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard67 authored Jul 7, 2024
1 parent 0c045c2 commit b6f4dfd
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function display($cachable = false, $urlparams = false)
$state = $model->getState();
$state->set('update_finished_with_error', $this->app->getUserState('com_joomlaupdate.update_finished_with_error'));
$state->set('update_errors', (array) $this->app->getUserState('com_joomlaupdate.update_errors', []));
$state->set('update_channel_reset', $this->app->getUserState('com_joomlaupdate.update_channel_reset'));
$state->set('installer_message', $this->app->getUserState('com_joomlaupdate.installer_message'));
$state->set('log_file', $this->app->get('log_path') . '/joomla_update.php');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public function finalise()
$model->collectError('finaliseUpgrade', $e);
}

// Reset update source from "Joomla Next" to "Default"
$this->app->setUserState('com_joomlaupdate.update_channel_reset', $model->resetUpdateSource());

// Check for update errors
if ($model->getErrors()) {
// The errors already should be logged at this point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2027,4 +2027,73 @@ private function checkManifestXML(string $manifest, $packageName)
throw new \RuntimeException(Text::sprintf('COM_JOOMLAUPDATE_VIEW_UPLOAD_ERROR_DOWNGRADE', $packageName, $versionPackage, $currentVersion), 500);
}
}

/**
* Reset update source from "next" to "default"
*
* @return boolean True if update source is reset, false if reset failed with error,
* null if no reset was necessary.
*
* @since __DEPLOY_VERSION__
*/
public function resetUpdateSource()
{
// Get current update source
$params = ComponentHelper::getParams('com_joomlaupdate');

// Do nothing if not "next"
if ($params->get('updatesource', 'default') !== 'next') {
return null;
}

$params->set('updatesource', 'default');

$params = $params->toString();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = :params')
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_joomlaupdate'))
->bind(':params', $params);

try {
$db->setQuery($query);
$db->execute();
} catch (\Exception $e) {
Log::add(
sprintf(
'An error has occurred while running "resetUpdateSource". Code: %s. Message: %s.',
$e->getCode(),
$e->getMessage()
),
Log::WARNING,
'Update'
);

Log::add(
Text::sprintf(
'COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED',
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'),
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')
),
Log::WARNING,
'Update'
);

return false;
}

Log::add(
Text::sprintf(
'COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_OK',
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'),
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')
),
Log::INFO,
'Update'
);

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

$hadErrors = $this->state->get('update_finished_with_error');
$errors = $this->state->get('update_errors');
$channelReset = $this->state->get('update_channel_reset');
$logFile = $this->state->get('log_file');
$installerMsg = $this->state->get('installer_message');
$forumLink = '<a href="https://forum.joomla.org/" target="_blank" rel="noopener noreferrer">https://forum.joomla.org/</a>';
Expand All @@ -27,6 +28,17 @@
<div class="card">
<h2 class="card-header"><?php echo Text::_('COM_JOOMLAUPDATE_VIEW_COMPLETE_HEADING'); ?></h2>
<div class="card-body">
<?php if ($channelReset) : ?>
<div class="alert alert-success">
<span class="icon-check-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('NOTICE'); ?></span>
<?php echo Text::sprintf('COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_OK', Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'), Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')); ?>
</div>
<?php elseif ($channelReset !== null) : ?>
<div class="alert alert-warning">
<span class="icon-check-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('WARNING'); ?></span>
<?php echo Text::sprintf('COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED', Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'), Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')); ?>
</div>
<?php endif; ?>
<?php if (!$hadErrors) : ?>
<div class="alert alert-success">
<span class="icon-check-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('NOTICE'); ?></span>
Expand Down
4 changes: 3 additions & 1 deletion administrator/language/en-GB/com_joomlaupdate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ COM_JOOMLAUPDATE_SELF_EMPTYSTATE_CONTENT="You must update this component first b
COM_JOOMLAUPDATE_SELF_EMPTYSTATE_TITLE="A new version of the Joomla Update Component is available"
COM_JOOMLAUPDATE_SYSTEM_CHECK="System Check"
COM_JOOMLAUPDATE_TOOLBAR_CHECK="Check for Updates"
COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED="Failed to reset the update channel from \"%1$s\" to \"%2$s\". Please change it in the Joomla Update Component's options so you don't miss future updates."
COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_OK="The update channel has been reset from \"%1$s\" to \"%2$s\"."
COM_JOOMLAUPDATE_UPDATE_CHECK="Update Check"
COM_JOOMLAUPDATE_UPDATE_CONFIRM_BACKUP="I'm aware that a backup before any update is highly recommended."
COM_JOOMLAUPDATE_UPDATE_EMPTYSTATE_TITLE="Update your site to \"Joomla! %s\""
Expand Down Expand Up @@ -169,7 +171,7 @@ COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATE_NOTICE="Before you update Joomla, ensure th
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATEFOUND="A Joomla update was found."
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_CUSTOM="You are on the &quot;%s&quot; update channel. This is not an official Joomla update channel."
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_DEFAULT="You are on the &quot;%s&quot; update channel. Through this channel you'll receive notifications for all updates of the current Joomla release (5.x)"
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_NEXT="You are on the &quot;%s&quot; update channel. Through this channel you'll receive notifications for all updates of the current Joomla release (5.x) and you will also be notified when the future major release (6.x) will be available. Before upgrading to 6.x you'll need to assess its compatibility with your environment."
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_NEXT="You are on the &quot;%s&quot; update channel. Through this channel you will be notified when the future major release (6.x) will be available. Before upgrading to 6.x you'll need to assess its compatibility with your environment. You will not be notified about updates of the current Joomla release (5.x)."
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_TESTING="You are on the &quot;%s&quot; update channel. This channel is designed for testing new releases and fixes in Joomla.<br>It is only intended for JBS (Joomla Bug Squad&trade;) members and others within the Joomla community who are testing. Do not use this setting on a production site."
COM_JOOMLAUPDATE_VIEW_DEFAULT_UPLOAD_INTRO="You can use this feature to update Joomla if your server is behind a firewall or otherwise unable to contact the update servers. First download the Joomla <em><strong>Update Package</strong></em> in ZIP format from <a class='alert-link' href='%s' target='_blank' rel='noopener noreferrer'>the official Joomla download page</a>. Then use the fields below to upload and install it."
COM_JOOMLAUPDATE_VIEW_UPDATE_BYTESEXTRACTED="Bytes extracted"
Expand Down
18 changes: 18 additions & 0 deletions libraries/src/Console/UpdateCoreCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ private function updateJoomlaCore($updatemodel): bool
$result = $updatemodel->finaliseUpgrade();

if ($result) {
$updateSourceChanged = $updatemodel->resetUpdateSource();

if ($updateSourceChanged) {
$message = Text::sprintf(
'COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_OK',
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'),
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')
);
$this->ioStyle->info($message);
} elseif ($updateSourceChanged !== null) {
$message = Text::sprintf(
'COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED',
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'),
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')
);
$this->ioStyle->warning($message);
}

$this->progressBar->clear();
$this->ioStyle->writeln("Cleaning up ...");
$this->progressBar->display();
Expand Down

0 comments on commit b6f4dfd

Please sign in to comment.