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.3] Remove unsed variable messages from enqueue messages #42948

Merged
merged 7 commits into from
Feb 28, 2025

Conversation

chmst
Copy link
Contributor

@chmst chmst commented Mar 4, 2024

Pull Request for Issue # .

Summary of Changes

As title says, there is an unused variable.

Testing Instructions

Test different situations where messages are sent and also enqueued, like here
grafik

All messages must be the same before and after patch

@laoneo
Copy link
Member

laoneo commented Mar 4, 2024

This should be properly tested as the function getMessageQueue initializes $this->messageQueue which is used later down. I don't think so we can remove that line. Perhaps the returned $messages variable should be used instead of $this->messageQueue.

@laoneo laoneo added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Mar 4, 2024
@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

Then we let it as is. Just looks weird in the IDE.

@chmst chmst closed this Mar 4, 2024
@laoneo
Copy link
Member

laoneo commented Mar 4, 2024

What you can remove is $messages = as the $messages variable is not used anywhere.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

shouldn't it be
$this->messageQueue = $this->getMessageQueue()

@joomdonation
Copy link
Contributor

Better remove the line as you did here, and replace next line with

if (!\in_array($message, $this->getMessageQueue())) {
	// Enqueue the message.
	$this->messageQueue[] = $message;
}

$this->getMessageQueue() needs to be called here instead of just $this->messageQueue to avoid the messages queued before redirecting to new page (for example, after saving an article, we will be redirected to articles management page, the messages queued before during save process are still being displayed)

@chmst chmst reopened this Mar 4, 2024
@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

@joomdonation I think with this changes we losing the context,
why it $this->getMessageQueue() and not just $this->messageQueue.

I would suggest to keep that comment and the logic. Kind of:

// For empty queue, if messages exists in the session, enqueue them first.
$this->getMessageQueue();

if (!\in_array($message, $this->messageQueue)) {
   // Enqueue the message.
  $this->messageQueue[] = $message;
}

@joomdonation
Copy link
Contributor

@chmst @Fedik That also works, but it is also a bit confusing when calling method returns data but we do not use that returned data for any thing. Honestly, I don't know what's better, but I would also not complain if your code is used. The most important thing is get rid of unused variable so that the code is not being removed by mistake in the future.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

Agree with @joomdonation
For me the comment itself is confusing and clearer to have only the code.

@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

For me the comment itself is confusing and clearer to have only the code.

The problem, that in future, someone may refactor that code, and just replace
if (!\in_array($message, $this->getMessageQueue())) {
back to
if (!\in_array($message, $this->messageQueue)) {

Because, why not?

But it is important to call $this->getMessageQueue() to load previous messages from session.
The comment is important, even if it confusing.

It can stay as you made, but then please add a comment with explanation.

@chmst
Copy link
Contributor Author

chmst commented Mar 4, 2024

@Fedik what about that comment?

@Fedik
Copy link
Member

Fedik commented Mar 4, 2024

Good enough, thanks 😉

@laoneo laoneo removed the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Mar 4, 2024
@HLeithner
Copy link
Member

I wouldn't do this in 4.4 and move it 5.2 since it doesn't solve a bug.

@brianteeman
Copy link
Contributor

@chmst will you be rebasing this?

@Quy Quy added the Updates Requested Indicates that this pull request needs an update from the author and should not be tested. label Jul 16, 2024
@chmst chmst changed the base branch from 4.4-dev to 5.2-dev July 20, 2024 20:57
@Hackwar Hackwar added PR-5.2-dev and removed Updates Requested Indicates that this pull request needs an update from the author and should not be tested. PR-4.4-dev labels Jul 20, 2024
@Hackwar Hackwar changed the title [4.4] Remove unsed variable messages from enqueue messages [5.2] Remove unsed variable messages from enqueue messages Jul 22, 2024
@Hackwar
Copy link
Member

Hackwar commented Jul 24, 2024

Could those who worked on this PR already test it again? That way it could be merged into 5.2.

@Hackwar
Copy link
Member

Hackwar commented Jul 24, 2024

The PR has been rebased. Could you retest this so that we can merge this into 5.2?

@HLeithner HLeithner changed the base branch from 5.2-dev to 5.3-dev September 2, 2024 08:51
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.3-dev.

@HLeithner HLeithner changed the title [5.2] Remove unsed variable messages from enqueue messages [5.3] Remove unsed variable messages from enqueue messages Sep 2, 2024
@Hackwar Hackwar removed the PR-5.2-dev label Sep 3, 2024
@crimle
Copy link

crimle commented Feb 22, 2025

I have tested this item 🔴 unsuccessfully on 208df7a

Installing the patch resulted in an error that crashed my whole Test website:
Call to undefined method Joomla\CMS\Application\AdministratorApplication::checkUserRequiresReset()


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42948.

@degobbis
Copy link
Contributor

I have tested this item 🔴 unsuccessfully on 208df7a

Can confirm, same error after apply with patchtester.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42948.

@degobbis
Copy link
Contributor

I have tested this item ✅ successfully on 26125e1

Testet again after rebase, now all works as expected.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42948.

@softforge
Copy link
Contributor

I have tested this item ✅ successfully on 26125e1

I used the workflow and set it so that it was not correctly set up, that produced both an error and a saved item message, the test instructions followed adn the results as suggested


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42948.

@alikon
Copy link
Contributor

alikon commented Feb 22, 2025

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/42948.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 22, 2025
@laoneo laoneo enabled auto-merge (squash) February 28, 2025 07:25
@laoneo laoneo added this to the Joomla! 5.3.0 milestone Feb 28, 2025
@laoneo laoneo merged commit 8a17a99 into joomla:5.3-dev Feb 28, 2025
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 28, 2025
@laoneo
Copy link
Member

laoneo commented Feb 28, 2025

Thanks!

@chmst chmst deleted the enqueue-messages-unused-variabe branch February 28, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet