change component registration to dynamic, module can disabled without errors

This commit is contained in:
Daniel Seifert 2015-12-24 11:51:39 +00:00
parent 6bcc9d5b97
commit bf3865f089
6 changed files with 541 additions and 461 deletions

1
.gitattributes vendored
View File

@ -11,6 +11,7 @@ copy_this/modules/d3/d3geoip/controllers/admin/d3_country_geoip.php -text
copy_this/modules/d3/d3geoip/menu.xml -text copy_this/modules/d3/d3geoip/menu.xml -text
copy_this/modules/d3/d3geoip/metadata.php -text copy_this/modules/d3/d3geoip/metadata.php -text
copy_this/modules/d3/d3geoip/models/d3geoip.php -text copy_this/modules/d3/d3geoip/models/d3geoip.php -text
copy_this/modules/d3/d3geoip/modules/controllers/d3_oxshopcontrol_geoip.php -text
copy_this/modules/d3/d3geoip/picture.png -text copy_this/modules/d3/d3geoip/picture.png -text
copy_this/modules/d3/d3geoip/setup/d3geoip_update.php -text copy_this/modules/d3/d3geoip/setup/d3geoip_update.php -text
copy_this/modules/d3/d3geoip/views/admin/de/d3_geoip_lang.php -text copy_this/modules/d3/d3geoip/views/admin/de/d3_geoip_lang.php -text

View File

@ -1 +1 @@
copyAsIsFiles = modules/d3/d3geoip/components, modules/d3/d3geoip/controllers, modules/d3/d3geoip/models/d3geoip_update.php, modules/d3/d3geoip/views, modules/d3/d3geoip/IntelliSenseHelper.php, modules/d3/d3geoip/metadata.php copyAsIsFiles = modules/d3/d3geoip/components, modules/d3/d3geoip/controllers, modules/d3/d3geoip/models/d3geoip_update.php, modules/d3/d3geoip/modules/controllers, modules/d3/d3geoip/views, modules/d3/d3geoip/IntelliSenseHelper.php, modules/d3/d3geoip/metadata.php

View File

