Compare commits

...

7 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
Tobias Merkl
f9d1561ea7
Update metadata.php 2020-09-15 11:23:28 +02:00
Tobias Merkl
dbdd20d7d6
fix getting shop url 2020-09-15 11:23:10 +02:00
Tobias Merkl
b32e37873d
Update README.md 2020-09-15 11:22:35 +02:00
4 changed files with 48 additions and 18 deletions

View File

@ -8,7 +8,7 @@
* @copyright (c) ProudCommerce | 2020 * @copyright (c) ProudCommerce | 2020
* @link www.proudcommerce.com * @link www.proudcommerce.com
* @package psCacheWarmer * @package psCacheWarmer
* @version 3.1.0 * @version 3.1.1
**/ **/
namespace ProudCommerce\CacheWarmer\Core; namespace ProudCommerce\CacheWarmer\Core;
@ -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()->getConfigParam('sShopURL'); $sSitemapUrl = Registry::getConfig()->getShopURL();
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
if($sSitemapFile != '')
{
$sSitemapUrl .= $sSitemapFile;
}
else{
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
}
return $sSitemapUrl; return $sSitemapUrl;
} }

View File

@ -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,11 +16,18 @@ 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
2020-09-14 3.1.0 add own logger 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 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-19 2.2.0 Write Report in a file (PR #3)

View File

@ -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);

View File

@ -8,7 +8,7 @@
* @copyright (c) ProudCommerce | 2020 * @copyright (c) ProudCommerce | 2020
* @link www.proudcommerce.com * @link www.proudcommerce.com
* @package psCacheWarmer * @package psCacheWarmer
* @version 3.1.0 * @version 3.1.1
**/ **/
/** /**
@ -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.0', 'version' => '3.1.2',
'author' => 'ProudCommerce', 'author' => 'ProudCommerce',
'url' => 'https://github.com/proudcommerce/psCacheWarmer', 'url' => 'https://github.com/proudcommerce/psCacheWarmer',
'email' => '', 'email' => '',