Bug 26470 - itemnumber not available for plugin hook
Summary: itemnumber not available for plugin hook
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low major (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Keywords:
Depends on: 22709 23463
Blocks:
  Show dependency treegraph
 
Reported: 2020-09-15 18:47 UTC by Tomás Cohen Arazi
Modified: 2022-06-06 20:24 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:
20.11.00


Attachments
Bug 26470: Regression tests (2.82 KB, patch)
2020-09-15 19:45 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 26470: Store the item before calling the after action hook (2.61 KB, patch)
2020-09-15 19:45 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 26470: Regression tests (2.87 KB, patch)
2020-09-15 21:40 UTC, David Nind
Details | Diff | Splinter Review
Bug 26470: Store the item before calling the after action hook (2.66 KB, patch)
2020-09-15 21:40 UTC, David Nind
Details | Diff | Splinter Review
Bug 26470: Regression tests (2.93 KB, patch)
2020-09-16 12:24 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 26470: Store the item before calling the after action hook (2.72 KB, patch)
2020-09-16 12:24 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2020-09-15 18:47:34 UTC
The way the hook got placed in Koha::Item->store, it doesn't get the itemnumber populated by the DB.
Comment 1 Tomás Cohen Arazi 2020-09-15 19:45:38 UTC
Created attachment 110119 [details] [review]
Bug 26470: Regression tests

This patch tweaks the test plugin so it composes an exception based on
the fact that the hook was called with the item and item_id parameters
defined.

It then makes the tests expect a specific exception message with
information about this.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t
=> FAIL: Tests fail!
Comment 2 Tomás Cohen Arazi 2020-09-15 19:45:51 UTC
Created attachment 110120 [details] [review]
Bug 26470: Store the item before calling the after action hook

This patch makes Koha::Item->store call $self->SUPER::store before
calling the hook, so things like the itemnumber (AUTO_INCREMENT field)
are available to the plugin hook.

It does so by storing the output on a temporary variable, to keep the
current behaviour of just returning the output from SUPER::store.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t \
           t/db_dependent/Koha/Item.t \
           t/db_dependent/Koha/Items.t
=> FAIL: the hooks tests fail. Item.t hasn't been altered so should pass
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass! Item.t as well! (i.e. no behaviour change)
5. Sign off :-D
Comment 3 David Nind 2020-09-15 21:40:00 UTC
Created attachment 110134 [details] [review]
Bug 26470: Regression tests

This patch tweaks the test plugin so it composes an exception based on
the fact that the hook was called with the item and item_id parameters
defined.

It then makes the tests expect a specific exception message with
information about this.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t
=> FAIL: Tests fail!

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2020-09-15 21:40:03 UTC
Created attachment 110135 [details] [review]
Bug 26470: Store the item before calling the after action hook

This patch makes Koha::Item->store call $self->SUPER::store before
calling the hook, so things like the itemnumber (AUTO_INCREMENT field)
are available to the plugin hook.

It does so by storing the output on a temporary variable, to keep the
current behaviour of just returning the output from SUPER::store.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t \
           t/db_dependent/Koha/Item.t \
           t/db_dependent/Koha/Items.t
=> FAIL: the hooks tests fail. Item.t hasn't been altered so should pass
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass! Item.t as well! (i.e. no behaviour change)
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 Martin Renvoize 2020-09-16 12:24:19 UTC
Created attachment 110185 [details] [review]
Bug 26470: Regression tests

This patch tweaks the test plugin so it composes an exception based on
the fact that the hook was called with the item and item_id parameters
defined.

It then makes the tests expect a specific exception message with
information about this.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t
=> FAIL: Tests fail!

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize 2020-09-16 12:24:25 UTC
Created attachment 110186 [details] [review]
Bug 26470: Store the item before calling the after action hook

This patch makes Koha::Item->store call $self->SUPER::store before
calling the hook, so things like the itemnumber (AUTO_INCREMENT field)
are available to the plugin hook.

It does so by storing the output on a temporary variable, to keep the
current behaviour of just returning the output from SUPER::store.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t \
           t/db_dependent/Koha/Item.t \
           t/db_dependent/Koha/Items.t
=> FAIL: the hooks tests fail. Item.t hasn't been altered so should pass
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass! Item.t as well! (i.e. no behaviour change)
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 7 Martin Renvoize 2020-09-16 12:25:06 UTC
Trivial fix with included regression tests.. works as expected

Passing QA
Comment 8 Jonathan Druart 2020-09-18 09:54:56 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 9 Lucas Gass 2020-10-15 21:48:10 UTC
doesn't apply clean to 20.05.x, no backport