Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ba687d58e6 | ||
a1ff8970f9 | |||
|
87fc962739 | ||
13a5758ad4 |
@ -22,14 +22,19 @@ use OxidEsales\Eshop\Core\Registry;
|
|||||||
*/
|
*/
|
||||||
class CacheWarmer
|
class CacheWarmer
|
||||||
{
|
{
|
||||||
|
private string $sCliSiteMapFile = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function run()
|
public function run($sFileSitemap)
|
||||||
{
|
{
|
||||||
|
$this->sCliSiteMapFile = trim($sFileSitemap);
|
||||||
|
|
||||||
$aUrls = $this->_getSitemapContent();
|
$aUrls = $this->_getSitemapContent();
|
||||||
if (!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && !empty($aUrls)) {
|
if ((!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl'))
|
||||||
|
|| !empty($sFileSitemap))
|
||||||
|
&& !empty($aUrls)) {
|
||||||
foreach ($aUrls as $sUrl) {
|
foreach ($aUrls as $sUrl) {
|
||||||
$oCurl = $this->_runCurlConnect($sUrl);
|
$oCurl = $this->_runCurlConnect($sUrl);
|
||||||
$this->_checkCurlResults($oCurl, $sUrl);
|
$this->_checkCurlResults($oCurl, $sUrl);
|
||||||
@ -50,6 +55,7 @@ class CacheWarmer
|
|||||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
|
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
|
||||||
curl_setopt($oCurl, CURLOPT_HEADER, true);
|
curl_setopt($oCurl, CURLOPT_HEADER, true);
|
||||||
|
curl_setopt($oCurl, CURLOPT_USERAGENT, 'CacheWarmer');
|
||||||
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
|
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
|
||||||
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
|
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
|
||||||
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
|
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
|
||||||
@ -94,16 +100,18 @@ class CacheWarmer
|
|||||||
protected function _getSitemapContent($sSitemapUrl = "")
|
protected function _getSitemapContent($sSitemapUrl = "")
|
||||||
{
|
{
|
||||||
$aUrls = [];
|
$aUrls = [];
|
||||||
if (empty($sSitemapUrl)) {
|
if (empty($sSitemapUrl) && $this->sCliSiteMapFile == '')
|
||||||
$sSitemapUrl = $this->_getSitemapUrl();
|
{
|
||||||
|
$sSitemapUrl = $this->_getSitemapUrl($sSitemapUrl);
|
||||||
|
}
|
||||||
|
elseif (empty($sSitemapUrl) && $this->sCliSiteMapFile != '')
|
||||||
|
{
|
||||||
|
$sSitemapUrl = $this->_getSitemapUrl($this->sCliSiteMapFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
|
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
|
||||||
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
|
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
|
||||||
$sSitemapUrl = str_replace("://", "://" . $sUsername . ":" . $sPassword . "@", $sSitemapUrl);
|
$sSitemapUrl = str_replace("://", "://" . $sUsername . ":" . $sPassword . "@", $sSitemapUrl);
|
||||||
|
|
||||||
echo $sSitemapUrl . "\r\n";
|
|
||||||
|
|
||||||
$sSitemapXmlData = @file_get_contents($sSitemapUrl);
|
$sSitemapXmlData = @file_get_contents($sSitemapUrl);
|
||||||
if ($oSitemap = @simplexml_load_string($sSitemapXmlData)) {
|
if ($oSitemap = @simplexml_load_string($sSitemapXmlData)) {
|
||||||
if (count($oSitemap->sitemap) > 0) {
|
if (count($oSitemap->sitemap) > 0) {
|
||||||
@ -126,10 +134,17 @@ class CacheWarmer
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _getSitemapUrl()
|
protected function _getSitemapUrl($sSitemapFile)
|
||||||
{
|
{
|
||||||
$sSitemapUrl = Registry::getConfig()->getShopURL();
|
$sSitemapUrl = Registry::getConfig()->getShopURL();
|
||||||
|
|
||||||
|
if($sSitemapFile != '')
|
||||||
|
{
|
||||||
|
$sSitemapUrl .= $sSitemapFile;
|
||||||
|
}
|
||||||
|
else{
|
||||||
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
|
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
|
||||||
|
}
|
||||||
|
|
||||||
return $sSitemapUrl;
|
return $sSitemapUrl;
|
||||||
}
|
}
|
||||||
|
10
README.md
10
README.md
@ -6,7 +6,7 @@ Free module for OXID eshop 6.
|
|||||||
|
|
||||||
Features
|
Features
|
||||||
|
|
||||||
- set sitemap url in admin
|
- set sitemap url in admin / or cli parameter
|
||||||
- optional basic auth user/password
|
- optional basic auth user/password
|
||||||
- optional csv logfile
|
- optional csv logfile
|
||||||
|
|
||||||
@ -16,10 +16,16 @@ Installation
|
|||||||
|
|
||||||
Usage
|
Usage
|
||||||
|
|
||||||
php source/modules/pc/cachewarmer/bin/warmup.php [optional parameter s for shop-id, eg. warmup.php -s 2]
|
php source/modules/pc/cachewarmer/bin/warmup.php [optional parameter s for shop-id, eg. warmup.php -s 2 -f sitemaps/categories.xml]
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
-s: ShopId: -s 2
|
||||||
|
-f: Path to separte Sitemap: -f sitemaps/categories.xml
|
||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
2021-03-17 3.1.2 add new new parameter -f for separate File
|
||||||
2020-09-15 3.1.1 readd ee shopurl fix (missing 3.0.1)
|
2020-09-15 3.1.1 readd ee shopurl fix (missing 3.0.1)
|
||||||
2020-09-14 3.1.0 add own logger
|
2020-09-14 3.1.0 add own logger
|
||||||
2020-08-17 3.0.0 cli only, some improvements
|
2020-08-17 3.0.0 cli only, some improvements
|
||||||
|
@ -15,20 +15,28 @@ if (PHP_SAPI != 'cli') {
|
|||||||
die('Only cli execution allowed!'."\r\n");
|
die('Only cli execution allowed!'."\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = getopt('s:');
|
$options = getopt('s:f:');
|
||||||
$shopId = $options['s'] ?? 0;
|
$shopId = $options['s'] ?? 0;
|
||||||
if (!$shopId) {
|
if (!$shopId) {
|
||||||
$shopId = 1;
|
$shopId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sFileSiteMap = $options['f'] ?? '';
|
||||||
|
if (!$sFileSiteMap) {
|
||||||
|
$sFileSitemap = '';
|
||||||
|
}
|
||||||
require_once dirname(__FILE__) . '/../../../../bootstrap.php';
|
require_once dirname(__FILE__) . '/../../../../bootstrap.php';
|
||||||
|
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use ProudCommerce\CacheWarmer\Core\CacheWarmer;
|
use ProudCommerce\CacheWarmer\Core\CacheWarmer;
|
||||||
|
|
||||||
echo 'Shop-ID '.$shopId." is used!\r\n";
|
echo 'Shop-ID '.$shopId." is used!\r\n";
|
||||||
|
if($sFileSiteMap != '') {
|
||||||
|
echo 'Sitemap: ' . $sFileSiteMap . " is used!\r\n";
|
||||||
|
}
|
||||||
Registry::getConfig()->setShopId($shopId);
|
Registry::getConfig()->setShopId($shopId);
|
||||||
Registry::set(Config::class, null);
|
Registry::set(Config::class, null);
|
||||||
|
|
||||||
|
|
||||||
$cacheWarmer = new CacheWarmer();
|
$cacheWarmer = new CacheWarmer();
|
||||||
$cacheWarmer->run();
|
$cacheWarmer->run($sFileSiteMap);
|
||||||
|
@ -27,7 +27,7 @@ $aModule = [
|
|||||||
'en' => 'Automatically calling urls using the xml-sitemap, eg. for cache warmup.',
|
'en' => 'Automatically calling urls using the xml-sitemap, eg. for cache warmup.',
|
||||||
],
|
],
|
||||||
'thumbnail' => 'logo_pc-os.jpg',
|
'thumbnail' => 'logo_pc-os.jpg',
|
||||||
'version' => '3.1.1',
|
'version' => '3.1.2',
|
||||||
'author' => 'ProudCommerce',
|
'author' => 'ProudCommerce',
|
||||||
'url' => 'https://github.com/proudcommerce/psCacheWarmer',
|
'url' => 'https://github.com/proudcommerce/psCacheWarmer',
|
||||||
'email' => '',
|
'email' => '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user