Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel Seifert 6e7c2d868e
adjust version informations 2023-06-20 11:16:48 +02:00
Daniel Seifert d47993ef64
use assertions for condition checks 2023-06-20 11:14:11 +02:00
Daniel Seifert 37ec1f8b3c
fix wrong method call 2023-06-20 10:13:42 +02:00
5 changed files with 112 additions and 42 deletions

View File

@ -1,5 +1,9 @@
# Changelog
- 4.1.2.0
- verwendet Assertions für Bedingungsprüfung
- fehlerhaften Methodenaufruf korrigiert
- 4.1.1.0
- Support für OXID 6.5.2
- Logging erweitert

View File

@ -37,7 +37,8 @@
},
"require": {
"oxid-esales/oxideshop-ce": "6.8 - 6.14",
"d3/modcfg": "^6"
"d3/modcfg": "^6",
"beberlei/assert": "^3.3"
},
"autoload": {
"psr-4": {

View File

@ -1,4 +1,5 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
@ -16,6 +17,8 @@
namespace D3\GeoIp\Application\Model;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
use D3\ModCfg\Application\Model\d3str;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
@ -257,14 +260,11 @@ class d3geoip extends BaseModel
$oCountry = $this->getUserLocationCountryObject();
if (!$this->isAdmin()
&& Registry::getUtils()->isSearchEngine() === false
&& Registry::getSession()->getId()
&& Registry::getSession()->getVariable('d3isSetLang') === null
&& $oCountry->getId() && $oCountry->getFieldData('d3geoiplang') > -1
) {
try {
$this->canChangeLanguage( $oCountry );
$language = (int) $oCountry->getFieldData('d3geoiplang');
$this->_getModConfig()->info(
$this->_getModConfig()->d3getLog()->info(
__CLASS__,
__FUNCTION__,
__LINE__,
@ -274,6 +274,9 @@ class d3geoip extends BaseModel
Registry::getLang()->setTplLanguage($language);
Registry::getLang()->setBaseLanguage($language);
Registry::getSession()->setVariable('d3isSetLang', true);
Registry::getLogger()->debug('language set', [$language]);
} catch (InvalidArgumentException $e) {
Registry::getLogger()->debug($e->getMessage(), [$oCountry]);
}
stopProfile(__METHOD__);
@ -301,12 +304,9 @@ class d3geoip extends BaseModel
$oCountry = $this->getUserLocationCountryObject();
if (!$this->isAdmin()
&& Registry::getUtils()->isSearchEngine() === false
&& !Registry::getSession()->getVariable('d3isSetCurr')
&& $oCountry->getId()
&& $oCountry->getFieldData('d3geoipcur') > -1
) {
try {
$this->canChangeCurrency( $oCountry );
$this->_getLog()->log(
d3log::INFO,
__CLASS__,
@ -317,6 +317,8 @@ class d3geoip extends BaseModel
);
Registry::getConfig()->setActShopCurrency((int) $oCountry->getFieldData('d3geoipcur'));
Registry::getSession()->setVariable('d3isSetCurr', true);
} catch (InvalidArgumentException $e) {
Registry::getLogger()->debug($e->getMessage(), [$oCountry]);
}
stopProfile(__METHOD__);
@ -369,19 +371,10 @@ class d3geoip extends BaseModel
$this->_getModConfig()->d3getLog()->info(__CLASS__, __FUNCTION__, __LINE__, 'check allowed shop change');
if (Registry::getRequest()->getRequestEscapedParameter('d3redirect') != 1
&& false == $this->isAdmin()
&& Registry::getUtils()->isSearchEngine() === false
&& $oCountry->getId()
&& Registry::getConfig()->isMall()
&& $iNewShop > -1 &&
(
$iNewShop != Registry::getConfig()->getShopId()
|| strtolower(Registry::getConfig()->getActiveView()->getClassKey()) == 'mallstart'
)
) {
$this->_getModConfig()->d3getLog()->info(__CLASS__, __FUNCTION__, __LINE__, 'prepare shop change to '.$iNewShop);
try {
$this->canChangeShop( $oCountry, $iNewShop );
$this->_getModConfig()->d3getLog()->info(__CLASS__, __FUNCTION__, __LINE__, 'prepare shop change to '.$iNewShop);
$oNewConf = new Config();
$oNewConf->setShopId($iNewShop);
$oNewConf->init();
@ -423,6 +416,8 @@ class d3geoip extends BaseModel
header("Location: ".$sUrl);
exit();
} catch (InvalidArgumentException $e) {
Registry::getLogger()->debug($e->getMessage(), [$oCountry]);
}
stopProfile(__METHOD__);
@ -453,13 +448,9 @@ class d3geoip extends BaseModel
$oCountry = $this->getUserLocationCountryObject();
if ($this->dontSkipUrlRedirect()
&& false == $this->isAdmin()
&& Registry::getUtils()->isSearchEngine() === false
&& $oCountry->getId()
&& $oCountry->getFieldData('d3geoipurl')
&& strlen(trim($oCountry->getFieldData('d3geoipurl'))) > 0
) {
try {
$this->canRedirect( $oCountry );
$sNewUrl = $oCountry->getFieldData('d3geoipurl');
$this->_getLog()->log(
@ -473,6 +464,8 @@ class d3geoip extends BaseModel
header("Location: ".$sNewUrl);
exit();
} catch (InvalidArgumentException $e) {
Registry::getLogger()->debug($e->getMessage(), [$oCountry]);
}
stopProfile(__METHOD__);
@ -540,5 +533,77 @@ class d3geoip extends BaseModel
return $this->oD3Log;
}
/**
* @param Country $oCountry
*
* @throws InvalidArgumentException
*/
protected function canRedirect( Country $oCountry )
{
Assert::that($this->dontSkipUrlRedirect())->true('redirect skip is not provided');
$this->isUserInFrontend();
Assert::that($oCountry->getId())->notBlank('no country loaded');
Assert::that($oCountry->getFieldData( 'd3geoipurl' ))->notBlank('no redirect url set');
}
/**
* @param Country $oCountry
*
* @return bool
*/
/**
* @param Country $oCountry
*
* @throws InvalidArgumentException
*/
protected function canChangeLanguage( Country $oCountry )
{
$this->isUserInFrontend();
Assert::that(Registry::getSession()->getVariable( 'd3isSetLang' ))->null('language already set');
Assert::that($oCountry->getId())->notBlank('no country loaded');
Assert::that($oCountry->getFieldData( 'd3geoiplang' ))->greaterThan(-1, 'no target language set');
}
/**
* @param Country $oCountry
*
* @throws InvalidArgumentException
*/
protected function canChangeCurrency( Country $oCountry )
{
$this->isUserInFrontend();
Assert::that(Registry::getSession()->getVariable( 'd3isSetCurr' ))->null('currency already set');
Assert::that($oCountry->getId())->notBlank('no country loaded');
Assert::that($oCountry->getFieldData( 'd3geoipcur' ))->greaterThan(-1, 'no target currency set');
}
/**
* @param Country $oCountry
* @param $iNewShop
*
* @throws InvalidArgumentException
*/
protected function canChangeShop( Country $oCountry, $iNewShop )
{
Assert::that(Registry::getRequest()->getRequestEscapedParameter( 'd3redirect' ))->notSame('1', 'redirect already performed');
$this->isUserInFrontend();
Assert::that($oCountry->getId())->notBlank('no country loaded');
Assert::that(Registry::getConfig()->isMall())->true('no mall installation');
Assert::that($iNewShop)->greaterThan(-1, 'no target shop id set');
Assert::that(
$iNewShop != Registry::getConfig()->getShopId() ||
strtolower( Registry::getConfig()->getActiveView()->getClassKey() ) == 'mallstart'
)->true('no different shop and no mallstart');
}
/**
* @throws InvalidArgumentException
*/
protected function isUserInFrontend()
{
Assert::that($this->isAdmin())->false('User is in admin');
Assert::that(Registry::getUtils()->isSearchEngine())->false('User is search engine');
}
}

View File

@ -38,15 +38,15 @@ class d3geoip_update extends d3install_updatebase
{
public $sModKey = 'd3_geoip';
public $sModName = 'GeoIP';
public $sModVersion = '4.1.1.0';
public $sModRevision = '4110';
public $sModVersion = '4.1.2.0';
public $sModRevision = '4120';
public $sBaseConf = '--------------------------------------------------------------------------------
61Gv2==Z0Ztc2NYQnJkMEZDYnhyaEFkTUtHRm9OSjUzQnAyTUhZaTRhaDRDNFRRdk1hVlFnRXZYNlJFT
3pwb2F0cTd4T2o1Nmc1KzFuODNqOHdlelZsd2lMa1huNUVIbDRsVlVQMFBXaVRaZXV4eUVnRmpSM3RzV
1c4LzQwK0tJMUV1YlpMUU1wRXIxNGdybVZEdi9lSG1PTlNSZE5zZXhNUy9FUjNaVjNsd2lGQTRzWHB2N
lhTend3akIyZU9QUzNuMmtjVkx4a0tpZHdmaDdwNjIzVVF5OENJKzhZYk84cjZ1TGZKZ0dISkdzTm50d
ld5bWZ2b0VFYWNIT3cxVGVwSEpjRDQvdE92cE5GQ2E2QkR3ZCtnOGQ5czVQakJkTEhITXdDb1BEa2xEc
WJtL0VZdk1OWmFyR216eTQyWHFxOEdxUkk=
4I6v2==YXpDb3ovcGlNbStFUXg1UXBUR0h6aXRiS2hZMHorN3d3Q2ZjTmVWcE8yNy9COFRidHFqL0VhW
WZVS2hvY2JlQ29EcTRoaEJJQjJoVXc5M1B3TmFseXEyUHQrUHEveUtGUFdhVW5wWFc3d2xTNGcyeDE3a
DBHbFBicHR1TWxWMkxZQURFMFNnV05ubllTcGRWdkw1SlJNNmk0OVBBT3Y5N0dRb1drWXJSUStsc1Q5Z
Gh0L09EMnhVYW9FUGNGSG5jcktXSXpVeE10Tm9IT2VmQW1VSFZQWmxaMG0ycHNKeks1cUNCWnI4c1Q3M
1F2U3RMY1FsWHRRTGRRL2kzN1pTaWpKWXBlaXBFYVFTN3lOWnpnZVl5blVhWkxNMnBqT1JQT3M2cnJYT
S9kMERSZUFscmR6VW9iZlZVZjhoYzNUdWo=
--------------------------------------------------------------------------------';
public $sRequirements = '';
public $sBaseValue = '';

View File

@ -30,7 +30,7 @@ $aModule = [
'en' => '',
],
'thumbnail' => 'picture.png',
'version' => '4.1.1.0',
'version' => '4.1.2.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',