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

New breaking error since 1.5.0 - MessageMovedEvent not enough parameters #322

Closed
devsi opened this issue Aug 24, 2020 · 4 comments
Closed

Comments

@devsi
Copy link

devsi commented Aug 24, 2020

Describe the bug
On this line since 1.5.0 you added Event:

MessageMovedEvent::dispatch($this, $message);

But the MessageMovedEvent has this signature

public function __construct($old_message, $new_message) {
:

You are missing the second parameter for the event. The result is that message->moveToFolder does not work and throws an error:

Too few arguments to function Webklex\IMAP\Events\MessageMovedEvent::__construct(), 1 passed in /var/www/vendor/webklex/laravel-imap/src/IMAP/Events/Event.php on line 15 and exactly 2 expected

@Webklex
Copy link
Owner

Webklex commented Aug 24, 2020

Hi @devsi ,
thanks for your report. I just tested and released a patch :)

Best regards,

@Webklex Webklex closed this as completed Aug 24, 2020
@devsi
Copy link
Author

devsi commented Aug 24, 2020

@Webklex Thanks for the quick response. Can I confirm the following (due to confusing name of function)

moveTofolder() fetches the message as here:

$message = $target_folder->getMessage($target_status->uidnext, null, $this->fetch_options, $this->fetch_body, $this->fetch_attachment, $this->fetch_flags);
MessageMovedEvent::dispatch($this, $message);

Does this not get a singleMessage object, rather than an array? and if so, does referencing the message as $messages[0] remain broken? I haven't tested this, I just ask in theory.

public function __construct($messages) {
$this->old_message = $messages[0];
$this->new_message = $messages[1];

@Webklex
Copy link
Owner

Webklex commented Aug 24, 2020

MessageMovedEvent::dispatch resolves to:

public static function dispatch() {
    return event(new static(func_get_args()));
}

..the two given variables get "cought" by func_get_args() which returns an array of the two given variables which then get used to initialize the original event class. In this case an array containing the old and new message :)

If you have php 7.x running you could also do the following and use the variables directly:

public static function dispatch() {
    return event(new static(...func_get_args()));
}

..however that's in this case not an option, since laravel 5.0 doesn't require php 7.x.

@devsi
Copy link
Author

devsi commented Aug 24, 2020

I understand. I didn't see the dispatch() function in the parent class. That makes much more sense.

Thanks for explaining!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants