Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- Fixed `Phalcon\Support\Helper\Json\Encode` to prefix the `InvalidArgumentException` message with `"json_encode error: "` for consistency [#16889](https://github.com/phalcon/cphalcon/issues/16889)
- Fixed `Phalcon\Storage\Adapter\Libmemcached`, `Phalcon\Storage\Adapter\Redis` and `Phalcon\Storage\Adapter\Weak` to call `initSerializer()` during construction [#16889](https://github.com/phalcon/cphalcon/issues/16889)
- Fixed `Phalcon\Storage\Adapter\Redis` to initialize `lifetime` from options during construction [#16889](https://github.com/phalcon/cphalcon/issues/16889)
- Fixed `Phalcon\Mvc\Model\Transaction\Manager::commit()` to remove each transaction from the pool after committing so that subsequent `get()` calls return a fresh transaction [#16522](https://github.com/phalcon/cphalcon/issues/16522)
- Fixed `Phalcon\Mvc\Model\Transaction\Manager::collectTransaction()` to keep the correct transactions when rebuilding the list after removal [#16522](https://github.com/phalcon/cphalcon/issues/16522)

### Removed

Expand Down
4 changes: 3 additions & 1 deletion phalcon/Mvc/Model/Transaction/Manager.zep
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class Manager implements ManagerInterface, InjectionAwareInterface
if connection->isUnderTransaction() {
connection->commit();
}

this->collectTransaction(transaction);
}
}

Expand Down Expand Up @@ -350,7 +352,7 @@ class Manager implements ManagerInterface, InjectionAwareInterface

for managedTransaction in this->transactions {
if managedTransaction != transaction {
let newTransactions[] = transaction;
let newTransactions[] = managedTransaction;
} else {
let this->number--;
}
Expand Down
70 changes: 70 additions & 0 deletions tests/database/Mvc/Model/Transaction/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,76 @@ public function testMvcModelTransactionManagerTransactionRemovedOnCommit(): void
);
}

/**
* @author Phalcon Team <team@phalcon.io>
* @since 2026-04-21
*
* @group mysql
* @group pgsql
*/
public function testMvcModelTransactionManagerCommitViaManagerClearsTransaction(): void
{
$tm = $this->container->getShared('transactionManager');

$transaction = $tm->get();

$select = new Select();
$select->setTransaction($transaction);
$select->assign(['sel_name' => 'Test One']);
$select->create();

$this->assertSame(1, $this->getProtectedProperty($tm, 'number'));
$this->assertCount(1, $this->getProtectedProperty($tm, 'transactions'));

$tm->commit();

$this->assertSame(0, $this->getProtectedProperty($tm, 'number'));
$this->assertCount(0, $this->getProtectedProperty($tm, 'transactions'));

$newTransaction = $tm->get();

$this->assertTrue($newTransaction->isValid());
$this->assertNotSame($transaction, $newTransaction);
}

/**
* @author Phalcon Team <team@phalcon.io>
* @since 2026-04-21
*
* @group mysql
* @group pgsql
*/
public function testMvcModelTransactionManagerCommitRollbackCycle(): void
{
$tm = $this->container->getShared('transactionManager');
$countBefore = Select::count();

$transaction = $tm->get();

$select = new Select();
$select->setTransaction($transaction);
$select->assign(['sel_name' => 'Cycle One']);
$select->create();

$tm->commit();

$countAfterCommit = Select::count();
$this->assertSame($countBefore + 1, $countAfterCommit);

$transaction = $tm->get();

$select = new Select();
$select->setTransaction($transaction);
$select->assign(['sel_name' => 'Cycle Two']);
$select->create();

$tm->rollback();

$stmt = self::getConnection()->query('SELECT COUNT(*) FROM ph_select');
$countAfterRollback = (int) $stmt->fetchColumn();
$this->assertSame($countAfterCommit, $countAfterRollback);
}

/**
* @author Phalcon Team <team@phalcon.io>
* @since 2012-08-07
Expand Down
Loading