From d2497c9c7c3d6fa208f36e42cc8e93f734b7cd7f Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Mon, 7 Jun 2021 14:36:57 +0000 Subject: [PATCH] if email couldn't sended make warning not error and transmit to login-server --- .../Controller/JsonRequestHandlerController.php | 4 ++++ .../src/Model/Transactions/Transaction.php | 13 ++++++++++--- .../src/Model/Transactions/TransactionBase.php | 16 +++++++++++++++- .../Model/Transactions/TransactionCreation.php | 1 + .../Model/Transactions/TransactionTransfer.php | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/community_server/src/Controller/JsonRequestHandlerController.php b/community_server/src/Controller/JsonRequestHandlerController.php index 12e03be8d..c1f7e4701 100644 --- a/community_server/src/Controller/JsonRequestHandlerController.php +++ b/community_server/src/Controller/JsonRequestHandlerController.php @@ -387,6 +387,10 @@ class JsonRequestHandlerController extends AppController { //echo "after validate
"; if ($transaction->save()) { + $result = ['state' => 'success']; + if($transaction->hasWarnings()) { + $result['warnings'] = $transaction->getWarnings(); + } // success return $this->returnJson(['state' => 'success']); } else { diff --git a/community_server/src/Model/Transactions/Transaction.php b/community_server/src/Model/Transactions/Transaction.php index 40be13cd3..810f20c9d 100644 --- a/community_server/src/Model/Transactions/Transaction.php +++ b/community_server/src/Model/Transactions/Transaction.php @@ -25,7 +25,7 @@ class Transaction extends TransactionBase { //$transactionBin = base64_decode($base64Data, true); //if($transactionBin == false) { //sodium_base64_VARIANT_URLSAFE_NO_PADDING - if(is_a($base64Data, '\Proto\Gradido\Transaction')) { + if(is_a($base64Data, '\Proto\Gradido\GradidoTransaction')) { $this->mProtoTransaction = $base64Data; $this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes()); return; @@ -93,7 +93,11 @@ class Transaction extends TransactionBase { return $this->mTransactionBody; } - public function getFirstPublic() { + public function getFirstPublic() + { + if(!$this->mProtoTransaction || !$this->mProtoTransaction->getSigMap()) { + return ''; + } $sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair(); return $sigPairs[0]->getPubKey(); } @@ -111,6 +115,7 @@ class Transaction extends TransactionBase { $sigMap = $this->mProtoTransaction->getSigMap(); if(!$sigMap) { $this->addError('Transaction', 'signature map is zero'); + //var_dump($this->mProtoTransaction); return false; } //var_dump($sigMap); @@ -193,8 +198,10 @@ class Transaction extends TransactionBase { $connection->commit(); - $this->mTransactionBody->getSpecificTransaction()->sendNotificationEmail($this->mTransactionBody->getMemo()); + $specificTransaction = $this->mTransactionBody->getSpecificTransaction(); + $specificTransaction->sendNotificationEmail($this->mTransactionBody->getMemo()); + $this->addWarnings($specificTransaction->getWarnings()); return true; } diff --git a/community_server/src/Model/Transactions/TransactionBase.php b/community_server/src/Model/Transactions/TransactionBase.php index 607903d8d..e106b8ac2 100644 --- a/community_server/src/Model/Transactions/TransactionBase.php +++ b/community_server/src/Model/Transactions/TransactionBase.php @@ -6,24 +6,38 @@ use Cake\ORM\TableRegistry; class TransactionBase { private $errors = []; + private $warnings = []; static $tables = []; public function getErrors() { return $this->errors; } - + + public function getWarnings() { + return $this->warnings; + } public function addError($functionName, $errorName) { array_push($this->errors, [$functionName => $errorName]); } + public function addWarning($functionName, $warningName) { + $this->warnings[] = [$functionName => $warningName]; + } public function addErrors($errors) { $this->errors = array_merge($this->errors, $errors); } + + public function addWarnings($warnings) { + $this->warnings = array_merge($this->warnings, $warnings); + } public function hasErrors() { return count($this->errors) > 0; } + public function hasWarnings() { + return count($this->warnings) > 0; + } public static function getTable($tableName) { if(!isset(self::$tables[$tableName])) { self::$tables[$tableName] = TableRegistry::getTableLocator()->get($tableName); diff --git a/community_server/src/Model/Transactions/TransactionCreation.php b/community_server/src/Model/Transactions/TransactionCreation.php index f9b3c7657..9150d24eb 100644 --- a/community_server/src/Model/Transactions/TransactionCreation.php +++ b/community_server/src/Model/Transactions/TransactionCreation.php @@ -209,6 +209,7 @@ class TransactionCreation extends TransactionBase { ->send(); } catch(Exception $e) { // $this->addError('TransactionCreation::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); + $this->addWarning('TransactionCreation::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); return false; } return true; diff --git a/community_server/src/Model/Transactions/TransactionTransfer.php b/community_server/src/Model/Transactions/TransactionTransfer.php index 12d2878fc..be4f45b88 100644 --- a/community_server/src/Model/Transactions/TransactionTransfer.php +++ b/community_server/src/Model/Transactions/TransactionTransfer.php @@ -211,6 +211,7 @@ class TransactionTransfer extends TransactionBase { ->send(); } catch(Exception $e) { //$this->addError('TransactionTransfer::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); + $this->addWarning('TransactionTransfer::sendNotificationEmail', 'error sending notification email: ' . $e->getMessage()); return false; } return true;