[Koha-devel] Plugin hooks on datas and store()

Fridolin SOMERS fridolin.somers at biblibre.com
Fri Mar 12 13:47:23 CET 2021


Mmmm interesting.

Why not send the $self object to plugin
and call SUPER::store() after hook ?

Best regards,


Le 10/03/2021 à 09:22, Jonathan Druart a écrit :
>  From perlobj pod:
> "The |SUPER| pseudo-class is resolved from the package where the call is 
> made. It is /not/ resolved based on the object's class."
> 
> You can still call $item->_result->update.
> 
> I suggest you open a bug report to add a no_trigger flag to 
> Koha::Object->store (like we did in Koha::Objects).
> 
> Also spotted, at the end of store:
>   193     my $result = $self->SUPER::store;
> 
>   202     $self->get_from_storage->_after_item_action_hooks({ action => 
> $action });
>   203
>   204     return $result;
> 
> That's wrong!
> 
> Le mar. 9 mars 2021 à 09:32, Fridolin SOMERS 
> <fridolin.somers at biblibre.com <mailto:fridolin.somers at biblibre.com>> a 
> écrit :
> 
>     Yop
> 
>     I've tried with :
> 
>     sub after_item_action {
>           my ( $self, $params ) = @_;
>           warn "AFTER ITEM ACTION";
> 
>           my $item = $params->{item};
>           $item->itemnotes("Edited at " . localtime);
>     }
> 
>     Calling $item->SUPER::store() generates an error :
> 
>     Plugin error (Example Kitchen-Sink Plugin): Can't locate object method
>     "store" via package "Koha::Plugin::Com::ByWaterSolutions::KitchenSink"
>     at
>     /mnt/git/koha-plugin-kitchen-sink/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm
> 
>     line 580.
> 
>     Surely only Koha::Item can call SUPER.
> 
>     Adding $self->SUPER::store() at the end of Koha::Item->store() does
>     also
>     not work.
> 
>     Is it because of "get_from_storage" ?
> 
>     $self->get_from_storage->_after_item_action_hooks({ action =>
>     $action });
> 
>     The _after_item_action_hooks method is called not on object $self
>     but on
>     a copy ?
> 
>     Best regards,
> 
>     Le 08/03/2021 à 11:49, Jonathan Druart a écrit :
>      > I wouldn't add other hooks, they are "_after_item_action_hooks" for
>      > creation and modification.
>      > "After item creation" should allow you to modify the item, unless we
>      > need a "pre store" hook.
>      > I had a look at the code and I didn't find any problems.
>      > Fridolin, what did you try exactly, can you share the code?
>      >
>      > Le lun. 8 mars 2021 à 11:17, Tomas Cohen Arazi
>     <tomascohen at gmail.com <mailto:tomascohen at gmail.com>
>      > <mailto:tomascohen at gmail.com <mailto:tomascohen at gmail.com>>> a
>     écrit :
>      >
>      >     Maybe you need some other hook. Ones that allows you to make
>     changes
>      >     to the object right before it is stored instead of this one, that
>      >     gets the 'just updated' object.
>      >     When I added 'after' hooks for biblios and items actions, the
>     idea
>      >     was that they should act as triggers for other actions: in my
>     case,
>      >     fill a zebraqueue-ish table my plugin uses.
>      >
>      >     El lun, 8 mar 2021 a las 5:11, Fridolin SOMERS
>      >     (<fridolin.somers at biblibre.com
>     <mailto:fridolin.somers at biblibre.com>
>      >     <mailto:fridolin.somers at biblibre.com
>     <mailto:fridolin.somers at biblibre.com>>>) escribió:
>      >
>      >         Hi,
>      >
>      >         While testing new hook :
>      > https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27066
>     <https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27066>
>      >       
>       <https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27066
>     <https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27066>>
>      >
>      >         I faced a problem :
>      >         How can I modify the current patron object ?
>      >         Since we are in the store() method of that object and
>     inside a
>      >         transation.
>      >         I tried to call $self->SUPER::store(); but does not work.
>      >
>      >         Should we implement this possiblity or document hooks to
>     say it is
>      >         impossible.
>      >
>      >         Thanks a lot for your help :D
>      >
>      >         Best regards,
>      >
>      >         --
>      >         Fridolin SOMERS <fridolin.somers at biblibre.com
>     <mailto:fridolin.somers at biblibre.com>
>      >         <mailto:fridolin.somers at biblibre.com
>     <mailto:fridolin.somers at biblibre.com>>>
>      >         Software and system maintainer 🦄
>      >         BibLibre, France
>      >         _______________________________________________
>      >         Koha-devel mailing list
>      > Koha-devel at lists.koha-community.org
>     <mailto:Koha-devel at lists.koha-community.org>
>      >         <mailto:Koha-devel at lists.koha-community.org
>     <mailto:Koha-devel at lists.koha-community.org>>
>      >
>     https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
>     <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel>
>      >       
>       <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel>>
>      >         website : https://www.koha-community.org/
>     <https://www.koha-community.org/>
>      >         <https://www.koha-community.org/
>     <https://www.koha-community.org/>>
>      >         git : https://git.koha-community.org/
>     <https://git.koha-community.org/>
>      >         <https://git.koha-community.org/
>     <https://git.koha-community.org/>>
>      >         bugs : https://bugs.koha-community.org/
>     <https://bugs.koha-community.org/>
>      >         <https://bugs.koha-community.org/
>     <https://bugs.koha-community.org/>>
>      >
>      >
>      >
>      >     --
>      >     Tomás Cohen Arazi
>      >     Theke Solutions (http://theke.io <http://theke.io>
>     <http://theke.io/ <http://theke.io/>>)
>      >     ✆ +54 9351 3513384
>      >     GPG: B2F3C15F
>      >     _______________________________________________
>      >     Koha-devel mailing list
>      > Koha-devel at lists.koha-community.org
>     <mailto:Koha-devel at lists.koha-community.org>
>      >     <mailto:Koha-devel at lists.koha-community.org
>     <mailto:Koha-devel at lists.koha-community.org>>
>      >
>     https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
>     <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel>
>      >   
>       <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel <https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel>>
>      >     website : https://www.koha-community.org/
>     <https://www.koha-community.org/>
>      >     <https://www.koha-community.org/
>     <https://www.koha-community.org/>>
>      >     git : https://git.koha-community.org/
>     <https://git.koha-community.org/> <https://git.koha-community.org/
>     <https://git.koha-community.org/>>
>      >     bugs : https://bugs.koha-community.org/
>     <https://bugs.koha-community.org/>
>      >     <https://bugs.koha-community.org/
>     <https://bugs.koha-community.org/>>
>      >
> 
>     -- 
>     Fridolin SOMERS <fridolin.somers at biblibre.com
>     <mailto:fridolin.somers at biblibre.com>>
>     Software and system maintainer 🦄
>     BibLibre, France
> 

-- 
Fridolin SOMERS <fridolin.somers at biblibre.com>
Software and system maintainer 🦄
BibLibre, France


More information about the Koha-devel mailing list