Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with only max 20 XML sitemap files generated on cron jobs #161

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 34 additions & 38 deletions gsitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,45 +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;
} 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);
} 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,
]));
}
}

Expand Down
4 changes: 3 additions & 1 deletion views/templates/admin/configuration.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@
<br><span style="font-style: italic;">{l s='-or-' d='Modules.Gsitemap.Admin'}</span><br><br>
2. <strong>{l s='Automatically:' d='Modules.Gsitemap.Admin'}</strong> {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'}
<a href="{$gsitemap_cron|escape:'htmlall':'UTF-8'}" target="_blank">{$gsitemap_cron|escape:'htmlall':'UTF-8'}</a><br>
{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'}<br>
{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'}<br>
{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'}<br>
</p>
{/if}
</p>
Expand Down