Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function
Summary: C4::Context->setCommandlineEnvironment() convenience function
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Olli-Antti Kivilahti
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-20 09:25 UTC by Olli-Antti Kivilahti
Modified: 2020-01-11 11:30 UTC (History)
3 users (show)

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


Attachments
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function (1.47 KB, patch)
2016-04-20 09:26 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function (4.37 KB, patch)
2016-04-21 12:37 UTC, Olli-Antti Kivilahti
Details | Diff | Splinter Review
Bug 16306 - (squashable) C4::Context->setCommandlineEnvironment() convenience function (1.14 KB, patch)
2017-07-10 14:01 UTC, Lari Taskula
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Olli-Antti Kivilahti 2016-04-20 09:25:06 UTC
There is no unified way to set the environment for commandline scripts, even if the C4::Context->interface('commandline') explicitly allows setting the cli interface.

Also a default user environment must be set.


This function wraps the complexity of environment setting in the command line.

Usage:

use C4::Context;
BEGIN {
    C4::Context->setCommandlineEnvironment();
}
... #Load other dependencies that might depend on the environment

or just:

...
use C4::Context;
C4::Context->setCommandlineEnvironment();
...
Comment 1 Olli-Antti Kivilahti 2016-04-20 09:26:18 UTC Comment hidden (obsolete)
Comment 2 Olli-Antti Kivilahti 2016-04-21 12:37:14 UTC
Created attachment 50501 [details] [review]
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function

There is no unified way to set the environment for commandline scripts,
even if the C4::Context->interface('commandline') explicitly allows setting
the cli interface.

This function wraps the complexity of environment setting in the command line.

Also a default user environment must be set.
To set the default user environment we need a default user. This patch
also makes sure that a default 'commandlineadmin' always exists in DB.

Usage:

use C4::Context;
BEGIN {
    C4::Context->setCommandlineEnvironment();
}
... #Load other dependencies that might depend on the environment

or just:

...
use C4::Context;
C4::Context->setCommandlineEnvironment();
...
Comment 3 Nicolas Legrand 2016-10-12 12:35:40 UTC
nicolas@plac:~/kohaclone$ git bz apply 16306
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function

50501 - Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function
fatal: sha1 information is lacking or useless (C4/Context.pm).
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function
The copy of the patch that failed is found in:
   /home/nicolas/kohaclone/.git/rebase-apply/patch
When you have resolved this problem run "git bz apply --continue".
If you would prefer to skip this patch, instead run "git bz apply --skip".
To restore the original branch and stop patching run "git bz apply --abort".
Patch left in /tmp/Bug-16306---C4Context-setCommandlineEnvironment-co-6OOIcM.patch
Comment 4 Lari Taskula 2017-07-10 14:01:37 UTC
Created attachment 64965 [details] [review]
Bug 16306 - (squashable) C4::Context->setCommandlineEnvironment() convenience function

Test t/db_dependent/Context_commandline.t fails due to commandlinesuperuser not
being stored in the database.

To test:
1. Make sure commandlinesuperuser does not exist
2. prove t/db_dependent/Context_commandline.t
3. Observe failure
4. Apply patch
5. prove t/db_dependent/Context_commandline.t
6. Success
Comment 5 Mark Tompsett 2017-08-25 03:34:10 UTC
Comment on attachment 50501 [details] [review]
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function

Review of attachment 50501 [details] [review]:
-----------------------------------------------------------------

::: C4/Context.pm
@@ +1309,5 @@
> +	C4::Context::set_userenv($clisu->{borrowernumber},$clisu->{userid},$clisu->{cardnumber},$clisu->{firstname},$clisu->{surname}, $clisu->{branchcode}, '', {}, '', '', '');
> +}
> +
> +sub _enforceCommandlineSuperuserBorrowerExists {
> +	my $commandlineSuperuser = C4::Members::GetMember(userid => 'commandlineadmin');

I believe this GetMember function was removed.