Skip to content

Commit 9045df3

Browse files
authored
Merge pull request #144 from andrefatchip/OX6-47
OX6-47: Added config validation
2 parents 360df9d + 05ba6f1 commit 9045df3

File tree

5 files changed

+103
-18
lines changed

5 files changed

+103
-18
lines changed

application/controllers/admin/fcpayone_main.php

+72
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class fcpayone_main extends fcpayone_admindetails
6464
*/
6565
protected $_aCountryList = array();
6666

67+
/**
68+
* List of config errors encountered
69+
* @var array
70+
*/
71+
protected $_aConfErrors = null;
72+
6773
/**
6874
* Set of default config strings
6975
*
@@ -309,6 +315,12 @@ public function fcpoGetCountryList()
309315
*/
310316
public function save()
311317
{
318+
$blValid = $this->_fcpoValidateData();
319+
320+
if (!$blValid) {
321+
return;
322+
}
323+
312324
$oConfig = $this->_oFcpoHelper->fcpoGetConfig();
313325
$aConfBools = $this->_oFcpoHelper->fcpoGetRequestParameter("confbools");
314326
$aConfStrs = $this->_oFcpoHelper->fcpoGetRequestParameter("confstrs");
@@ -359,6 +371,66 @@ public function save()
359371
$this->_fcpoLoadConfigs($sOxid);
360372
}
361373

374+
/**
375+
* Returns collected errors
376+
*
377+
* @param void
378+
* @return mixed array|false
379+
*/
380+
public function fcpoGetConfigErrors()
381+
{
382+
if (!is_array($this->_aConfErrors)) {
383+
return false;
384+
}
385+
386+
return $this->_aConfErrors;
387+
}
388+
389+
/**
390+
* Validation of entered configuration values
391+
*
392+
* @param void
393+
* @return bool
394+
*/
395+
protected function _fcpoValidateData()
396+
{
397+
$blValidAccountData = $this->_fcpoValidateAccountData();
398+
399+
$blValid = (
400+
$blValidAccountData
401+
);
402+
403+
return $blValid;
404+
}
405+
406+
/**
407+
* Checks accountdata section on errors
408+
*
409+
* @param void
410+
* @return bool
411+
*/
412+
protected function _fcpoValidateAccountData()
413+
{
414+
return true;
415+
}
416+
417+
/**
418+
* Adding a detected configuration error
419+
*
420+
* @param $sTranslationString
421+
* @return void
422+
*/
423+
protected function _fcpoAddConfigError($sTranslationString)
424+
{
425+
$oLang = $this->_oFcpoHelper->fcpoGetLang();
426+
$sMessage = $oLang->translateString($sTranslationString);
427+
428+
if (!is_array($this->_aConfErrors)) {
429+
$this->_aConfErrors = array();
430+
}
431+
$this->_aConfErrors[] = $sMessage;
432+
}
433+
362434
/**
363435
* Loads list of countries
364436
*

application/views/admin/tpl/fcpayone_main.tpl

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<input type="hidden" name="cl" value="fcpayone_main">
1919
</form>
2020

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

2931
[{oxmultilang ident="FCPO_MODULE_VERSION"}] [{$oView->fcpoGetModuleVersion()}]<br><br>
30-
32+
33+
[{if $oView->fcpoGetConfigErrors()}]
34+
[{foreach from=$oView->fcpoGetConfigErrors() item='sErrorMessage'}]
35+
<div style="padding:4px;background: red;color: white;font-weight: bold;">
36+
[{$sErrorMessage}]
37+
</div>
38+
[{/foreach}]
39+
[{/if}]
3140
<div class="groupExp">
3241
<div>
3342
<a href="#" onclick="_groupExp(this);return false;" class="rc"><b>[{oxmultilang ident="FCPO_CONFIG_GROUP_CONN"}]</b></a>

core/fcpayone_events.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public static function addDatabaseStructure()
550550

551551
self::changeColumnTypeIfWrong('fcpotransactionstatus', 'FCPO_USERID', 'varchar(32)', self::$sQueryChangeToVarchar1);
552552
self::changeColumnTypeIfWrong('fcpotransactionstatus', 'FCPO_TXID', 'varchar(32)', self::$sQueryChangeToVarchar2);
553-
self::changeColumnTypeIfWrong('fcporequestlog', 'FCPO_REFNR', 'varchar(32)', self::$sQueryChangeFcporequestlog);
553+
self::changeColumnTypeIfWrong('fcporequestlog', 'FCPO_REFNR', 'int(11)', self::$sQueryChangeFcporequestlog);
554554
self::changeColumnTypeIfWrong('oxorder', 'FCPOREFNR', 'varchar(32)', self::$sQueryChangeRefNrToVarchar);
555555

556556
self::dropIndexIfExists('fcporefnr', 'FCPO_REFNR');
@@ -642,9 +642,14 @@ public static function insertRowIfNotExists($sTableName, $aKeyValue, $sQuery)
642642
*/
643643
public static function changeColumnTypeIfWrong($sTableName, $sColumnName, $sExpectedType, $sQuery)
644644
{
645-
if (oxDb::getDb()->getOne("SHOW COLUMNS FROM {$sTableName} WHERE FIELD = '{$sColumnName}' AND TYPE = '{$sExpectedType}'")) {
645+
$sCheckQuery = "
646+
SHOW COLUMNS
647+
FROM {$sTableName}
648+
WHERE FIELD = '{$sColumnName}'
649+
AND TYPE = '{$sExpectedType}'
650+
";
651+
if (oxDb::getDb()->getOne($sCheckQuery)) {
646652
oxDb::getDb()->Execute($sQuery);
647-
// echo 'In Tabelle '.$sTableName.' Spalte '.$sColumnName.' auf Typ '.$sExpectedType.' umgestellt.<br>';
648653
return true;
649654
}
650655
return false;

extend/application/models/fcPayOneOrder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,7 @@ protected function _fcpoGetResponseQuery()
11611161
{$sAnd}
11621162
)
11631163
";
1164-
$sPath = getShopBasePath()."/log/andre.log";
1165-
$oFile = fopen($sPath, 'a');
1166-
fwrite($oFile, $sQuery."\n");
1167-
fclose($oFile);
1164+
11681165
return $sQuery;
11691166
}
11701167

