Bug 13053 - Do not use template cache when from commandline
Summary: Do not use template cache when from commandline
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Fridolin Somers
QA Contact: Testopia
URL:
Keywords:
: 10739 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-10-09 14:09 UTC by Fridolin Somers
Modified: 2015-12-03 22:11 UTC (History)
4 users (show)

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


Attachments
Bug 13053 - Do not use template cache when from commandline (2.82 KB, patch)
2014-10-09 14:54 UTC, Fridolin Somers
Details | Diff | Splinter Review
Bug 13053 - Do not use template cache when from commandline (2.88 KB, patch)
2014-10-26 06:15 UTC, Chris Cormack
Details | Diff | Splinter Review
[PASSED QA] Bug 13053 - Do not use template cache when from commandline (3.01 KB, patch)
2014-10-26 09:18 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Fridolin Somers 2014-10-09 14:09:46 UTC
You may define in config a folder (usually /tmp) for TT cache : 
template_cache_dir in etc/koha-conf.xml.

Some perl pages may be launched from commandline, like tools/export.pl.
Also, the script gather_print_notices.pl uses C4::Templates.

The problem is that when script is launched from Apache, the Unix owner of cache files will be www-data. When script is launched from commandline, like in a cronjob, the Unix owner will be different (like a user named "koha"), causing a crash because cache files can only be read by its owner.

I propose not to use the template cache if perl script is called from commandline. This cache is certainly only useful for web access.
Comment 1 Fridolin Somers 2014-10-09 14:54:42 UTC Comment hidden (obsolete)
Comment 2 Chris Cormack 2014-10-14 12:48:40 UTC
I don't have plack set up on the testing environment I have hear, but I can test that when I get back to NZ, but if someone wants to confirm that the ENV variable used by the patch is available in a plack set up too that would be great
Comment 3 Chris Cormack 2014-10-26 06:15:21 UTC Comment hidden (obsolete)
Comment 4 Katrin Fischer 2014-10-26 09:18:06 UTC
Created attachment 32767 [details] [review]
[PASSED QA] Bug 13053 - Do not use template cache when from commandline

You may define in config a folder (usually /tmp) for TT cache :
template_cache_dir in etc/koha-conf.xml.

Some perl pages may be launched from commandline, like tools/export.pl.
Also, the script gather_print_notices.pl uses C4::Templates.

The problem is that when script is launched from Apache, the Unix owner of cache files will be www-data. When script is launched from commandline, like in a cronjob, the Unix owner will be different (like a user named "koha"), causing a crash because cache files can only be read by its owner.

This script disables the template cache if perl script is called from commandline. This cache is certainly only useful for web access.
Using GATEWAY_INTERFACE env var comes from tools/export.pl

Test plan :
- Use a dev install of koha installed in a user home, ie "/home/kohadev"
- Define a folder for template_cache_dir in etc/koha-conf.xml. For example : <template_cache_dir>/tmp</template_cache_dir>
- Check there is no cached templates already in this forder
- Create a file "bib.list" containing a few existing biblionumbers
- As user kohadev, launch : tools/export.pl --record-type=bibs --id_list_file=bib.list
- Look at cache folder
=> Without patch you see cache files owned by user kohadev
=> With patch there are no cache files
- Use the Koha interfaces OPAC and Intranet
=> Without patch you get an error : Template process failed: file error - cache failed to write ...
=> With patch you have no error and cache files are generated with Apache user as owner

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described, good test plan!
Passes tests and QA script.
Comment 5 Tomás Cohen Arazi 2014-11-21 23:57:36 UTC
Patch pushed to master.

Thanks Frido!
Comment 6 Jonathan Druart 2014-12-11 15:35:47 UTC
*** Bug 10739 has been marked as a duplicate of this bug. ***
Comment 7 Fridolin Somers 2015-04-02 08:48:58 UTC
Can this be backported to 3.16.x ?