diff --git a/administrator/components/com_joomlaupdate/src/Controller/DisplayController.php b/administrator/components/com_joomlaupdate/src/Controller/DisplayController.php index b03b7d6dc31eb..dba5f257ae347 100644 --- a/administrator/components/com_joomlaupdate/src/Controller/DisplayController.php +++ b/administrator/components/com_joomlaupdate/src/Controller/DisplayController.php @@ -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'); } diff --git a/administrator/components/com_joomlaupdate/src/Controller/UpdateController.php b/administrator/components/com_joomlaupdate/src/Controller/UpdateController.php index 727f4edd9e9c3..f63a4dd7de605 100644 --- a/administrator/components/com_joomlaupdate/src/Controller/UpdateController.php +++ b/administrator/components/com_joomlaupdate/src/Controller/UpdateController.php @@ -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 diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index b28ed81f2c716..802c6effdcafe 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -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; + } } diff --git a/administrator/components/com_joomlaupdate/tmpl/joomlaupdate/complete.php b/administrator/components/com_joomlaupdate/tmpl/joomlaupdate/complete.php index 53b17ccf0fc6c..2920c2a26b060 100644 --- a/administrator/components/com_joomlaupdate/tmpl/joomlaupdate/complete.php +++ b/administrator/components/com_joomlaupdate/tmpl/joomlaupdate/complete.php @@ -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 = 'https://forum.joomla.org/'; @@ -27,6 +28,17 @@