Skip to content
Snippets Groups Projects
Commit a5f36bd1 authored by Earl Miles's avatar Earl Miles
Browse files

#447064: Make the CSS cache directory creation more robust, plus add hook_requirements as well.

parent 82ea60ce
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,37 @@ ...@@ -6,6 +6,37 @@
* Contains install and update functions for ctools. * 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() * Implementation of hook_install()
*/ */
......
...@@ -147,13 +147,18 @@ function ctools_css_cache($css, $filter = TRUE) { ...@@ -147,13 +147,18 @@ function ctools_css_cache($css, $filter = TRUE) {
// Create the css/ within the files folder. // Create the css/ within the files folder.
$path = file_create_path('ctools/css'); $path = file_create_path('ctools/css');
if (!$path) { if (!file_check_directory($path)) {
$path = file_directory_path() . '/ctools'; $path = file_directory_path() . '/ctools';
file_check_directory($path, FILE_CREATE_DIRECTORY); file_check_directory($path, FILE_CREATE_DIRECTORY);
$path .= '/css'; $path .= '/css';
file_check_directory($path, FILE_CREATE_DIRECTORY); 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? // @todo Is this slow? Does it matter if it is?
$filename = $path . '/' . md5($css) . '.css'; $filename = $path . '/' . md5($css) . '.css';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment