From a443e6e95b74d7e47ea9779c4c4f97b6b34baeda Mon Sep 17 00:00:00 2001 From: Kevin Archer Date: Tue, 23 Oct 2012 21:47:38 -0400 Subject: [PATCH] Add config parameter for cache dir permissions --- .../Compiler/CreateCacheDirectoriesCompilerPass.php | 3 ++- DependencyInjection/Configuration.php | 1 + README.md | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Compiler/CreateCacheDirectoriesCompilerPass.php b/DependencyInjection/Compiler/CreateCacheDirectoriesCompilerPass.php index f31770aa0..fd84c9b9e 100644 --- a/DependencyInjection/Compiler/CreateCacheDirectoriesCompilerPass.php +++ b/DependencyInjection/Compiler/CreateCacheDirectoriesCompilerPass.php @@ -16,13 +16,14 @@ public function process(ContainerBuilder $container) $webRoot = $container->getParameter('liip_imagine.web_root'); $cachePrefix = $container->getParameter('liip_imagine.cache_prefix'); $filters = $container->getParameter('liip_imagine.filters'); + $mode = $container->getParameter('liip_imagine.cache_mkdir_mode'); foreach ($filters as $filter => $options) { $dir = isset($options['path']) ? $webRoot.$options['path'] : $webRoot.$cachePrefix.'/'.$filter; - if (!is_dir($dir) && !mkdir($dir, 0777, true)) { + if (!is_dir($dir) && !mkdir($dir, $mode, true)) { throw new \RuntimeException(sprintf( 'Could not create directory for caching processed '. 'images in "%s"', $dir diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 358298404..2859d7d58 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -29,6 +29,7 @@ public function getConfigTreeBuilder() ->end() ->scalarNode('web_root')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('data_root')->defaultValue('%liip_imagine.web_root%')->end() + ->scalarNode('cache_mkdir_mode')->defaultValue(0777)->end() ->scalarNode('cache_prefix')->defaultValue('/media/cache')->end() ->scalarNode('cache')->defaultValue('web_path')->end() ->scalarNode('cache_base_path')->defaultValue('')->end() diff --git a/README.md b/README.md index 2985c35bf..9c1b7856d 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ liip_imagine: driver: gd web_root: %kernel.root_dir%/../web data_root: %liip_imagine.web_root% + cache_mkdir_mode: 0777 cache_prefix: /media/cache cache: web_path cache_clearer: true @@ -203,6 +204,12 @@ There are several configuration options available: default: `%kernel.root_dir%/../web` + - `cache_mkdir_mode` - permissions to set on generated cache directories. + Must be specified as an octal number, which means it should begin with a + leading zero. mode is ignored on Windows. + + default: `0777` + - `cache_prefix` - this is also used in the path for image generation, so as to not clutter your web root with cached images. For example by default, the images would be written to the `web/media/cache/` directory.