From 90dd39f7817bfeb298defaee9ac33e63b5e4856d Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 24 Jan 2025 12:00:45 +0700 Subject: [PATCH] Remove `TransactionalTrait` --- src/Trait/TransactionalTrait.php | 100 ------------------------------- src/TransactionalInterface.php | 77 ------------------------ 2 files changed, 177 deletions(-) delete mode 100644 src/Trait/TransactionalTrait.php delete mode 100644 src/TransactionalInterface.php diff --git a/src/Trait/TransactionalTrait.php b/src/Trait/TransactionalTrait.php deleted file mode 100644 index 828cb4548..000000000 --- a/src/Trait/TransactionalTrait.php +++ /dev/null @@ -1,100 +0,0 @@ -isTransactional(TransactionalInterface::OP_DELETE)) { - return $this->deleteInternal(); - } - - $transaction = $this->db()->beginTransaction(); - - try { - $result = $this->deleteInternal(); - $transaction->commit(); - - return $result; - } catch (Throwable $e) { - $transaction->rollBack(); - throw $e; - } - } - - public function insert(array|null $propertyNames = null): bool - { - if (!$this->isTransactional(TransactionalInterface::OP_INSERT)) { - return $this->insertInternal($propertyNames); - } - - $transaction = $this->db()->beginTransaction(); - - try { - $result = $this->insertInternal($propertyNames); - if ($result === false) { - $transaction->rollBack(); - } else { - $transaction->commit(); - } - - return $result; - } catch (Throwable $e) { - $transaction->rollBack(); - throw $e; - } - } - - public function isTransactional(int $operation): bool - { - return in_array($operation, $this->transactions(), true); - } - - public function transactions(): array - { - return [ - TransactionalInterface::OP_INSERT, - TransactionalInterface::OP_UPDATE, - TransactionalInterface::OP_DELETE, - ]; - } - - public function update(array|null $propertyNames = null): int - { - if (!$this->isTransactional(TransactionalInterface::OP_UPDATE)) { - return $this->updateInternal($propertyNames); - } - - $transaction = $this->db()->beginTransaction(); - - try { - $result = $this->updateInternal($propertyNames); - if ($result === 0) { - $transaction->rollBack(); - } else { - $transaction->commit(); - } - - return $result; - } catch (Throwable $e) { - $transaction->rollBack(); - throw $e; - } - } -} diff --git a/src/TransactionalInterface.php b/src/TransactionalInterface.php deleted file mode 100644 index c779e988e..000000000 --- a/src/TransactionalInterface.php +++ /dev/null @@ -1,77 +0,0 @@ - self::OP_INSERT, - * 'api' => self::OP_INSERT | self::OP_UPDATE | self::OP_DELETE, - * // the above is equivalent to the following: - * // 'api' => self::OP_ALL, - * - * ]; - * ``` - * - * The above declaration specifies that in the "admin" scenario, the insert operation ({@see insert()}) should be - * done in a transaction; and in the "api" scenario, all the operations should be done in a transaction. - * - * @return array The declarations of transactional operations. The array keys are scenario names, and the array - * values are the corresponding transaction operations. - */ - public function transactions(): array; -}