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(); ...
Created attachment 50454 [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. 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(); ...
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(); ...
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
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 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.