Bug 26652

Summary: Add a way to mark messages as 'seen' in Koha::Object
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Architecture, internals, and plumbingAssignee: Bugs List <koha-bugs>
Status: In Discussion --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: agustinmoyano, jonathan.druart, joonas.kylmala, julian.maurice, kyle, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26651
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 26555    
Bug Blocks:    

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.