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

[5.1] Add update channel reset to Joomla Update Component #3217

Closed
jgerman-bot opened this issue Jul 8, 2024 · 0 comments · Fixed by #3218
Closed

[5.1] Add update channel reset to Joomla Update Component #3217

jgerman-bot opened this issue Jul 8, 2024 · 0 comments · Fixed by #3218

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#43717 Here are the upstream changes:

Click to expand the diff!
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    = '<a href="https://forum.joomla.org/" target="_blank" rel="noopener noreferrer">https://forum.joomla.org/</a>';
@@ -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>
diff --git a/administrator/language/en-GB/com_joomlaupdate.ini b/administrator/language/en-GB/com_joomlaupdate.ini
index 5902c52891851..66daf5ab8fdb9 100644
--- a/administrator/language/en-GB/com_joomlaupdate.ini
+++ b/administrator/language/en-GB/com_joomlaupdate.ini
@@ -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\""
@@ -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"
diff --git a/libraries/src/Console/UpdateCoreCommand.php b/libraries/src/Console/UpdateCoreCommand.php
index 8a28fe15aab31..bef4f091c4722 100644
--- a/libraries/src/Console/UpdateCoreCommand.php
+++ b/libraries/src/Console/UpdateCoreCommand.php
@@ -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();
tecpromotion added a commit to tecpromotion/joomla that referenced this issue Jul 8, 2024
translation
zero-24 added a commit that referenced this issue Jul 8, 2024
* add two new strings

* fix #3217

translation

* Update administrator/language/de-DE/com_joomlaupdate.ini

Co-authored-by: Tobias Zulauf <zero-24@users.noreply.github.com>

---------

Co-authored-by: Tobias Zulauf <zero-24@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants