Skip to content

Commit

Permalink
Merge pull request #144 from andrefatchip/OX6-47
Browse files Browse the repository at this point in the history
OX6-47: Added config validation
  • Loading branch information
T-Kuchel authored Mar 16, 2020
2 parents 360df9d + 05ba6f1 commit 9045df3
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 18 deletions.
72 changes: 72 additions & 0 deletions application/controllers/admin/fcpayone_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class fcpayone_main extends fcpayone_admindetails
*/
protected $_aCountryList = array();

/**
* List of config errors encountered
* @var array
*/
protected $_aConfErrors = null;

/**
* Set of default config strings
*
Expand Down Expand Up @@ -309,6 +315,12 @@ public function fcpoGetCountryList()
*/
public function save()
{
$blValid = $this->_fcpoValidateData();

if (!$blValid) {
return;
}

$oConfig = $this->_oFcpoHelper->fcpoGetConfig();
$aConfBools = $this->_oFcpoHelper->fcpoGetRequestParameter("confbools");
$aConfStrs = $this->_oFcpoHelper->fcpoGetRequestParameter("confstrs");
Expand Down Expand Up @@ -359,6 +371,66 @@ public function save()
$this->_fcpoLoadConfigs($sOxid);
}

/**
* Returns collected errors
*
* @param void
* @return mixed array|false
*/
public function fcpoGetConfigErrors()
{
if (!is_array($this->_aConfErrors)) {
return false;
}

return $this->_aConfErrors;
}

/**
* Validation of entered configuration values
*
* @param void
* @return bool
*/
protected function _fcpoValidateData()
{
$blValidAccountData = $this->_fcpoValidateAccountData();

$blValid = (
$blValidAccountData
);

return $blValid;
}

/**
* Checks accountdata section on errors
*
* @param void
* @return bool
*/
protected function _fcpoValidateAccountData()
{
return true;
}

/**
* Adding a detected configuration error
*
* @param $sTranslationString
* @return void
*/
protected function _fcpoAddConfigError($sTranslationString)
{
$oLang = $this->_oFcpoHelper->fcpoGetLang();
$sMessage = $oLang->translateString($sTranslationString);

if (!is_array($this->_aConfErrors)) {
$this->_aConfErrors = array();
}
$this->_aConfErrors[] = $sMessage;
}

/**
* Loads list of countries
*
Expand Down
11 changes: 10 additions & 1 deletion application/views/admin/tpl/fcpayone_main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<input type="hidden" name="cl" value="fcpayone_main">
</form>



<form autocomplete="off" name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" enctype="multipart/form-data">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="fcpayone_main">
Expand All @@ -27,7 +29,14 @@
[{oxmultilang ident="FCPO_MAIN_CONFIG_INFOTEXT"}]<br><br>

[{oxmultilang ident="FCPO_MODULE_VERSION"}] [{$oView->fcpoGetModuleVersion()}]<br><br>


[{if $oView->fcpoGetConfigErrors()}]
[{foreach from=$oView->fcpoGetConfigErrors() item='sErrorMessage'}]
<div style="padding:4px;background: red;color: white;font-weight: bold;">
[{$sErrorMessage}]
</div>
[{/foreach}]
[{/if}]
<div class="groupExp">
<div>
<a href="#" onclick="_groupExp(this);return false;" class="rc"><b>[{oxmultilang ident="FCPO_CONFIG_GROUP_CONN"}]</b></a>
Expand Down
11 changes: 8 additions & 3 deletions core/fcpayone_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public static function addDatabaseStructure()

self::changeColumnTypeIfWrong('fcpotransactionstatus', 'FCPO_USERID', 'varchar(32)', self::$sQueryChangeToVarchar1);
self::changeColumnTypeIfWrong('fcpotransactionstatus', 'FCPO_TXID', 'varchar(32)', self::$sQueryChangeToVarchar2);
self::changeColumnTypeIfWrong('fcporequestlog', 'FCPO_REFNR', 'varchar(32)', self::$sQueryChangeFcporequestlog);
self::changeColumnTypeIfWrong('fcporequestlog', 'FCPO_REFNR', 'int(11)', self::$sQueryChangeFcporequestlog);
self::changeColumnTypeIfWrong('oxorder', 'FCPOREFNR', 'varchar(32)', self::$sQueryChangeRefNrToVarchar);

self::dropIndexIfExists('fcporefnr', 'FCPO_REFNR');
Expand Down Expand Up @@ -642,9 +642,14 @@ public static function insertRowIfNotExists($sTableName, $aKeyValue, $sQuery)
*/
public static function changeColumnTypeIfWrong($sTableName, $sColumnName, $sExpectedType, $sQuery)
{
if (oxDb::getDb()->getOne("SHOW COLUMNS FROM {$sTableName} WHERE FIELD = '{$sColumnName}' AND TYPE = '{$sExpectedType}'")) {
$sCheckQuery = "
SHOW COLUMNS
FROM {$sTableName}
WHERE FIELD = '{$sColumnName}'
AND TYPE = '{$sExpectedType}'
";
if (oxDb::getDb()->getOne($sCheckQuery)) {
oxDb::getDb()->Execute($sQuery);
// echo 'In Tabelle '.$sTableName.' Spalte '.$sColumnName.' auf Typ '.$sExpectedType.' umgestellt.<br>';
return true;
}
return false;
Expand Down
5 changes: 1 addition & 4 deletions extend/application/models/fcPayOneOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,7 @@ protected function _fcpoGetResponseQuery()
{$sAnd}
)
";
$sPath = getShopBasePath()."/log/andre.log";
$oFile = fopen($sPath, 'a');
fwrite($oFile, $sQuery."\n");
fclose($oFile);

return $sQuery;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,17 @@ public function test_Save_Coverage()
{
$oTestObject = $this->getMock(
'fcpayone_main', array(
'_fcpoCheckAndAddStoreId',
'_fcpoCheckAndAddCampaign',
'_fcpoCheckAndAddLogos',
'_fcpoInsertStoreIds',
'_fcpoInsertCampaigns',
'_fcpoCheckRequestAmazonPayConfiguration',
'_handlePayPalExpressLogos',
'_fcpoInsertProfiles',
'_fcpoCheckAndAddRatePayProfile',
'_fcpoLoadConfigs',
'_fcpoCheckAndAddStoreId',
'_fcpoCheckAndAddCampaign',
'_fcpoCheckAndAddLogos',
'_fcpoInsertStoreIds',
'_fcpoInsertCampaigns',
'_fcpoCheckRequestAmazonPayConfiguration',
'_handlePayPalExpressLogos',
'_fcpoInsertProfiles',
'_fcpoCheckAndAddRatePayProfile',
'_fcpoLoadConfigs',
'_fcpoValidateData',
)
);
$oTestObject->method('_fcpoCheckAndAddStoreId')->will($this->returnValue(null));
Expand All @@ -261,6 +262,7 @@ public function test_Save_Coverage()
$oTestObject->method('_fcpoInsertProfiles')->will($this->returnValue(null));
$oTestObject->method('_fcpoCheckAndAddRatePayProfile')->will($this->returnValue(null));
$oTestObject->method('_fcpoLoadConfigs')->will($this->returnValue(null));
$oTestObject->method('_fcpoValidateData')->will($this->returnValue(true));

$oMockConfig = $this->getMockBuilder('oxConfig')->disableOriginalConstructor()->getMock();
$oMockConfig->expects($this->any())->method('saveShopConfVar')->will($this->returnValue(true));
Expand Down

0 comments on commit 9045df3

Please sign in to comment.