diff --git a/Core/CacheWarmer.php b/Core/CacheWarmer.php index 5713740..9154396 100644 --- a/Core/CacheWarmer.php +++ b/Core/CacheWarmer.php @@ -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); @@ -94,16 +99,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 +133,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; } diff --git a/README.md b/README.md index 2585a2a..798a40a 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/bin/warmup.php b/bin/warmup.php index 72fc60d..bdfb6e4 100644 --- a/bin/warmup.php +++ b/bin/warmup.php @@ -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); diff --git a/metadata.php b/metadata.php index e1371b6..e60dff0 100644 --- a/metadata.php +++ b/metadata.php @@ -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' => '',