Bug 26652 - Add a way to mark messages as 'seen' in Koha::Object
Summary: Add a way to mark messages as 'seen' in Koha::Object
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on: 26555
Blocks:
  Show dependency treegraph
 
Reported: 2020-10-09 18:07 UTC by Tomás Cohen Arazi
Modified: 2020-10-09 18:09 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2020-10-09 18:07:35 UTC
Bug 26555 adds a way for Koha::Object-derived classes to carry errors messages between method calls. On bug 26651 there's a proposal for a Koha::Object->reset_messages method that *could* be used to clean that messages list, if required.

Another option could be to have Koha::Object::Message carry some flag (seen?) that tells if the message has already been looked at. So if ->messages is called twice, the second one returns no results as all messages have been marked as seen:

=head3 messages

    $object->methods
           ->that
           ->each
           ->adds
           ->messages;
    @messages = $object->messages; # all accumulated messages
    @messages = $object->messages; # @messages is empty
    $object->boo;
    @messages = $object->messages; # @messages contains messages added by ->boo

The implementation could look like:

=cut

sub messages {
    my ($self) = @_;

    my @messages = map { $_->mark_as_seen } @{ grep { $_->unseen } @{ $self->messages } };
    return \@messages;
}


package Koha::Object::Message;

sub mark_as_seen {
    my ($self) = @_;
    $self->{seen} = 1;
    return $self;
}


A method for retrieving all messages in the object lifetime could be added.

I put this here for discussing it, and just in case someone is looking for something like this and finds this bug, adding their two cents here with their use cases.