latest changes

Cette révision appartient à :
Tobias Merkl 2020-08-17 15:13:10 +02:00
Parent 7fcf810ce4
révision 6d955441b4
Signature inconnue de Gitea
ID de la clé GPG: B971FFBCFA6D09BC
4 fichiers modifiés avec 52 ajouts et 40 suppressions

Voir le fichier

@ -23,7 +23,7 @@ $aLang = [
'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',
'SHOP_MODULE_psCacheWarmerWriteCsv' => 'Logfile für gesamten Crawl',
'SHOP_MODULE_psCacheWarmerWriteCsvOnlyError' => 'Logfile nur bei HTTP-Codes != 200',
];

Voir le fichier

@ -13,40 +13,28 @@
namespace ProudCommerce\CacheWarmer\Core;
if (PHP_SAPI != 'cli') {
throw new RuntimeException('Only cli execution allowed!');
}
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Controller\BaseController;
/**
* Class CacheWarmer
* @package ProudCommerce\CacheWarmer\Core
*/
class CacheWarmer extends BaseController
class CacheWarmer
{
/**
* @return string|void|null
*
*/
public function render()
public function run()
{
$sMessage = "<b>psCacheWarmer</b><br>" . $this->_getSitemapUrl() . "<br>---<br>";
$aUrls = $this->_getSitemapContent();
if (!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && count($aUrls) > 0) {
if (!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && !empty($aUrls)) {
foreach ($aUrls as $sUrl) {
$oCurl = $this->_runCurlConnect($sUrl);
$sMessage .= $this->_checkCurlResults($oCurl, $sUrl);
$this->_checkCurlResults($oCurl, $sUrl);
curl_close($oCurl);
}
} else {
$sMessage .= '<span style="color: red;">Keine Daten vorhanden!</span>';
}
echo '<pre>' . $sMessage . '</pre>';
exit;
}
/**
@ -70,40 +58,29 @@ class CacheWarmer extends BaseController
/**
* @param $oCurl
* @param $sUrl
* @return string
*/
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);
$sMessage = curl_error($oCurl);
} else {
$sTmpText = $sUrl;
if (in_array(trim($httpStatus), Registry::getConfig()->getShopConfVar('psCacheWarmerConfig'))) {
$sMessage .= '<span style="color: green;">OK ' . $httpStatus . ': ' . $sUrl . '</span><br>';
$sMessage = $sUrl;
if (in_array(trim($httpStatus), Registry::getConfig()->getShopConfVar('psCacheWarmerHttpCodes'))) {
$sStatusMsg = 'OK';
} else {
$sMessage .= '<span style="color: red;">ERROR <b>' . $httpStatus . '</b>: ' . $sUrl . '</span><br>';
$sStatusMsg = 'ERROR';
}
}
$httpStatus = trim($httpStatus);
$aLog = [$sStatusMsg, $httpStatus, $sMessage];
print_r($aLog);
if (Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true) {
$aTmp = [$sStatusMsg, $httpStatus, $sTmpText];
if (trim($httpStatus) == '200' && Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsvOnlyError') == true) {
$aTmp = [];
}
if (count($aTmp)) {
Registry::getUtils()->writeToLog(implode(' | ', $aTmp) . "\r", 'tabslbillomat_' . date("d.m.Y H:i:s") . '.log');
}
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');
}
return $sMessage;
}
/**
@ -121,6 +98,8 @@ class CacheWarmer extends BaseController
$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) {
@ -136,7 +115,6 @@ class CacheWarmer extends BaseController
}
}
}
#print_r($aUrls);
return $aUrls;
}

Voir le fichier

@ -16,7 +16,7 @@ Installation
Usage
php source/modules/pc/cachewarmer/Core/CacheWarmer.php
php source/modules/pc/cachewarmer/bin/warmup.php [optional parameter s for shop-id, eg. warmup.php -s 2]
Changelog

34
bin/warmup.php Fichier normal
Voir le fichier

@ -0,0 +1,34 @@
<?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.0.0
**/
if (PHP_SAPI != 'cli') {
die('Only cli execution allowed!'."\r\n");
}
$options = getopt('s:');
$shopId = $options['s'] ?? 0;
if (!$shopId) {
$shopId = 1;
}
require_once dirname(__FILE__) . '/../../../../bootstrap.php';
use OxidEsales\Eshop\Core\Registry;
use ProudCommerce\CacheWarmer\Core\CacheWarmer;
echo 'Shop-ID '.$shopId." is used!\r\n";
Registry::getConfig()->setShopId($shopId);
Registry::set(Config::class, null);
$cacheWarmer = new CacheWarmer();
$cacheWarmer->run();