Bug 16306

Summary: C4::Context->setCommandlineEnvironment() convenience function
Product: Koha Reporter: Olli-Antti Kivilahti <olli-antti.kivilahti>
Component: Architecture, internals, and plumbingAssignee: Olli-Antti Kivilahti <olli-antti.kivilahti>
Status: Failed QA --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: nicolas.legrand, veron
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14167
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function
Bug 16306 - C4::Context->setCommandlineEnvironment() convenience function
Bug 16306 - (squashable) C4::Context->setCommandlineEnvironment() convenience function

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.