Commit 056619f6 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Removed xmlsitemap_cache_clear() to file_unmanaged_delete_recursive().

parent 4c285eca
...@@ -72,10 +72,14 @@ function xmlsitemap_settings_form() { ...@@ -72,10 +72,14 @@ function xmlsitemap_settings_form() {
'#default_value' => xmlsitemap_var('batch_limit'), '#default_value' => xmlsitemap_var('batch_limit'),
'#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'), '#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'),
); );
$path = variable_get('xmlsitemap_path', 'xmlsitemap');
if (!xmlsitemap_check_directory()) {
form_set_error('xmlsitemap_path', t('The directory %directory does not exist or is not writable.', array('%directory' => file_directory_path() . '/' . $path)));
}
$form['advanced']['xmlsitemap_path'] = array( $form['advanced']['xmlsitemap_path'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Sitemap cache directory'), '#title' => t('Sitemap cache directory'),
'#default_value' => xmlsitemap_var('path'), '#default_value' => $path,
'#size' => 30, '#size' => 30,
'#maxlength' => 255, '#maxlength' => 255,
'#description' => t('Subdirectory in the directory %dir where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.', array('%dir' => file_directory_path() .'/')), '#description' => t('Subdirectory in the directory %dir where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.', array('%dir' => file_directory_path() .'/')),
...@@ -152,14 +156,6 @@ function _xmlsitemap_process_language_checkboxes($element) { ...@@ -152,14 +156,6 @@ function _xmlsitemap_process_language_checkboxes($element) {
* @see xmlsitemap_settings_form() * @see xmlsitemap_settings_form()
*/ */
function xmlsitemap_settings_form_validate($form, &$form_state) { function xmlsitemap_settings_form_validate($form, &$form_state) {
// Check if the xmlsitemap files directory has changed.
$path_new = file_create_path($form_state['values']['xmlsitemap_path']);
$path_old = file_create_path(xmlsitemap_var('path'));
if ($path_new != $path_old && file_check_directory($path_new, FILE_CREATE_DIRECTORY, 'xmlsitemap_path')) {
// If creating the new directory was successful, remove the old directory.
xmlsitemap_clear_cache(TRUE, $path_old);
}
// Check that the chunk size will not create more than 1000 chunks. // Check that the chunk size will not create more than 1000 chunks.
$chunk_size = $form_state['values']['xmlsitemap_chunk_size']; $chunk_size = $form_state['values']['xmlsitemap_chunk_size'];
if ($chunk_size != 'auto' && $chunk_size != 50000 && (xmlsitemap_get_link_count() / $chunk_size) > 1000) { if ($chunk_size != 'auto' && $chunk_size != 50000 && (xmlsitemap_get_link_count() / $chunk_size) > 1000) {
......
...@@ -90,7 +90,9 @@ function _xmlsitemap_regenerate_before() { ...@@ -90,7 +90,9 @@ function _xmlsitemap_regenerate_before() {
_xmlsitemap_get_memory_usage(TRUE); _xmlsitemap_get_memory_usage(TRUE);
// Clear all cached sitemap files. // Clear all cached sitemap files.
xmlsitemap_clear_cache(); $path = file_directory_path() . '/' . variable_get('xmlsitemap_path', 'xmlsitemap');
file_unmanaged_delete_recursive($path);
xmlsitemap_check_directory();
} }
function _xmlsitemap_get_memory_usage($start = FALSE) { function _xmlsitemap_get_memory_usage($start = FALSE) {
......
...@@ -151,7 +151,8 @@ function xmlsitemap_uninstall() { ...@@ -151,7 +151,8 @@ function xmlsitemap_uninstall() {
} }
// Remove files directory. // Remove files directory.
xmlsitemap_clear_cache(TRUE); $path = file_directory_path() . '/' . variable_get('xmlsitemap_path', 'xmlsitemap');
file_unmanaged_delete_recursive($path);
} }
/** /**
......
...@@ -562,25 +562,6 @@ function xmlsitemap_delete_link(array $conditions) { ...@@ -562,25 +562,6 @@ function xmlsitemap_delete_link(array $conditions) {
return db_affected_rows(); return db_affected_rows();
} }
/**
* Delete all cached sitemap XML files.
*
* @param $rmdir
* A boolean that if TRUE the directory will be removed after emptying.
* @param $path
* An optional directory path, defaults to the xmlsiteamp cache directory.
*/
function xmlsitemap_clear_cache($rmdir = FALSE, $path = NULL) {
if (!isset($path)) {
$path = file_create_path(xmlsitemap_var('path'));
}
file_scan_directory($path, '.*', array('.', '..', 'CVS', '.svn'), 'file_delete', TRUE);
if ($rmdir) {
rmdir($path);
}
}
/** /**
* Get the filename of a specific sitemap page chunk. * Get the filename of a specific sitemap page chunk.
* *
...@@ -594,7 +575,7 @@ function xmlsitemap_clear_cache($rmdir = FALSE, $path = NULL) { ...@@ -594,7 +575,7 @@ function xmlsitemap_clear_cache($rmdir = FALSE, $path = NULL) {
* @todo Move to xmlsitemap.inc * @todo Move to xmlsitemap.inc
*/ */
function xmlsitemap_get_chunk_file($chunk = 0, $language, $compressed = FALSE) { function xmlsitemap_get_chunk_file($chunk = 0, $language, $compressed = FALSE) {
return file_create_path(xmlsitemap_var('path')) .'/xmlsitemap-' . $language->language . '-' . $chunk . ($compressed ? '.gz' : '.xml'); return file_directory_path() . '/' . variable_get('xmlsitemap_path', 'xmlsitemap') . '/xmlsitemap-' . $language->language . '-' . $chunk . ($compressed ? '.gz' : '.xml');
} }
/** /**
...@@ -937,6 +918,10 @@ function xmlsitemap_xmlsitemap_link_info() { ...@@ -937,6 +918,10 @@ function xmlsitemap_xmlsitemap_link_info() {
* Check that the sitemap files directory exists and is writable. * Check that the sitemap files directory exists and is writable.
*/ */
function xmlsitemap_check_directory() { function xmlsitemap_check_directory() {
$directory = file_directory_path() . '/' . xmlsitemap_var('path'); $path = file_directory_path() . '/' . variable_get('xmlsitemap_path', 'xmlsitemap');
return file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); $result = file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
if (!$result) {
watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' => $path), WATCHDOG_ERROR);
}
return $result;
} }
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