Comparer les révisions

..

Pas de révisions en commun. "master" et "oxid410" ont des historiques entièrement différents.

13 fichiers modifiés avec 264 ajouts et 426 suppressions

Voir le fichier

@ -1,30 +0,0 @@
<?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
**/
$sLangName = "Deutsch";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = [
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_psCacheWarmerConfig' => 'Einstellungen',
'SHOP_MODULE_psCacheWarmerSitemapUrl' => 'XML-Sitemap URL',
'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_psCacheWarmerPass' => 'Basic-Auth Kennwort',
'SHOP_MODULE_psCacheWarmerWriteCsv' => 'LOG-File für gesamten Crawl',
'SHOP_MODULE_psCacheWarmerWriteCsvOnlyError' => 'LOG-File nur wenn HTTP-Responsecode != 200',
];

Voir le fichier

@ -1,152 +0,0 @@
<?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.1
**/
namespace ProudCommerce\CacheWarmer\Core;
use OxidEsales\Eshop\Core\Registry;
/**
* Class CacheWarmer
*
* @package ProudCommerce\CacheWarmer\Core
*/
class CacheWarmer
{
private string $sCliSiteMapFile = '';
/**
*
*/
public function run($sFileSitemap)
{
$this->sCliSiteMapFile = trim($sFileSitemap);
$aUrls = $this->_getSitemapContent();
if ((!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl'))
|| !empty($sFileSitemap))
&& !empty($aUrls)) {
foreach ($aUrls as $sUrl) {
$oCurl = $this->_runCurlConnect($sUrl);
$this->_checkCurlResults($oCurl, $sUrl);
curl_close($oCurl);
}
}
}
/**
* @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);
curl_setopt($oCurl, CURLOPT_USERAGENT, 'CacheWarmer');
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
curl_exec($oCurl);
return $oCurl;
}
/**
* @param $oCurl
* @param $sUrl
*/
protected function _checkCurlResults($oCurl, $sUrl)
{
$httpStatus = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
if (curl_error($oCurl)) {
$sStatusMsg = 'ERROR';
$sMessage = curl_error($oCurl);
} else {
$sMessage = $sUrl;
if (in_array(trim($httpStatus), Registry::getConfig()->getShopConfVar('psCacheWarmerHttpCodes'))) {
$sStatusMsg = 'OK';
} else {
$sStatusMsg = 'ERROR';
}
}
$httpStatus = trim($httpStatus);
$aLog = [$sStatusMsg, $httpStatus, $sMessage];
print_r($aLog);
if (!empty($aLog) && ((Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsvOnlyError') == true && $httpStatus != '200') || Registry::getConfig()->getShopConfVar('psCacheWarmerWriteCsv') == true)) {
$logger = Logging::getLogger('psCacheWarmer', Registry::getConfig()->getLogsDir() . 'pscachewarmer_' . date("dmY_His") . '.log');
$logger->info(implode(' | ', $aLog) . "\r");
}
}
/**
* @param string $sSitemapUrl
*
* @return array
*/
protected function _getSitemapContent($sSitemapUrl = "")
{
$aUrls = [];
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);
$sSitemapXmlData = @file_get_contents($sSitemapUrl);
if ($oSitemap = @simplexml_load_string($sSitemapXmlData)) {
if (count($oSitemap->sitemap) > 0) {
foreach ($oSitemap->sitemap as $oSubSitemap) {
$sNextSitemapUrl = (string) $oSubSitemap->loc;
$aUrls = array_merge($aUrls, $this->_getSitemapContent($sNextSitemapUrl));
}
}
if (count($oSitemap->url) > 0) {
foreach ($oSitemap->url as $oSitemapUrl) {
$aUrls[] = (string) $oSitemapUrl->loc;
}
}
}
return $aUrls;
}
/**
* @return string
*/
protected function _getSitemapUrl($sSitemapFile)
{
$sSitemapUrl = Registry::getConfig()->getShopURL();
if($sSitemapFile != '')
{
$sSitemapUrl .= $sSitemapFile;
}
else{
$sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
}
return $sSitemapUrl;
}
}

Voir le fichier

@ -1,60 +0,0 @@
<?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 ];
}
}

Voir le fichier

