diff --git a/ctools.install b/ctools.install index 6b63e9b961bd6888a4ee27155665300e8f65dfef..446c1f3cad9a761903d7253afd27cc37b6f5ec3d 100644 --- a/ctools.install +++ b/ctools.install @@ -6,6 +6,37 @@ * Contains install and update functions for ctools. */ +/** + * Use requirements to ensure that the CTools CSS cache directory can be + * created. + */ +function ctools_requirements($phase) { + $requirements = array(); + if ($phase == 'runtime') { + $path = file_create_path('ctools/css'); + if (!file_check_directory($path)) { + $path = file_directory_path() . '/ctools'; + file_check_directory($path, FILE_CREATE_DIRECTORY); + $path .= '/css'; + file_check_directory($path, FILE_CREATE_DIRECTORY); + } + + $requirements['ctools_css_cache'] = array( + 'title' => t('CTools CSS Cache'), + 'severity' => REQUIREMENT_OK, + 'value' => t('Exists'), + ); + + if (!file_check_directory($path)) { + $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory could not be created due to a misconfigured files directory. Please ensure that the files directory is corretly configured and that the webserver has permission to create directories.'); + $requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR; + $requirements['ctools_css_cache']['value'] = t('Unable to create'); + } + } + + return $requirements; +} + /** * Implementation of hook_install() */ diff --git a/includes/css.inc b/includes/css.inc index 313188a12d7377a227b588598268b6158d071df3..c8c19804449ba40045fd81fe41f24fa1ad1bfdb8 100644 --- a/includes/css.inc +++ b/includes/css.inc @@ -147,13 +147,18 @@ function ctools_css_cache($css, $filter = TRUE) { // Create the css/ within the files folder. $path = file_create_path('ctools/css'); - if (!$path) { + if (!file_check_directory($path)) { $path = file_directory_path() . '/ctools'; file_check_directory($path, FILE_CREATE_DIRECTORY); $path .= '/css'; file_check_directory($path, FILE_CREATE_DIRECTORY); } + if (!file_check_directory($path)) { + drupal_set_message(t('Unable to create CTools CSS cache directory. Check the permissions on your files directory.'), 'error'); + return; + } + // @todo Is this slow? Does it matter if it is? $filename = $path . '/' . md5($css) . '.css';