Bug 18709

Summary: koha-foreach should use koha-shell, internally
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Command-line UtilitiesAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: fridolin.somers, martin.renvoize, mirko, robin
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17717
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 18709: Make koha-foreach use koha-shell internally
Bug 18709: Make koha-foreach use koha-shell internally
Bug 18709: Make koha-foreach use koha-shell internally

Description Tomás Cohen Arazi 2017-05-31 14:36:47 UTC
Highlighted by bug 17717, koha-foreach is currently taking care of crafting all env variables and call sudo to run the required tasks.

We should definitely call koha-shell in there, and have a single place in which to take care of this logic.
Comment 1 Tomás Cohen Arazi 2017-06-27 15:02:47 UTC
Created attachment 64680 [details] [review]
Bug 18709: Make koha-foreach use koha-shell internally

This patch simplifies the koha-foreach script, making it use koha-shell
to gain instance privileges and have all environment variables set.

To test:
- Apply the patch
- Have one or more instances created (kohadev already exists in kohadevbox, add
  another onewith $ sudo koha-create --create-db test)
- Run:
  $ sudo kohaclone/debian/scripts/koha-foreach echo "This is instance __instancename__"
=> SUCCESS: The script runs gracefuly, and outputs something like:
This is instance kohadev
This is instance test
  Note: this means the command was executed for each instance and the current behaviour
        of replacing the placeholder __instancename__ for the actual instance name still
        works as expected.
- You can try the different filter switches, but the logic has not been touched. only the
  command call.
- Sign off :-D
Comment 2 Jonathan Druart 2017-09-26 17:46:33 UTC
Created attachment 67372 [details] [review]
Bug 18709: Make koha-foreach use koha-shell internally

This patch simplifies the koha-foreach script, making it use koha-shell
to gain instance privileges and have all environment variables set.

To test:
- Apply the patch
- Have one or more instances created (kohadev already exists in kohadevbox, add
  another onewith $ sudo koha-create --create-db test)
- Run:
  $ sudo kohaclone/debian/scripts/koha-foreach echo "This is instance __instancename__"
=> SUCCESS: The script runs gracefuly, and outputs something like:
This is instance kohadev
This is instance test
  Note: this means the command was executed for each instance and the current behaviour
        of replacing the placeholder __instancename__ for the actual instance name still
        works as expected.
- You can try the different filter switches, but the logic has not been touched. only the
  command call.
- Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 3 Nick Clemens 2017-10-11 00:16:46 UTC
Created attachment 67920 [details] [review]
Bug 18709: Make koha-foreach use koha-shell internally

This patch simplifies the koha-foreach script, making it use koha-shell
to gain instance privileges and have all environment variables set.

To test:
- Apply the patch
- Have one or more instances created (kohadev already exists in kohadevbox, add
  another onewith $ sudo koha-create --create-db test)
- Run:
  $ sudo kohaclone/debian/scripts/koha-foreach echo "This is instance __instancename__"
=> SUCCESS: The script runs gracefuly, and outputs something like:
This is instance kohadev
This is instance test
  Note: this means the command was executed for each instance and the current behaviour
        of replacing the placeholder __instancename__ for the actual instance name still
        works as expected.
- You can try the different filter switches, but the logic has not been touched. only the
  command call.
- Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 4 Jonathan Druart 2017-10-11 16:53:51 UTC
Pushed to master for 17.11, thanks to everybody involved!
Comment 5 Fridolin Somers 2018-04-10 07:17:39 UTC
Pushed to 17.05.x for v17.05.11