Commit f71a634a authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Replace all variable_get(), variable_set() and...

Issue #2249723 by andrei.dincu: Replace all variable_get(), variable_set() and variable_del() from .install and .module file with \Drupal::config() methods
parent c1e4608b
......@@ -12,4 +12,13 @@ xmlsitemap_developer_mode: 0
xmlsitemap_frontpage_priority: 1.0
xmlsitemap_frontpage_changefreq: 86400
xmlsitemap_lastmod_format: 'Y-m-d\TH:i\Z'
xmlsitemap_gz: false
\ No newline at end of file
xmlsitemap_gz: false
clean_url: 0
cron_threshold_error: 1209600
cron_threshold_warning: 172800
xmlsitemap_regenerate_last: {}
xmlsitemap_custom_links: {}
xmlsitemap_priority_default: {}
xmlsitemap_languages: {}
xmlsitemap_max_chunks: {}
xmlsitemap_max_filesize: {}
\ No newline at end of file
......@@ -49,4 +49,31 @@ xmlsitemap.settings:
xmlsitemap_gz:
type: boolean
label: 'Gz'
clean_url:
type: integer
label: 'Insert clean urls into sitemap'
cron_threshold_error:
type: integer
label: 'Threshold error for cron job'
cron_threshold_warning:
type: integer
label: 'Threshold warning for cron job'
xmlsitemap_regenerate_last:
type: undefined
label: 'Last regenerate xmlsitemap'
xmlsitemap_custom_links:
type: undefined
label: 'Custom links'
xmlsitemap_priority_default:
type: undefined
label: 'Default priority for a link'
xmlsitemap_languages:
type: mapping
label: 'Languages for xmlsitemap'
xmlsitemap_max_chunks:
type: undefined
label: 'Max chunks'
xmlsitemap_max_filesize:
type: undefined
label: 'Maximul size of xml file'
......@@ -6,6 +6,7 @@
*
* @ingroup xmlsitemap
*/
use Drupal\Core\Language\LanguageInterface;
/**
* Implements hook_requirements().
......@@ -33,7 +34,7 @@ function xmlsitemap_requirements($phase) {
if ($phase == 'runtime') {
// If clean URLs are disabled there must not be an actual sitemap.xml in
// the root directory.
if (variable_get('clean_url', 0) && file_exists(DRUPAL_ROOT . '/sitemap.xml')) {
if (\Drupal::config('xmlsitemap.settings')->get('clean_url') && file_exists(DRUPAL_ROOT . '/sitemap.xml')) {
$requirements['xmlsitemap_file'] = array(
'title' => $t('XML sitemap'),
'value' => $t('Existing sitemap.xml file found.'),
......@@ -102,31 +103,31 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_file_size']['description'] = $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE)));
$requirements['xmlsitemap_file_size']['severity'] = REQUIREMENT_ERROR;
}
elseif (!variable_get('xmlsitemap_developer_mode', 0)) {
elseif (!\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_developer_mode')) {
unset($requirements['xmlsitemap_file_size']);
}
// Check when the cached files were last generated.
$generated_last = variable_get('xmlsitemap_generated_last', 0);
$generated_last = \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_generated_last');
$generated_ago = REQUEST_TIME - $generated_last;
$requirements['xmlsitemap_generated'] = array(
'title' => $t('XML sitemap'),
'value' => $generated_last ? $t('Last attempted generation on !date (!interval ago).', array('!date' => format_date($generated_last, 'small'), '!interval' => format_interval($generated_ago))) : $t('Cached files have not been generated yet.'),
'severity' => REQUIREMENT_OK,
);
if (variable_get('xmlsitemap_rebuild_needed', FALSE) && _xmlsitemap_rebuild_form_access()) {
if (\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_rebuild_needed') && _xmlsitemap_rebuild_form_access()) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
$requirements['xmlsitemap_generated']['description'] = $t('The XML sitemap data is out of sync and needs to be <a href="@link-rebuild">completely rebuilt<a>.', array('@link-rebuild' => url('admin/config/search/xmlsitemap/rebuild')));
}
elseif (variable_get('xmlsitemap_regenerate_needed', FALSE)) {
elseif (\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_regenerate_needed')) {
if ($max_filesize == 0) {
// A maximum sitemap file size of 0 indicates an error in generation.
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
}
elseif ($generated_ago >= variable_get('cron_threshold_error', 1209600)) {
elseif ($generated_ago >= \Drupal::config('xmlsitemap.settings')->get('cron_threshold_error')) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_ERROR;
}
elseif ($generated_ago >= variable_get('cron_threshold_warning', 172800)) {
elseif ($generated_ago >= \Drupal::config('xmlsitemap.settings')->get('cron_threshold_warning')) {
$requirements['xmlsitemap_generated']['severity'] = REQUIREMENT_WARNING;
}
if ($requirements['xmlsitemap_generated']['severity']) {
......@@ -315,9 +316,9 @@ function xmlsitemap_install() {
'type' => 'frontpage',
'id' => 0,
'loc' => '',
'priority' => variable_get('xmlsitemap_frontpage_priority', 1.0),
'changefreq' => variable_get('xmlsitemap_frontpage_changefreq', XMLSITEMAP_FREQUENCY_DAILY),
'language' => LANGUAGE_NONE,
'priority' => \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_frontpage_priority'),
'changefreq' => \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_frontpage_changefreq'),
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
))
->execute();
......@@ -340,7 +341,7 @@ function xmlsitemap_enable() {
// Ensure the file cache directory is available and ready.
xmlsitemap_check_directory();
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
}
/**
......@@ -421,7 +422,7 @@ function xmlsitemap_update_6202() {
// Refresh the schema and load the module if it's disabled.
drupal_get_schema(NULL, TRUE);
if (module_exists('xmlsitemap_i18n') && $languages = variable_get('xmlsitemap_languages', array())) {
if (module_exists('xmlsitemap_i18n') && $languages = \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_languages')) {
foreach ($languages as $language) {
$sitemap = new stdClass();
$sitemap->context = array('language' => $language);
......@@ -436,11 +437,11 @@ function xmlsitemap_update_6202() {
}
// Language variable is no longer needed, so go ahead and delete it.
variable_del('xmlsitemap_languages');
\Drupal::config()->clear('xmlsitemap_languages');
// Ensure that the sitemaps will be refreshed on next cron.
variable_set('xmlsitemap_generated_last', 0);
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_generated_last', 0);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
}
/**
......@@ -471,8 +472,8 @@ function xmlsitemap_update_6203() {
->execute();
}
variable_del('xmlsitemap_max_filesize');
variable_del('xmlsitemap_max_chunks');
\Drupal::config('xmlsitemap.settings')->clear('xmlsitemap_max_filesize');
\Drupal::config('xmlsitemap.settings')->clear('xmlsitemap_max_chunks');
}
/**
......
......@@ -231,13 +231,13 @@ function _xmlsitemap_rebuild_form_access() {
*/
function xmlsitemap_cron() {
// If there were no new or changed links, skip.
if (!variable_get('xmlsitemap_regenerate_needed', FALSE)) {
if (!\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_regenerate_needed')) {
return;
}
// If the minimum sitemap lifetime hasn't been passed, skip.
$lifetime = REQUEST_TIME - variable_get('xmlsitemap_generated_last', 0);
if ($lifetime < variable_get('xmlsitemap_minimum_lifetime', 0)) {
$lifetime = REQUEST_TIME - \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_generated_last');
if ($lifetime < \Drupal::config('xmlsitemap.settings')->get('xmlsitemap_minimum_lifetime')) {
return;
}
......@@ -423,7 +423,7 @@ function xmlsitemap_sitemap_save(stdClass $sitemap) {
->execute();
// Mark the sitemaps as needing regeneration.
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
}
if ($sitemap->is_new) {
......@@ -515,7 +515,7 @@ function xmlsitemap_sitemap_uri(stdClass $sitemap) {
drupal_alter('xmlsitemap_context_url_options', $uri['options'], $sitemap->context);
$uri['options'] += array(
'absolute' => TRUE,
'base_url' => variable_get('xmlsitemap_base_url', $GLOBALS['base_url']),
'base_url' => $GLOBALS['base_url'],
);
return $uri;
}
......@@ -592,7 +592,7 @@ function xmlsitemap_link_save(array $link) {
$existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, array(':type' => $link['type'], ':id' => $link['id']))->fetchAssoc();
// Check if this is a changed link and set the regenerate flag if necessary.
if (!variable_get('xmlsitemap_regenerate_needed', FALSE)) {
if (!\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_regenerate_needed')) {
_xmlsitemap_check_changed_link($link, $existing, TRUE);
}
......@@ -625,7 +625,7 @@ function xmlsitemap_link_save(array $link) {
function xmlsitemap_link_update_multiple($updates = array(), $conditions = array(), $check_flag = TRUE) {
// If we are going to modify a visible sitemap link, we will need to set
// the regenerate needed flag.
if ($check_flag && !variable_get('xmlsitemap_regenerate_needed', FALSE)) {
if ($check_flag && !\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_regenerate_needed')) {
_xmlsitemap_check_changed_links($conditions, $updates, TRUE);
}
......@@ -678,7 +678,7 @@ function xmlsitemap_link_delete_multiple(array $conditions) {
return FALSE;
}
if (!variable_get('xmlsitemap_regenerate_needed', TRUE)) {
if (!\Drupal::config('xmlsitemap.settings')->get('xmlsitemap_regenerate_needed')) {
_xmlsitemap_check_changed_links($conditions, array(), TRUE);
}
......@@ -717,7 +717,7 @@ function _xmlsitemap_check_changed_links(array $conditions = array(), array $upd
$changed = $query->execute()->fetchField();
if ($changed && $flag) {
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
......@@ -764,7 +764,7 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
}
if ($changed && $flag) {
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
}
return $changed;
......@@ -883,7 +883,7 @@ function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
continue;
}
$entry_path = $path . '/' . $entry;
file_unmanaged_delete_recursive($entry_path, TRUE);
file_unmanaged_delete_recursive($entry_path, NULL);
}
$dir->close();
return $delete_root ? drupal_rmdir($path) : TRUE;
......@@ -1024,7 +1024,7 @@ function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings,
}
}
variable_set("xmlsitemap_settings_{$entity}_{$bundle}", $settings);
\Drupal::config('xmlsitemap.settings')->set("xmlsitemap_settings_{$entity}_{$bundle}", $settings);
cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE);
//xmlsitemap_get_link_info(NULL, TRUE);
}
......@@ -1032,7 +1032,7 @@ function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings,
function xmlsitemap_link_bundle_rename($entity, $bundle_old, $bundle_new) {
if ($bundle_old != $bundle_new) {
$settings = xmlsitemap_link_bundle_load($entity, $bundle_old);
variable_del("xmlsitemap_settings_{$entity}_{$bundle_old}");
\Drupal::config('xmlsitemap.settings')->clear("xmlsitemap_settings_{$entity}_{$bundle_old}");
xmlsitemap_link_bundle_settings_save($entity, $bundle_new, $settings, FALSE);
xmlsitemap_link_update_multiple(array('subtype' => $bundle_new), array('type' => $entity, 'subtype' => $bundle_old));
}
......@@ -1044,11 +1044,11 @@ function xmlsitemap_link_bundle_rename($entity, $bundle_old, $bundle_new) {
function xmlsitemap_link_type_rename($entity_old, $entity_new, $bundles = NULL) {
$variables = db_query("SELECT name FROM {variable} WHERE name LIKE :pattern", array(':pattern' => db_like('xmlsitemap_settings_' . $entity_old . '_') . '%'))->fetchCol();
foreach ($variables as $variable) {
$value = variable_get($variable);
variable_del($variable);
$value = \Drupal::config('xmlsitemap.settings')->get($variable);
\Drupal::config('xmlsitemap.settings')->clear($variable);
if (isset($value)) {
$variable_new = str_replace('xmlsitemap_settings_' . $entity_old, 'xmlsitemap_settings_' . $entity_new, $variable);
variable_set($variable_new, $value);
\Drupal::config('xmlsitemap.settings')->set($variable_new, $value);
}
}
......@@ -1067,7 +1067,7 @@ function xmlsitemap_link_bundle_load($entity, $bundle, $load_bundle_info = TRUE)
$info['info'] = $entity_info['bundles'][$bundle];
}
}
$info += variable_get("xmlsitemap_settings_{$entity}_{$bundle}", array());
$info += \Drupal::config('xmlsitemap.settings')->get("xmlsitemap_settings_{$entity}_{$bundle}");
$info += array(
'status' => XMLSITEMAP_STATUS_DEFAULT,
'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
......@@ -1076,7 +1076,7 @@ function xmlsitemap_link_bundle_load($entity, $bundle, $load_bundle_info = TRUE)
}
function xmlsitemap_link_bundle_delete($entity, $bundle, $delete_links = TRUE) {
variable_del("xmlsitemap_settings_{$entity}_{$bundle}");
\Drupal::config('xmlsitemap.settings')->clear("xmlsitemap_settings_{$entity}_{$bundle}");
if ($delete_links) {
xmlsitemap_link_delete_multiple(array('type' => $entity, 'subtype' => $bundle));
}
......@@ -1246,12 +1246,17 @@ function xmlsitemap_calculate_changefreq($timestamps) {
*/
function xmlsitemap_form_submit_flag_regenerate($form, $form_state) {
foreach ($form_state['values'] as $variable => $value) {
$stored_value = variable_get($variable, 'not_a_variable');
if (\Drupal::config('xmlsitemap.settings')->get($variable) == NULL) {
$stored_value = 'not_a_variable';
}
else {
$stored_value = \Drupal::config('xmlsitemap.settings')->get($variable);
}
if (is_array($value) && !empty($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
if ($stored_value != 'not_a_variable' && $stored_value != $value) {
variable_set('xmlsitemap_regenerate_needed', TRUE);
\Drupal::config('xmlsitemap.settings')->set('xmlsitemap_regenerate_needed', TRUE);
drupal_set_message(t('XML sitemap settings have been modified and the files should be regenerated. You can <a href="@run-cron">run cron manually</a> to regenerate the cached files.', array('@run-cron' => url('admin/reports/status/run-cron', array('query' => drupal_get_destination())))), 'warning', FALSE);
return;
}
......
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