Compare commits

...

4 Commits

Author SHA1 Message Date
Tobias Merkl
ba687d58e6
Merge pull request #6 from gaertnermarkus/master
add UserAgent "CacheWarmer"
2021-04-23 13:08:23 +02:00
a1ff8970f9 add UserAgent "CacheWarmer" 2021-04-23 10:03:26 +02:00
Tobias Merkl
87fc962739
Merge pull request #5 from gaertnermarkus/master
add cli-parameter for Sitemapfile
2021-03-22 07:43:48 +01:00
13a5758ad4 add cli-parameter for Sitemapfile 2021-03-17 15:10:26 +01:00
4 changed files with 45 additions and 16 deletions

View File

@ -22,14 +22,19 @@ use OxidEsales\Eshop\Core\Registry;
*/
class CacheWarmer
{
private string $sCliSiteMapFile = '';
/**
*
*/
public function run()
public function run($sFileSitemap)
{
$this->sCliSiteMapFile = trim($sFileSitemap);
$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) {
$oCurl = $this->_runCurlConnect($sUrl);
$this->_checkCurlResults($oCurl, $sUrl);
@ -50,6 +55,7 @@ class CacheWarmer
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
curl_setopt($oCurl, CURLOPT_HEADER, true);
curl_setopt($oCurl, CURLOPT_USERAGENT, 'CacheWarmer');
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
@ -94,16 +100,18 @@ class CacheWarmer
protected function _getSitemapContent($sSitemapUrl = "")
{
$aUrls = [];
if (empty($sSitemapUrl)) {
$sSitemapUrl = $this->_getSitemapUrl();
if (empty($sSitemapUrl) && $this->sCliSiteMapFile == '')
{
$sSitemapUrl = $this->_getSitemapUrl($sSitemapUrl);
}
elseif (empty($sSitemapUrl) && $this->sCliSiteMapFile != '')
{
$sSitemapUrl = $this->_getSitemapUrl($this->sCliSiteMapFile);
}
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
$sSitemapUrl = str_replace("://", "://" . $sUsername . ":" . $sPassword . "@", $sSitemapUrl);
echo $sSitemapUrl . "\r\n";
$sSitemapXmlData = @file_get_contents($sSitemapUrl);
if ($oSitemap = @simplexml_load_string($sSitemapXmlData)) {
if (count($oSitemap->sitemap) > 0) {
@ -126,10 +134,17 @@ class CacheWarmer
/**
* @return string
*/
protected function _getSitemapUrl()
protected function _getSitemapUrl($sSitemapFile)
{
$sSitemapUrl = Registry::getConfig()->getShopURL();
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
if($sSitemapFile != '')
{
$sSitemapUrl .= $sSitemapFile;
}
else{
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
}
return $sSitemapUrl;
}

View File

@ -6,7 +6,7 @@ Free module for OXID eshop 6.
Features
- set sitemap url in admin
- set sitemap url in admin / or cli parameter
- optional basic auth user/password
- optional csv logfile
@ -16,13 +16,19 @@ Installation
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
2020-09-15 3.1.1 readd ee shopurl fix (missing 3.0.1)
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-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
2020-08-06 2.2.1 fix for OXID 6.2
2019-07-19 2.2.0 Write Report in a file (PR #3)
2019-07-17 2.1.0 add error 500 check (PR #2)

View File

@ -15,20 +15,28 @@ if (PHP_SAPI != 'cli') {
die('Only cli execution allowed!'."\r\n");
}
$options = getopt('s:');
$options = getopt('s:f:');
$shopId = $options['s'] ?? 0;
if (!$shopId) {
$shopId = 1;
}
$sFileSiteMap = $options['f'] ?? '';
if (!$sFileSiteMap) {
$sFileSitemap = '';
}
require_once dirname(__FILE__) . '/../../../../bootstrap.php';
use OxidEsales\Eshop\Core\Registry;
use ProudCommerce\CacheWarmer\Core\CacheWarmer;
echo 'Shop-ID '.$shopId." is used!\r\n";
if($sFileSiteMap != '') {
echo 'Sitemap: ' . $sFileSiteMap . " is used!\r\n";
}
Registry::getConfig()->setShopId($shopId);
Registry::set(Config::class, null);
$cacheWarmer = new CacheWarmer();
$cacheWarmer->run();
$cacheWarmer->run($sFileSiteMap);

View File

@ -27,7 +27,7 @@ $aModule = [
'en' => 'Automatically calling urls using the xml-sitemap, eg. for cache warmup.',
],
'thumbnail' => 'logo_pc-os.jpg',
'version' => '3.1.1',
'version' => '3.1.2',
'author' => 'ProudCommerce',
'url' => 'https://github.com/proudcommerce/psCacheWarmer',
'email' => '',