Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ba687d58e6 | ||
a1ff8970f9 | |||
|
87fc962739 | ||
13a5758ad4 | |||
|
f9d1561ea7 | ||
|
dbdd20d7d6 | ||
|
b32e37873d | ||
|
638fcc064a | ||
|
fc6373de2b | ||
|
93bf8fe856 |
@ -6,9 +6,9 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* @copyright (c) ProudCommerce | 2020
|
* @copyright (c) ProudCommerce | 2020
|
||||||
* @link www.proudcommerce.com
|
* @link www.proudcommerce.com
|
||||||
* @package psCacheWarmer
|
* @package psCacheWarmer
|
||||||
* @version 3.0.0
|
* @version 3.0.0
|
||||||
**/
|
**/
|
||||||
|
|
||||||
$sLangName = "Deutsch";
|
$sLangName = "Deutsch";
|
||||||
@ -21,9 +21,10 @@ $aLang = [
|
|||||||
'SHOP_MODULE_GROUP_psCacheWarmerConfig' => 'Einstellungen',
|
'SHOP_MODULE_GROUP_psCacheWarmerConfig' => 'Einstellungen',
|
||||||
'SHOP_MODULE_psCacheWarmerSitemapUrl' => 'XML-Sitemap URL',
|
'SHOP_MODULE_psCacheWarmerSitemapUrl' => 'XML-Sitemap URL',
|
||||||
'SHOP_MODULE_psCacheWarmerKey' => 'Cronjob-Key',
|
'SHOP_MODULE_psCacheWarmerKey' => 'Cronjob-Key',
|
||||||
|
'SHOP_MODULE_psCacheWarmerHttpCodes' => 'gültige HTTP-Responsecode (OK im LOG-File, sonst ERROR)',
|
||||||
'SHOP_MODULE_psCacheWarmerUser' => 'Basic-Auth Benutzer',
|
'SHOP_MODULE_psCacheWarmerUser' => 'Basic-Auth Benutzer',
|
||||||
'SHOP_MODULE_psCacheWarmerPass' => 'Basic-Auth Kennwort',
|
'SHOP_MODULE_psCacheWarmerPass' => 'Basic-Auth Kennwort',
|
||||||
'SHOP_MODULE_psCacheWarmerWriteCsv' => 'Logfile für gesamten Crawl',
|
'SHOP_MODULE_psCacheWarmerWriteCsv' => 'LOG-File für gesamten Crawl',
|
||||||
'SHOP_MODULE_psCacheWarmerWriteCsvOnlyError' => 'Logfile nur bei HTTP-Codes != 200',
|
'SHOP_MODULE_psCacheWarmerWriteCsvOnlyError' => 'LOG-File nur wenn HTTP-Responsecode != 200',
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* @copyright (c) ProudCommerce | 2020
|
* @copyright (c) ProudCommerce | 2020
|
||||||
* @link www.proudcommerce.com
|
* @link www.proudcommerce.com
|
||||||
* @package psCacheWarmer
|
* @package psCacheWarmer
|
||||||
* @version 3.0.0
|
* @version 3.1.1
|
||||||
**/
|
**/
|
||||||
|
|
||||||
namespace ProudCommerce\CacheWarmer\Core;
|
namespace ProudCommerce\CacheWarmer\Core;
|
||||||
@ -17,18 +17,24 @@ use OxidEsales\Eshop\Core\Registry;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CacheWarmer
|
* Class CacheWarmer
|
||||||
|
*
|
||||||
* @package ProudCommerce\CacheWarmer\Core
|
* @package ProudCommerce\CacheWarmer\Core
|
||||||
*/
|
*/
|
||||||
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);
|
||||||
@ -39,6 +45,7 @@ class CacheWarmer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $sUrl
|
* @param $sUrl
|
||||||
|
*
|
||||||
* @return false|resource
|
* @return false|resource
|
||||||
*/
|
*/
|
||||||
protected function _runCurlConnect($sUrl)
|
protected function _runCurlConnect($sUrl)
|
||||||
@ -48,10 +55,12 @@ 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);
|
||||||
curl_exec($oCurl);
|
curl_exec($oCurl);
|
||||||
|
|
||||||
return $oCurl;
|
return $oCurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,53 +87,65 @@ class CacheWarmer
|
|||||||
print_r($aLog);
|
print_r($aLog);
|
||||||
|
|
||||||
if (!empty($aLog) && ((Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsvOnlyError') == true && $httpStatus != '200') || Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)) {
|
if (!empty($aLog) && ((Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsvOnlyError') == true && $httpStatus != '200') || Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)) {
|
||||||
Registry::getUtils()->writeToLog(implode(' | ', $aLog) . "\r", 'pscachewarmer_' . date("d.m.Y H:i:s") . '.log');
|
$logger = Logging::getLogger('psCacheWarmer', Registry::getConfig()->getLogsDir() . 'pscachewarmer_' . date("dmY_His") . '.log');
|
||||||
|
$logger->info(implode(' | ', $aLog) . "\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sSitemapUrl
|
* @param string $sSitemapUrl
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
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) {
|
||||||
foreach ($oSitemap->sitemap as $oSubSitemap) {
|
foreach ($oSitemap->sitemap as $oSubSitemap) {
|
||||||
$sNextSitemapUrl = (string)$oSubSitemap->loc;
|
$sNextSitemapUrl = (string) $oSubSitemap->loc;
|
||||||
$aUrls = array_merge($aUrls, $this->_getSitemapContent($sNextSitemapUrl));
|
$aUrls = array_merge($aUrls, $this->_getSitemapContent($sNextSitemapUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($oSitemap->url) > 0) {
|
if (count($oSitemap->url) > 0) {
|
||||||
foreach ($oSitemap->url as $oSitemapUrl) {
|
foreach ($oSitemap->url as $oSitemapUrl) {
|
||||||
$aUrls[] = (string)$oSitemapUrl->loc;
|
$aUrls[] = (string) $oSitemapUrl->loc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aUrls;
|
return $aUrls;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
60
Core/Logging.php
Normal file
60
Core/Logging.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @copyright (c) ProudCommerce | 2020
|
||||||
|
* @link www.proudcommerce.com
|
||||||
|
* @package psCacheWarmer
|
||||||
|
* @version 3.1.0
|
||||||
|
**/
|
||||||
|
|
||||||
|
namespace ProudCommerce\CacheWarmer\Core;
|
||||||
|
|
||||||
|
use \OxidEsales\Eshop\Core\Registry;
|
||||||
|
use \Monolog\Logger;
|
||||||
|
use \Monolog\Handler\StreamHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Logging
|
||||||
|
*
|
||||||
|
* @package ProudCommerce\CacheWarmer\Core
|
||||||
|
*/
|
||||||
|
class Logging
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $_aLogger = [];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sLogger
|
||||||
|
* @param string $sPath
|
||||||
|
* @param string $sLogLevel
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function getLogger(string $sLogger = '', string $sPath = '', string $sLogLevel = ''): Logger
|
||||||
|
{
|
||||||
|
$sLogger = (!empty($sLogger) ? $sLogger : 'OXID Logger');
|
||||||
|
if (!array_key_exists($sLogger, self::$_aLogger)) {
|
||||||
|
$sPath = ((!empty($sPath)) ? $sPath : Registry::getConfig()->getLogsDir() . 'oxideshop.log');
|
||||||
|
$sLogLevel = strtoupper($sLogLevel);
|
||||||
|
$sLogLevel = ((!empty($sLogLevel) && defined("Logger::$sLogLevel")) ? constant("Logger::$sLogLevel") : Logger::DEBUG);
|
||||||
|
self::$_aLogger[ $sLogger ] = new Logger($sLogger);
|
||||||
|
self::$_aLogger[ $sLogger ]->pushHandler(
|
||||||
|
new StreamHandler(
|
||||||
|
$sPath,
|
||||||
|
$sLogLevel
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$_aLogger[ $sLogger ];
|
||||||
|
}
|
||||||
|
}
|
12
README.md
12
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,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
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -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);
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* @copyright (c) ProudCommerce | 2020
|
* @copyright (c) ProudCommerce | 2020
|
||||||
* @link www.proudcommerce.com
|
* @link www.proudcommerce.com
|
||||||
* @package psCacheWarmer
|
* @package psCacheWarmer
|
||||||
* @version 3.0.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.0.0',
|
'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