Compare commits

..

No commits in common. "master" and "3.1.0" have entirely different histories.

4 changed files with 18 additions and 48 deletions

View File

@ -8,7 +8,7 @@
* @copyright (c) ProudCommerce | 2020
* @link www.proudcommerce.com
* @package psCacheWarmer
* @version 3.1.1
* @version 3.1.0
**/
namespace ProudCommerce\CacheWarmer\Core;
@ -22,19 +22,14 @@ use OxidEsales\Eshop\Core\Registry;
*/
class CacheWarmer
{
private string $sCliSiteMapFile = '';
/**
*
*/
public function run($sFileSitemap)
public function run()
{
$this->sCliSiteMapFile = trim($sFileSitemap);
$aUrls = $this->_getSitemapContent();
if ((!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl'))
|| !empty($sFileSitemap))
&& !empty($aUrls)) {
if (!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && !empty($aUrls)) {
foreach ($aUrls as $sUrl) {
$oCurl = $this->_runCurlConnect($sUrl);
$this->_checkCurlResults($oCurl, $sUrl);
@ -55,7 +50,6 @@ 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);
@ -100,18 +94,16 @@ class CacheWarmer
protected function _getSitemapContent($sSitemapUrl = "")
{
$aUrls = [];
if (empty($sSitemapUrl) && $this->sCliSiteMapFile == '')
{
$sSitemapUrl = $this->_getSitemapUrl($sSitemapUrl);
}
elseif (empty($sSitemapUrl) && $this->sCliSiteMapFile != '')
{
$sSitemapUrl = $this->_getSitemapUrl($this->sCliSiteMapFile);
if (empty($sSitemapUrl)) {
$sSitemapUrl = $this->_getSitemapUrl();
}
$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) {
@ -134,17 +126,10 @@ class CacheWarmer
/**
* @return string
*/
protected function _getSitemapUrl($sSitemapFile)
protected function _getSitemapUrl()
{
$sSitemapUrl = Registry::getConfig()->getShopURL();
if($sSitemapFile != '')
{
$sSitemapUrl .= $sSitemapFile;
}
else{
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
}
$sSitemapUrl = Registry::getConfig()->getConfigParam('sShopURL');
$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 / or cli parameter
- set sitemap url in admin
- optional basic auth user/password
- optional csv logfile
@ -16,18 +16,11 @@ Installation
Usage
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
php source/modules/pc/cachewarmer/bin/warmup.php [optional parameter s for shop-id, eg. warmup.php -s 2]
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-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-06 2.2.1 fix for OXID 6.2
2019-07-19 2.2.0 Write Report in a file (PR #3)

View File

@ -15,28 +15,20 @@ if (PHP_SAPI != 'cli') {
die('Only cli execution allowed!'."\r\n");
}
$options = getopt('s:f:');
$options = getopt('s:');
$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($sFileSiteMap);
$cacheWarmer->run();

View File

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