Commit 4c285eca authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Added xmlsitemap_check_directory() to re-use cache directory checking code.

parent 78db5072
......@@ -27,8 +27,7 @@ function xmlsitemap_drush_command() {
* Check that the sitemap files directory exists and is writable.
*/
function drush_xmlsitemap_check_directory() {
$dir = file_create_path(xmlsitemap_var('path'));
if (!file_check_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
if (!xmlsitemap_check_directory()) {
drush_die(dt('The XML sitemap cache directory @directory was not found was not writable.', array('@directory' => $dir)));
}
}
......
......@@ -33,8 +33,7 @@ function xmlsitemap_requirements($phase) {
}
if ($phase == 'runtime') {
$directory = file_directory_path() . '/' . xmlsitemap_var('path');
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
if (!xmlsitemap_check_directory()) {
$requirements['xmlsitemap_directory'] = array(
'title' => $t('XML sitemap cache directory'),
'value' => $t('Not found or not writable'),
......@@ -124,8 +123,7 @@ function xmlsitemap_install() {
drupal_load('module', 'xmlsitemap');
// Add files directory.
$path = file_directory_path() . '/' . xmlsitemap_var('path');
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
xmlsitemap_check_directory();
// Insert the homepage link into the {xmlsitemap} table so we do not show an
// empty sitemap after install.
......
......@@ -932,3 +932,11 @@ function xmlsitemap_xmlsitemap_link_info() {
'frontpage' => array(),
);
}
/**
* Check that the sitemap files directory exists and is writable.
*/
function xmlsitemap_check_directory() {
$directory = file_directory_path() . '/' . xmlsitemap_var('path');
return file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
......@@ -80,8 +80,6 @@ function xmlsitemap_file_transfer($source, $headers) {
drupal_set_header($header);
}
//$source = file_create_path($source);
// Transfer file in 1024 byte chunks to save memory usage.
if ($handle = fopen($source, 'rb')) {
while (!feof($handle)) {
......
......@@ -38,9 +38,8 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
* Check the files directory is created (massive fails if not done).
*/
protected function checkFilesDirectory() {
$path = file_create_path(variable_get('xmlsitemap_path', 'xmlsitemap'));
if (!file_check_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
$this->fail(t('Directory %dir was found and writable for testing.', array('%dir' => $path)));
if (!xmlsitemap_check_directory()) {
$this->fail(t('Sitemap directory was found and writable for testing.'));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment