Merge pull request #3 from gaertnermarkus/patch-1

thanks!
Dieser Commit ist enthalten in:
ProudCommerce 2019-07-23 11:00:31 +02:00 committet von GitHub
Commit a2dcbd6f08
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 117 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,13 @@ use OxidEsales\Eshop\Core\Controller\BaseController;
class CacheWarmer extends BaseController
{
protected $_sFileAndPathToExportFile = '';
protected $_handle = null;
protected $_sSeparator = ";";
protected $_sEnclosure = "'";
// todo: add to config
protected $_aHttpCodesIsOkay = array('200','302');
/**
* Executes cache warmer
*/
@ -25,31 +32,18 @@ class CacheWarmer extends BaseController
{
$sMessage = "<b>psCacheWarmer</b><br>".$this->_getSitemapUrl()."<br>---<br>";
$this->_sFileAndPathToExportFile = $this->_getPathWithFileName();
if(Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)
{
$this->_handle = fopen( $this->_sFileAndPathToExportFile, "w+");;
}
if($this->_checkAuthentification()) {
$aUrls = $this->_getSitemapContent();
if(!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && count($aUrls) > 0) {
foreach($aUrls as $sUrl) {
$oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
curl_setopt($oCurl, CURLOPT_HEADER, true);
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
curl_exec($oCurl);
$httpStatus = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
if(curl_error($oCurl)) {
$sMessage .= '<span style="color: orange;">ERROR '.$httpStatus.': ' . curl_error($oCurl) . '</span><br>';
} else {
if(trim($httpStatus) == '500')
{
$sMessage .= '<span style="color: red;">ERROR <b>'.$httpStatus.'</b>: ' . $sUrl. '</span><br>';
}
else{
$sMessage .= '<span style="color: green;">OK '.$httpStatus.': ' . $sUrl . '</span><br>';
}
}
$oCurl = $this->_runCurlConnect($sUrl);
$sMessage .= $this->_checkCurlResults($oCurl,$sUrl);
curl_close($oCurl);
}
} else {
@ -59,10 +53,73 @@ class CacheWarmer extends BaseController
$sMessage .= '<span style="color: red;">Authentifizierung fehlgeschlagen!</span>';
}
if(Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)
{
fclose($this->_handle);
}
echo '<pre>'.$sMessage.'</pre>';
exit;
}
/**
* @param $sUrl
* @return false|resource
*/
protected function _runCurlConnect($sUrl)
{
$oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
curl_setopt($oCurl, CURLOPT_HEADER, true);
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
curl_exec($oCurl);
return $oCurl;
}
protected function _checkCurlResults($oCurl,$sUrl)
{
$sMessage = '';
$httpStatus = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
if(curl_error($oCurl)) {
$sMessage .= '<span style="color: orange;">ERROR '.$httpStatus.': ' . curl_error($oCurl) . '</span><br>';
$sStatusMsg = 'ERROR';
$sTmpText = curl_error($oCurl);
} else {
$sTmpText = $sUrl;
if(in_array(trim($httpStatus),$this->_aHttpCodesIsOkay))
{
$sMessage .= '<span style="color: green;">OK '.$httpStatus.': ' . $sUrl . '</span><br>';
$sStatusMsg = 'OK';
}
else{
$sMessage .= '<span style="color: red;">ERROR <b>'.$httpStatus.'</b>: ' . $sUrl. '</span><br>';
$sStatusMsg = 'ERROR';
}
}
if(Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)
{
$aTmp = array($sStatusMsg,
$httpStatus,
$sTmpText
);
if(trim($httpStatus) == '200' && Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsvOnlyError') == true)
{
$aTmp = array();
}
if(count($aTmp)) {
fputcsv($this->_handle, $aTmp, $this->_sSeparator, $this->_sEnclosure);
}
}
return $sMessage;
}
/**
* Returens urls from sitemap
*
@ -125,4 +182,26 @@ class CacheWarmer extends BaseController
}
return false;
}
/**
* Return Path with Filename, from /log
*
* @return string
*/
protected function _getPathWithFileName()
{
return Registry::getConfig()->getConfigParam('sShopDir').'/log/'.$this->_getFileName();
}
/**
* Return Filename, Formae psCacheWarmerReport_20190717-122345.csv
*
* @return string
*/
protected function _getFileName()
{
return 'psCacheWarmerReport_'.date("Ymd-His").".csv";
}
}

Datei anzeigen

@ -22,6 +22,8 @@ $aLang = array(
'SHOP_MODULE_psCacheWarmerKey' => 'Cronjob-Key',
'SHOP_MODULE_psCacheWarmerUser' => 'Basic-Auth Benutzer',
'SHOP_MODULE_psCacheWarmerPass' => 'Basic-Auth Kennwort',
'SHOP_MODULE_psCacheWarmerWriteCsv' => 'Report als CSV-Datei im Log-Ordner abspeichern',
'SHOP_MODULE_psCacheWarmerWriteCsvOnlyError' => 'Alle Ergebnisse ausser HTTP-Code 200 loggen',
);

Datei anzeigen

@ -18,6 +18,7 @@ Installation
Changelog
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)
2019-06-26 2.0.0 OXID eShop 6 (PR #1)
2016-10-12 1.0.1 fix reading sitemap url with user/pass,fix checking sitemap object

Datei anzeigen

@ -1,6 +1,6 @@
{
"name": "proudcommerce/cachewarmer",
"version": "2.1.0",
"version": "2.2.0",
"description": "psCacheWarmer",
"type": "oxideshop-module",
"license": [

Datei anzeigen

@ -29,7 +29,7 @@ $aModule = array(
<b>URL:</b> <a href="'.oxRegistry::getConfig()->getConfigParam('sShopURL').'?cl=psCacheWarmer&key='.oxRegistry::getConfig()->getShopConfVar('psCacheWarmerKey', oxRegistry::getConfig()->getShopId()).'" target="_blank">'.oxRegistry::getConfig()->getConfigParam('sShopURL').'?cl=psCacheWarmer&key='.oxRegistry::getConfig()->getShopConfVar('psCacheWarmerKey', oxRegistry::getConfig()->getShopId()).'</a>',
),
'thumbnail' => 'logo_pc-os.jpg',
'version' => '2.1.0',
'version' => '2.2.0',
'author' => 'Proud Sourcing GmbH',
'url' => 'http://www.proudcommerce.com/',
'email' => 'support@proudcommerce.com',
@ -67,5 +67,17 @@ $aModule = array(
'type' => 'str',
'value' => '',
),
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerWriteCsv',
'type' => 'bool',
'value' => '',
),
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerWriteCsvOnlyError',
'type' => 'bool',
'value' => '',
),
),
);