tests/unit/fcPayOne/application/controllers/admin/fcpayone_mainTest.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,17 @@ public function test_Save_Coverage()
239239
{
240240
$oTestObject = $this->getMock(
241241
'fcpayone_main', array(
242-
'_fcpoCheckAndAddStoreId',
243-
'_fcpoCheckAndAddCampaign',
244-
'_fcpoCheckAndAddLogos',
245-
'_fcpoInsertStoreIds',
246-
'_fcpoInsertCampaigns',
247-
'_fcpoCheckRequestAmazonPayConfiguration',
248-
'_handlePayPalExpressLogos',
249-
'_fcpoInsertProfiles',
250-
'_fcpoCheckAndAddRatePayProfile',
251-
'_fcpoLoadConfigs',
242+
'_fcpoCheckAndAddStoreId',
243+
'_fcpoCheckAndAddCampaign',
244+
'_fcpoCheckAndAddLogos',
245+
'_fcpoInsertStoreIds',
246+
'_fcpoInsertCampaigns',
247+
'_fcpoCheckRequestAmazonPayConfiguration',
248+
'_handlePayPalExpressLogos',
249+
'_fcpoInsertProfiles',
250+
'_fcpoCheckAndAddRatePayProfile',
251+
'_fcpoLoadConfigs',
252+
'_fcpoValidateData',
252253
)
253254
);
254255
$oTestObject->method('_fcpoCheckAndAddStoreId')->will($this->returnValue(null));
@@ -261,6 +262,7 @@ public function test_Save_Coverage()
261262
$oTestObject->method('_fcpoInsertProfiles')->will($this->returnValue(null));
262263
$oTestObject->method('_fcpoCheckAndAddRatePayProfile')->will($this->returnValue(null));
263264
$oTestObject->method('_fcpoLoadConfigs')->will($this->returnValue(null));
265+
$oTestObject->method('_fcpoValidateData')->will($this->returnValue(true));
264266

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

0 commit comments

Comments
 (0)