If you have say /sites/sitename.com/themes/default and /themes/default , sometimes ive noticed smarty's compiled templates getting "mashed" across both sites, which is a real pain in multi-homed commercial environments.

Attached is a patch that suffix's the MD5 sum of the current sites config_path to the templates_c/ subdirectory, which ensures smarty cache paths dont get mashed across theme names/site installations

I think the ultimate way would be to move the templates_c to under the /sites/sitename.com/templates_c directory so each site carries its own compiled smarty cache

Attached patch is for smartytemplate.php from CVS @ 1.6 2005/12/31 09:24:02 diffed against my patches to smartytemplate.php @ ,v 1.1.1.1 2006-05-04 01:36:11

Comments

tclineks’s picture

Version: master » 4.7.x-1.x-dev
Assigned: Unassigned » tclineks

Thanks dgtlmoon, that was an oversight on my part, I'll get it committed.

dgtlmoon’s picture

Just a thought - this could also be a security issue

sun’s picture

-1 for /sites/<sitename>/themes/templates_c
(each templates_c directory must have proper permissions - this wouldn't really be maintainable)

+1 for using .../templates_c/<themename>_<MD5>
(although a bit long)

+2 for using .../templates_c/sites/default/<themename> and .../templates_c/themes/<themename>
(/themes/smarty/templates_c/ and anything below is writable anyway)

tclineks’s picture

I should have looked a bit closer at the original solution.

+2 for using .../templates_c/sites/default/<themename> and .../templates_c/themes/<themename>
(/themes/smarty/templates_c/ and anything below is writable anyway)

I don't understand your second suggestion there.

I'm inclined to do smarty/templates_c/site_name/theme_name

I dont think there are very serious security considerations so I'll wait for feedback on this before committing (and repackaging).

dgtlmoon’s picture

my two cents: compiled templates _shouldnt_ be important to the sysop or the browser, so long as they dont overlap and are tucked away somewhere, its one of those things where if its working you really dont have much reason to be looking at it

+1 for leaving it in themes/engines/smarty/templates_c/[someUUID]/

sun’s picture

Status: Active » Needs work

I'm inclined to do smarty/templates_c/site_name/theme_name

seems to solve this issue, too. My proposal was to add the full path to the theme after /themes/engines/smarty/templates_c, but I think the proposal of site_name/theme_name is enough to prevent garbled output. We should go for that.

dgtlmoon’s picture

Sitename?


  • Do you mean domain name? What if it the site runs on a subdirectory?

  • Any other wierd char's that might not like to be a path

sun’s picture

Yes, the name of each site is unique and based on the folder name located in /sites. With that prefix each templates_c directory will also be unique.
F.e.

  • /sites/exampledomain.com with a theme in /themes/example will be compiled in /themes/engines/smarty/templates_c/exampledomain.com/example, whereas
  • /sites/exampledomain.org with a theme in /sites/exampledomain.org/themes/example will be compiled in /themes/engines/smarty/templates_c/exampledomain.org/example and even
  • /sites/exampledomain.com with a theme in /sites/exampledomain.com/themes/other will be compiled in /themes/engines/smarty/templates_c/exampledomain.com/other.

The only thing which would not be supported is

  • /sites/exampledomain.com with a theme in /themes/example while having also
  • /sites/exampledomain.com with a theme in /sites/exampledomain.com/themes/example
  • which both would be compiled in /themes/engines/smarty/templates_c/exampledomain.com/example

I don't know if we should care about the latter case, too. IMHO, a notice in README.TXT or INSTALL.TXT should be enough.

tclineks’s picture

Thanks for the input sun

As for the latter situtation, I considered this. It's not a problem since a single site can only be using one of the locations at a time.

sun’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new590 bytes

Attached patch creates a Smarty compile dir in /themes/engines/smarty/templates_c/$confdir_$themedir for each site running on one Drupal installation.

I've decided to not use subdirectories because mkdir() does not support creation of subdirectories in PHP < 5 - and IMHO there shouldn't be much more needless subdirectories at this point.

sun’s picture

Patch stills works like a breeze.

sun’s picture

Travis, is it possible to commit this one-liner?

recidive’s picture

+1. I've tested this patch and it worked well in a multisite environment.

sun’s picture

Assigned: tclineks » sun
Status: Reviewed & tested by the community » Fixed

Committed to HEAD and DRUPAL-4-7.

Anonymous’s picture

Status: Fixed » Closed (fixed)