@ -2,39 +2,25 @@ psCacheWarmer
============
Automatically calling urls using the xml-sitemap, eg. for cache warming.
Free module for OXID eshop 6.
Free module for OXID eshop 4.7, 4.8, 4.9 and 4.10.
Features
- set sitemap url in admin / or cli parameter
- optional basic auth user/password
- optional csv logfile
- admin setting sitemap url
- admin setting security key (cronjob)
- admin setting basic auth user/password
Installation
composer require proudcommerce/cachewarmer
1. copy content from copy_this folder into your shop root
2. activate module psCacheWarmer in shop admin
Usage
Tip: Use the [OXID module connector](https://github.com/OXIDprojects/OXID-Module-Connector) to install this module.
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
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-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)
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
2016-08-25 1.0.0 module release for oxid 4.7, 4.8, 4.9, 4.10
2016-10-12 1.0.1 fix reading sitemap url with user/pass,fix checking sitemap object
2016-08-25 1.0.0 module release for oxid 4.7, 4.8, 4.9, 4.10
License
@ -54,4 +40,5 @@ License
Copyright
ProudCommerce { www.proudcommerce.com }
Proud Sourcing GmbH 2016
www.proudcommerce.com / www.proudsourcing.de

Voir le fichier

@ -1,42 +0,0 @@
<?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: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($sFileSiteMap);

Voir le fichier

@ -1,32 +0,0 @@
{
"name": "proudcommerce/cachewarmer",
"description": "Website anhand der XML-Sitemap automatisch aufrufen, z. B. zum 'Aufwärmen' eines Caches.",
"type": "oxideshop-module",
"license": [
"GPL-3.0-or-later"
],
"authors": [
{
"name": "ProudCommerce",
"homepage": "https://www.proudcommerce.com/",
"email": "welcome@proudcommerce.com",
"role": "Developer"
}
],
"support": {
"email": "support@proudcommerce.com"
},
"require": {
"php": ">= 7.0"
},
"autoload": {
"psr-4": {
"ProudCommerce\\CacheWarmer\\": "../../../source/modules/pc/cachewarmer"
}
},
"extra": {
"oxideshop": {
"target-directory": "pc/cachewarmer"
}
}
}

Voir le fichier

@ -0,0 +1,116 @@
<?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) Proud Sourcing GmbH | 2016
* @link www.proudcommerce.com
* @package psCacheWarmer
* @version 1.0.1
**/
class psCacheWarmer extends oxUBase
{
/**
* Executes cache warmer
*/
public function render()
{
$sMessage = "<b>psCacheWarmer</b><br>".$this->_getSitemapUrl()."<br>---<br>";
if($this->_checkAuthentification()) {
$aUrls = $this->_getSitemapContent();
if(!empty(oxRegistry::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 = oxRegistry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = oxRegistry::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 {
$sMessage .= '<span style="color: green;">OK '.$httpStatus.': ' . $sUrl . '</span><br>';
}
curl_close($oCurl);
}
} else {
$sMessage .= '<span style="color: red;">Keine Daten vorhanden!</span>';
}
} else {
$sMessage .= '<span style="color: red;">Authentifizierung fehlgeschlagen!</span>';
}
echo '<pre>'.$sMessage.'</pre>';
exit;
}
/**
* Returens urls from sitemap
*
* @return array urls
*/
protected function _getSitemapContent($sSitemapUrl = "")
{
$aUrls = array();
if(empty($sSitemapUrl)) {
$sSitemapUrl = $this->_getSitemapUrl();
}
$sUsername = oxRegistry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = oxRegistry::getConfig()->getShopConfVar('psCacheWarmerPass');
$sSitemapUrl = str_replace("://", "://".$sUsername.":".$sPassword."@", $sSitemapUrl);
$sSitemapXmlData = @file_get_contents($sSitemapUrl);
if($oSitemap = @simplexml_load_string($sSitemapXmlData)) {
if (count($oSitemap->sitemap) > 0) {
foreach ($oSitemap->sitemap as $oSubSitemap) {
$sNextSitemapUrl = (string)$oSubSitemap->loc;
$aUrls = array_merge($aUrls, $this->_getSitemapContent($sNextSitemapUrl));
}
}
if(count($oSitemap->url) > 0) {
foreach($oSitemap->url as $oSitemapUrl) {
$aUrls[] = (string)$oSitemapUrl->loc;
}
}
}
#print_r($aUrls);
return $aUrls;
}
/**
* Returens sitemap url
*
* @return string sitemap url
*/
protected function _getSitemapUrl()
{
$sSitemapUrl = oxRegistry::getConfig()->getConfigParam('sShopURL');
$sSitemapUrl .= oxRegistry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl');
return $sSitemapUrl;
}
/**
* Checks authentification
*
* @return bool true|false
*/
protected function _checkAuthentification()
{
$oConfig = oxRegistry::getConfig();
$sKey = oxRegistry::getConfig()->getRequestParameter("key");
$sSavedKey = $oConfig->getShopConfVar('psCacheWarmerKey', $oConfig->getShopId());
if($sSavedKey == $sKey) {
return true;
}
return false;
}
}

Voir le fichier

