From e0aa533505999dec1d73145ae3da65850193e8d7 Mon Sep 17 00:00:00 2001
From: Dimitrios Karvounaris
Date: Wed, 15 Mar 2023 13:53:38 +0100
Subject: [PATCH 1/4] Fix issue not creating more than 20 sitemaps with cron
and CLI request tools (as curl)
---
gsitemap.php | 3 ---
1 file changed, 3 deletions(-)
diff --git a/gsitemap.php b/gsitemap.php
index 92121c5..e664003 100755
--- a/gsitemap.php
+++ b/gsitemap.php
@@ -295,9 +295,6 @@ public function addLinkToSitemap(&$link_sitemap, $new_link, $lang, &$index, &$i,
]);
return false;
- } elseif ($index % 20 == 0 && $this->cron) {
- header('Refresh: 5; url=http' . (Configuration::get('PS_SSL_ENABLED') ? 's' : '') . '://' . Tools::getShopDomain(false, true) . __PS_BASE_URI__ . 'modules/gsitemap/gsitemap-cron.php?continue=1&token=' . Tools::substr(Tools::hash('gsitemap/cron'), 0, 10) . '&type=' . $new_link['type'] . '&lang=' . $lang . '&index=' . $index . '&id=' . (int) $id_obj . '&id_shop=' . $this->context->shop->id);
- exit();
} else {
if ($this->cron) {
Tools::redirect($this->context->link->getBaseLink() . 'modules/gsitemap/gsitemap-cron.php?continue=1&token=' . Tools::substr(Tools::hash('gsitemap/cron'), 0, 10) . '&type=' . $new_link['type'] . '&lang=' . $lang . '&index=' . $index . '&id=' . (int) $id_obj . '&id_shop=' . $this->context->shop->id);
From a504413e4f30c895997e17090245ae96292042c6 Mon Sep 17 00:00:00 2001
From: Dimitrios Karvounaris
Date: Wed, 15 Mar 2023 13:58:59 +0100
Subject: [PATCH 2/4] Both else and exit() not needed. Clearer intention and
lower complexity. All paths either return or exit() through class Tools
---
gsitemap.php | 69 ++++++++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 35 deletions(-)
diff --git a/gsitemap.php b/gsitemap.php
index e664003..bf986fd 100755
--- a/gsitemap.php
+++ b/gsitemap.php
@@ -277,42 +277,41 @@ public function addLinkToSitemap(&$link_sitemap, $new_link, $lang, &$index, &$i,
++$i;
return true;
- } else {
- $this->recursiveSitemapCreator($link_sitemap, $lang, $index);
- if ($index % 20 == 0 && !$this->cron) {
- $this->context->smarty->assign([
- 'gsitemap_number' => (int) $index,
- 'gsitemap_refresh_page' => $this->context->link->getAdminLink('AdminModules', true, [], [
- 'tab_module' => $this->tab,
- 'module_name' => $this->name,
- 'continue' => 1,
- 'type' => $new_link['type'],
- 'lang' => $lang,
- 'index' => $index,
- 'id' => (int) $id_obj,
- 'id_shop' => $this->context->shop->id,
- ]),
- ]);
+ }
- return false;
- } else {
- if ($this->cron) {
- Tools::redirect($this->context->link->getBaseLink() . 'modules/gsitemap/gsitemap-cron.php?continue=1&token=' . Tools::substr(Tools::hash('gsitemap/cron'), 0, 10) . '&type=' . $new_link['type'] . '&lang=' . $lang . '&index=' . $index . '&id=' . (int) $id_obj . '&id_shop=' . $this->context->shop->id);
- } else {
- Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], [
- 'tab_module' => $this->tab,
- 'module_name' => $this->name,
- 'configure' => $this->name,
- 'continue' => 1,
- 'type' => $new_link['type'],
- 'lang' => $lang,
- 'index' => $index,
- 'id' => (int) $id_obj,
- 'id_shop' => $this->context->shop->id,
- ]));
- }
- exit();
- }
+ $this->recursiveSitemapCreator($link_sitemap, $lang, $index);
+ if ($index % 20 == 0 && !$this->cron) {
+ $this->context->smarty->assign([
+ 'gsitemap_number' => (int) $index,
+ 'gsitemap_refresh_page' => $this->context->link->getAdminLink('AdminModules', true, [], [
+ 'tab_module' => $this->tab,
+ 'module_name' => $this->name,
+ 'continue' => 1,
+ 'type' => $new_link['type'],
+ 'lang' => $lang,
+ 'index' => $index,
+ 'id' => (int) $id_obj,
+ 'id_shop' => $this->context->shop->id,
+ ]),
+ ]);
+
+ return false;
+ }
+
+ if ($this->cron) {
+ Tools::redirect($this->context->link->getBaseLink() . 'modules/gsitemap/gsitemap-cron.php?continue=1&token=' . Tools::substr(Tools::hash('gsitemap/cron'), 0, 10) . '&type=' . $new_link['type'] . '&lang=' . $lang . '&index=' . $index . '&id=' . (int) $id_obj . '&id_shop=' . $this->context->shop->id);
+ } else {
+ Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], [
+ 'tab_module' => $this->tab,
+ 'module_name' => $this->name,
+ 'configure' => $this->name,
+ 'continue' => 1,
+ 'type' => $new_link['type'],
+ 'lang' => $lang,
+ 'index' => $index,
+ 'id' => (int) $id_obj,
+ 'id_shop' => $this->context->shop->id,
+ ]));
}
}
From 30d4223f52378b6041735a251b3e0eb4018b1449 Mon Sep 17 00:00:00 2001
From: Dimitrios Karvounaris
Date: Wed, 15 Mar 2023 15:17:14 +0100
Subject: [PATCH 3/4] Troubleshooting documentation about increasing the
redirect limit of tools for large shops in cron jobs
---
views/templates/admin/configuration.tpl | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/views/templates/admin/configuration.tpl b/views/templates/admin/configuration.tpl
index 959a65e..41b43d7 100644
--- a/views/templates/admin/configuration.tpl
+++ b/views/templates/admin/configuration.tpl
@@ -128,7 +128,9 @@
{l s='-or-' d='Modules.Gsitemap.Admin'}
2. {l s='Automatically:' d='Modules.Gsitemap.Admin'} {l s='Ask your hosting provider to setup a "Cron job" to load the following URL at the time you would like:' d='Modules.Gsitemap.Admin'}
{$gsitemap_cron|escape:'htmlall':'UTF-8'}
- {l s='It will automatically generate your XML sitemaps.' d='Modules.Gsitemap.Admin'}
+ {l s='It will automatically generate your XML sitemaps.' d='Modules.Gsitemap.Admin'}
+ {l s='If you are using a cron job in combination with a command-line tool, such as curl, and your shop is so large to require a large amount of XML sitemap files generated, you might need to modify the tools default redirect limit.'}
+ {l s='For example: curl follows up to 50 redirects by default. To increase this number further, you will have to add the parameter "-L --max-redirs 99" to the curl command line in your cron job, which increases the redirect limit to 99 redirects.'}
{/if}
From cacf3b9515fa149080f13d6988183021567ba2ce Mon Sep 17 00:00:00 2001
From: Dimitrios Karvounaris
Date: Fri, 31 Mar 2023 16:40:28 +0200
Subject: [PATCH 4/4] Update views/templates/admin/configuration.tpl
Co-authored-by: Krystian Podemski
---
views/templates/admin/configuration.tpl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/views/templates/admin/configuration.tpl b/views/templates/admin/configuration.tpl
index 41b43d7..b9cd1f3 100644
--- a/views/templates/admin/configuration.tpl
+++ b/views/templates/admin/configuration.tpl
@@ -129,8 +129,8 @@
2. {l s='Automatically:' d='Modules.Gsitemap.Admin'} {l s='Ask your hosting provider to setup a "Cron job" to load the following URL at the time you would like:' d='Modules.Gsitemap.Admin'}
{$gsitemap_cron|escape:'htmlall':'UTF-8'}
{l s='It will automatically generate your XML sitemaps.' d='Modules.Gsitemap.Admin'}
- {l s='If you are using a cron job in combination with a command-line tool, such as curl, and your shop is so large to require a large amount of XML sitemap files generated, you might need to modify the tools default redirect limit.'}
- {l s='For example: curl follows up to 50 redirects by default. To increase this number further, you will have to add the parameter "-L --max-redirs 99" to the curl command line in your cron job, which increases the redirect limit to 99 redirects.'}
+ {l s='If you are using a cron job in combination with a command-line tool, such as curl, and your shop is so large to require a large amount of XML sitemap files generated, you might need to modify the tools default redirect limit.' d='Modules.Gsitemap.Admin'}
+ {l s='For example: curl follows up to 50 redirects by default. To increase this number further, you will have to add the parameter "-L --max-redirs 99" to the curl command line in your cron job, which increases the redirect limit to 99 redirects.' d='Modules.Gsitemap.Admin'}
{/if}