From 184d9c61fa2f3d6586448cb1180f678796e471c1 Mon Sep 17 00:00:00 2001 From: Alexander Vokin Date: Tue, 9 Jul 2024 18:22:16 +0800 Subject: [PATCH] adding_validation_of_sitemapVersion_before_import_of_sitemap --- src/_locales/en/messages.json | 3 +++ src/_locales/ru/messages.json | 3 +++ src/scripts/Controller.js | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index d59998e..4e275e9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -245,6 +245,9 @@ "sitemapmodel_empty_message": { "message": "Empty value is possible model" }, "sitemapjson_invalid_message": { "message": "JSON is not valid" }, "sitemapjson_empty_message": { "message": "Sitemap JSON is required and cannot be empty" }, + "sitemap_invalid_specificationVersion": { + "message": "The version of the sitemap is younger than the plugin version. Please update the plugin" + }, "sitemap_url_pattern_empty_message": { "message": "URL pattern is required and can't be empty" }, diff --git a/src/_locales/ru/messages.json b/src/_locales/ru/messages.json index 188726a..9563025 100644 --- a/src/_locales/ru/messages.json +++ b/src/_locales/ru/messages.json @@ -267,6 +267,9 @@ "sitemapjson_empty_message": { "message": "JSON карта обхода обязателен и не может быть пустым" }, + "sitemap_invalid_specificationVersion": { + "message": "Версия карты обхода новее чем версия плагина. Пожалуйста обновите плагин" + }, "sitemap_url_pattern_empty_message": { "message": "Шаблон URL не может быть пустым" }, "sitemap_url_pattern_invalid_message": { "message": "Шаблон URL должен быть корректным регулярным выражением" diff --git a/src/scripts/Controller.js b/src/scripts/Controller.js index 38a8c0d..8564b03 100644 --- a/src/scripts/Controller.js +++ b/src/scripts/Controller.js @@ -15,7 +15,7 @@ import SelectorList from './SelectorList'; import SelectorTable from './Selector/SelectorTable'; import Model from './Model'; import Translator from './Translator'; - +import SitemapSpecMigrationManager from './SitemapSpecMigration/Manager'; export default class SitemapController { constructor(store, templateDir) { this.store = store; @@ -609,7 +609,22 @@ export default class SitemapController { }; } } - + // check sitemapSpecificationVersion not younger than plugin version + if (sitemap.hasOwnProperty('sitemapSpecificationVersion')) { + const versionOfSitemap = + sitemap.sitemapSpecificationVersion; + if ( + versionOfSitemap > + SitemapSpecMigrationManager.currentVersion() + ) { + return { + valid: false, + message: Translator.getTranslationByKey( + 'sitemap_invalid_specificationVersion' + ), + }; + } + } // check for start urls or url pattern if ( Object.hasOwn(sitemap, 'startUrls') &&