Update besar apk finance
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class TransactionService
|
||||
{
|
||||
private $CI;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
}
|
||||
|
||||
public function run(callable $callback)
|
||||
{
|
||||
$this->CI->db->trans_begin();
|
||||
|
||||
try {
|
||||
$result = $callback();
|
||||
if ($this->CI->db->trans_status() === false) {
|
||||
throw new RuntimeException('Operasi database gagal.');
|
||||
}
|
||||
$this->CI->db->trans_commit();
|
||||
return $result;
|
||||
} catch (Throwable $exception) {
|
||||
$this->CI->db->trans_rollback();
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user