@ -0,0 +1,30 @@
<?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) Proud Sourcing GmbH | 2016
* @link www.proudcommerce.com
* @package psCacheWarmer
* @version 1.0.1
**/
$sLangName = "Deutsch";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = array(
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_psCacheWarmerConfig' => 'Einstellungen',
'SHOP_MODULE_psCacheWarmerSitemapUrl' => 'XML-Sitemap URL',
'SHOP_MODULE_psCacheWarmerKey' => 'Cronjob-Key',
'SHOP_MODULE_psCacheWarmerUser' => 'Basic-Auth Benutzer',
'SHOP_MODULE_psCacheWarmerPass' => 'Basic-Auth Kennwort',
);
/*
[{ oxmultilang ident="GENERAL_YOUWANTTODELETE" }]
*/

Voir le fichier

Avant

Largeur:  |  Hauteur:  |  Taille: 13 KiB

Après

Largeur:  |  Hauteur:  |  Taille: 13 KiB

Voir le fichier

@ -0,0 +1,71 @@
<?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) Proud Sourcing GmbH | 2016
* @link www.proudcommerce.com
* @package psCacheWarmer
* @version 1.0.1
**/
/**
* Metadata version
*/
$sMetadataVersion = '1.1';
/**
* Module information
*/
$aModule = array(
'id' => 'psCacheWarmer',
'title' => 'psCacheWarmer',
'description' => array(
'de' => 'Website anhand der XML-Sitemap automatisch aufrufen, z. B. zum "Aufwärmen" eines Caches.<br>
<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>',
'en' => 'Automatically calling urls using the xml-sitemap, eg. for cache warming.
<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' => '1.0.1',
'author' => 'Proud Sourcing GmbH',
'url' => 'http://www.proudcommerce.com/',
'email' => 'support@proudcommerce.com',
'extend' => array(
),
'files' => array(
'pscachewarmer' => 'proudsourcing/psCacheWarmer/application/controllers/pscachewarmer.php',
),
'templates' => array(
),
'blocks' => array(
),
'settings' => array(
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerSitemapUrl',
'type' => 'str',
'value' => 'sitemap.xml',
),
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerKey',
'type' => 'str',
'value' => md5(time()),
),
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerUser',
'type' => 'str',
'value' => '',
),
array(
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerPass',
'type' => 'str',
'value' => '',
),
),
);

Voir le fichier

@ -0,0 +1,30 @@
<?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) Proud Sourcing GmbH | 2016
* @link www.proudcommerce.com
* @package psCacheWarmer
* @version 1.0.1
**/
$sLangName = "Deutsch";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = array(
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_psCacheWarmerConfig' => 'Einstellungen',
'SHOP_MODULE_psCacheWarmerSitemapUrl' => 'XML-Sitemap URL',
'SHOP_MODULE_psCacheWarmerKey' => 'Cronjob-Key',
'SHOP_MODULE_psCacheWarmerUser' => 'Basic-Auth Benutzer',
'SHOP_MODULE_psCacheWarmerPass' => 'Basic-Auth Kennwort',
);
/*
[{ oxmultilang ident="GENERAL_YOUWANTTODELETE" }]
*/

Voir le fichier

@ -0,0 +1,6 @@
<?php
/**
* Metadata version
*/
$sVendorMetadataVersion = '1.0';

Voir le fichier

@ -1,86 +0,0 @@
<?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.1
**/
/**
* Metadata version
*/
$sMetadataVersion = '2.0';
/**
* Module information
*/
$aModule = [
'id' => 'psCacheWarmer',
'title' => 'psCacheWarmer',
'description' => [
'de' => 'Website anhand der XML-Sitemap automatisch aufrufen, z. B. zum "Aufwärmen" eines Caches.',
'en' => 'Automatically calling urls using the xml-sitemap, eg. for cache warmup.',
],
'thumbnail' => 'logo_pc-os.jpg',
'version' => '3.1.2',
'author' => 'ProudCommerce',
'url' => 'https://github.com/proudcommerce/psCacheWarmer',
'email' => '',
'extend' => [
],
'controllers' => [
],
'templates' => [
],
'blocks' => [
],
'settings' => [
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerSitemapUrl',
'type' => 'str',
'value' => 'sitemap.xml',
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerKey',
'type' => 'str',
'value' => md5(time()),
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerUser',
'type' => 'str',
'value' => '',
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerPass',
'type' => 'str',
'value' => '',
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerHttpCodes',
'type' => 'arr',
'value' => [200, 302],
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerWriteCsv',
'type' => 'bool',
'value' => false,
],
[
'group' => 'psCacheWarmerConfig',
'name' => 'psCacheWarmerWriteCsvOnlyError',
'type' => 'bool',
'value' => true,
]
],
];