WarehouseOrderSwapTrait
Swaps the draw priority (`order`) between two warehouses.
The swap is one Api operation api/store/warehouse/swap-order
(WarehouseOrderSwapTrait::swapOrder()): in one DB
transaction it loads and locks (FOR UPDATE) both rows, verifies that order matches what the
admin saw in the list, writes both values and commits; otherwise it rolls back and writes nothing.
IMPORTANT: two separate updateColumns() calls (two HTTP POSTs) would leave the first change in
place when the second fails and would not handle two concurrent moves.
The trait is only orchestration: find the neighbor in the list, send one call, show the message.
It works with raw {id, order} pairs, not entities, so it can be tested in isolation without
DB/DI (WarehouseOrderSwapTest).
Table of Contents
Methods
- flashWarehouseOrderResult() : void
- Result message of the move (`moveSuccess`/`moveFailure`).
- loadWarehouseOrderPairs() : array<int, array{id: int, order: int}>
- Current list of warehouses as `{id, order}` pairs sorted `order ASC, id ASC`.
- swapWarehouseOrder() : void
- Swaps `order` between warehouse `$id` and its neighbor in the priority order. The neighbor is determined from the current list sorted `order ASC, id ASC` (a deterministic tiebreak on equal `order`).
- swapWarehouseOrderPair() : Result
- Atomic swap of `order` of two warehouses = one Api operation call, a single `Result`.
Methods
flashWarehouseOrderResult()
Result message of the move (`moveSuccess`/`moveFailure`).
protected
abstract flashWarehouseOrderResult(bool $success) : void
Parameters
- $success : bool
loadWarehouseOrderPairs()
Current list of warehouses as `{id, order}` pairs sorted `order ASC, id ASC`.
protected
abstract loadWarehouseOrderPairs() : array<int, array{id: int, order: int}>
Return values
array<int, array{id: int, order: int}>swapWarehouseOrder()
Swaps `order` between warehouse `$id` and its neighbor in the priority order. The neighbor is determined from the current list sorted `order ASC, id ASC` (a deterministic tiebreak on equal `order`).
protected
swapWarehouseOrder(int $id, bool $up) : void
Parameters
- $id : int
- $up : bool
swapWarehouseOrderPair()
Atomic swap of `order` of two warehouses = one Api operation call, a single `Result`.
protected
abstract swapWarehouseOrderPair(int $warehouseId, int $currentOrder, int $neighborId, int $neighborOrder) : Result
Expected values are sent for verification on the Api side (race protection).
Parameters
- $warehouseId : int
- $currentOrder : int
- $neighborId : int
- $neighborOrder : int