@ -19,7 +19,9 @@ $aModule = array(
'author' => 'D³ Data Development (Inh.: Thomas Dartsch)', 'author' => 'D³ Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com', 'email' => 'support@shopmodule.com',
'url' => 'http://www.oxidmodule.com/', 'url' => 'http://www.oxidmodule.com/',
'extend' => array(), 'extend' => array(
'oxshopcontrol' => 'd3/d3geoip/modules/controllers/d3_oxshopcontrol_geoip',
),
'files' => array( 'files' => array(
'd3cmp_geoip' => 'd3/d3geoip/components/d3cmp_geoip.php', 'd3cmp_geoip' => 'd3/d3geoip/components/d3cmp_geoip.php',
'd3_cfg_geoipset' => 'd3/d3geoip/controllers/admin/d3_cfg_geoipset.php', 'd3_cfg_geoipset' => 'd3/d3geoip/controllers/admin/d3_cfg_geoipset.php',

View File

@ -0,0 +1,58 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
class d3_oxshopcontrol_geoip extends d3_oxshopcontrol_geoip_parent
{
/**
* @param null $sClass
* @param null $sFunction
* @param null $aParams
* @param null $aViewsChain
* @return null
*/
public function start ($sClass = null, $sFunction = null, $aParams = null, $aViewsChain = null)
{
$this->_d3AddGeoIpComponent();
parent::start($sClass, $sFunction, $aParams, $aViewsChain);
}
/**
* check, if developer mode has to be enabled
*
* @return bool
*/
protected function _d3AddGeoIpComponent()
{
startProfile(__METHOD__);
$aUserComponentNames = oxRegistry::getConfig()->getConfigParam('aUserComponentNames');
$sGeoIpCmpName = 'd3cmp_geoip';
$blDontUseCache = 1;
if (false == is_array($aUserComponentNames)) {
$aUserComponentNames = array();
}
if (false == in_array($sGeoIpCmpName, array_keys($aUserComponentNames))) {
$aUserComponentNames[$sGeoIpCmpName] = $blDontUseCache;
oxRegistry::getConfig()->setConfigParam('aUserComponentNames', $aUserComponentNames);
}
stopProfile(__METHOD__);
}
}

View File

@ -43,7 +43,7 @@ FE9';
array('check' => 'hasUnregisteredFiles', array('check' => 'hasUnregisteredFiles',
'do' => 'showUnregisteredFiles'), 'do' => 'showUnregisteredFiles'),
array('check' => 'checkRegisteredComponent', array('check' => 'checkRegisteredComponent',
'do' => 'registerComponent'), 'do' => 'unregisterComponent'),
array('check' => 'checkModCfgSameRevision', array('check' => 'checkModCfgSameRevision',
'do' => 'updateModCfgSameRevision'), 'do' => 'updateModCfgSameRevision'),
); );
@ -413,15 +413,12 @@ FE9';
*/ */
public function checkRegisteredComponent() public function checkRegisteredComponent()
{ {
$sVarName = 'aUserComponentNames';
$sModuleId = '';
/** @var $oShop oxshop */ /** @var $oShop oxshop */
foreach ($this->getShopListByActiveModule('d3geoip') as $oShop) { foreach ($this->getShopListByActiveModule('d3geoip') as $oShop) {
/** @var array $aUserComponents */ $aUserComponents = $this->_d3GetUserComponentsFromDb($oShop);
$aUserComponents = oxRegistry::getConfig()->getShopConfVar($sVarName, $oShop->getId(), $sModuleId);
if (false == $aUserComponents if (is_array($aUserComponents)
|| false == $aUserComponents['d3cmp_geoip'] && in_array('d3cmp_geoip', array_keys($aUserComponents))
) { ) {
return true; return true;
} }
@ -433,26 +430,48 @@ FE9';
/** /**
* @return bool * @return bool
*/ */
public function registerComponent() public function unregisterComponent()
{ {
$blRet = true; $blRet = true;
$sVarName = 'aUserComponentNames'; $sVarName = 'aUserComponentNames';
$sModuleId = '';
/** @var $oShop oxshop */ /** @var $oShop oxshop */
foreach ($this->getShopList() as $oShop) { foreach ($this->getShopList() as $oShop) {
$aUserComponents = oxRegistry::getConfig()->getShopConfVar($sVarName, $oShop->getId(), $sModuleId); $aUserComponents = $this->_d3GetUserComponentsFromDb($oShop);
if (false == $aUserComponents) {
$aUserComponents = array();
}
if (false == $aUserComponents['d3cmp_geoip']) { if (is_array($aUserComponents)
$blDontUseCache = 1; && in_array('d3cmp_geoip', array_keys($aUserComponents))
$aUserComponents['d3cmp_geoip'] = $blDontUseCache; ) {
unset($aUserComponents['d3cmp_geoip']);
if (false == count($aUserComponents)) {
$aUserComponents = null;
}
$this->fixOxconfigVariable($sVarName, $oShop->getId(), '', $aUserComponents, 'arr'); $this->fixOxconfigVariable($sVarName, $oShop->getId(), '', $aUserComponents, 'arr');
} }
} }
return $blRet; return $blRet;
} }
/**
* @param oxShop $oShop
* @return array|null
*/
protected function _d3GetUserComponentsFromDb(oxShop $oShop)
{
$sVarName = 'aUserComponentNames';
$sModuleId = '';
$oDb = oxDb::getDb(oxDb::FETCH_MODE_ASSOC);
$sSelect = "SELECT oxvartype as type, ".oxRegistry::getConfig()->getDecodeValueQuery().
" as value FROM `oxconfig` WHERE oxshopid = ".$oDb->quote($oShop->getId()).
" AND oxvarname = ".$oDb->quote($sVarName).
" AND oxmodule = ".$oDb->quote($sModuleId);
$aResult = $oDb->getAll($sSelect);
$aUserComponents = is_array($aResult) && count($aResult)
? oxRegistry::getConfig()->decodeValue($aResult[0]['type'], $aResult[0]['value'])
: null;
return $aUserComponents;
}
} }