InventoryTransaction::execute() now throws exceptions instead of returning true/false

This commit is contained in:
Dylan K. Taylor
2020-07-01 14:08:28 +01:00
parent 30591d047c
commit cf5e31c619
5 changed files with 83 additions and 26 deletions

View File

@ -269,12 +269,6 @@ class InventoryTransaction{
}
}
protected function sendInventories() : void{
foreach($this->inventories as $inventory){
$this->source->getNetworkSession()->getInvManager()->syncContents($inventory);
}
}
protected function callExecuteEvent() : bool{
$ev = new InventoryTransactionEvent($this);
$ev->call();
@ -284,32 +278,24 @@ class InventoryTransaction{
/**
* Executes the group of actions, returning whether the transaction executed successfully or not.
*
* @throws TransactionValidationException
* @throws TransactionException
*/
public function execute() : bool{
public function execute() : void{
if($this->hasExecuted()){
$this->sendInventories();
return false;
throw new TransactionValidationException("Transaction has already been executed");
}
$this->shuffleActions();
try{
$this->validate();
}catch(TransactionValidationException $e){
$this->sendInventories();
throw $e;
}
$this->validate();
if(!$this->callExecuteEvent()){
$this->sendInventories();
return false;
throw new TransactionCancelledException("Transaction event cancelled");
}
foreach($this->actions as $action){
if(!$action->onPreExecute($this->source)){
$this->sendInventories();
return false;
throw new TransactionCancelledException("One of the actions in this transaction was cancelled");
}
}
@ -318,8 +304,6 @@ class InventoryTransaction{
}
$this->hasExecuted = true;
return true;
}
public function hasExecuted() : bool{