| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Clamps and persists the admin table rows-per-page preference. |
| 9 |
* |
| 10 |
* Shared by the admin action facade and AJAX pagination paths so every caller |
| 11 |
* applies the same min/max bounds before writing the options row. |
| 12 |
*/ |
| 13 |
class ABJ_404_Solution_PerPageOptionUpdater { |
| 14 |
|
| 15 |
/** |
| 16 |
* @param int $rows Requested number of rows per page. |
| 17 |
* @return void |
| 18 |
*/ |
| 19 |
public function update(int $rows): void { |
| 20 |
$tracer = ABJ_404_Solution_OptionPersistenceTracer::begin(); |
| 21 |
try { |
| 22 |
$normalization = static function () use ($rows): int { |
| 23 |
$showRows = max($rows, ABJ404_OPTION_MIN_PERPAGE); |
| 24 |
return min($showRows, ABJ404_OPTION_MAX_PERPAGE); |
| 25 |
}; |
| 26 |
$showRows = $tracer === null |
| 27 |
? $normalization() |
| 28 |
: $tracer->traceOperation('rows_per_page_normalization', $normalization); |
| 29 |
|
| 30 |
$optionsRead = static function () { |
| 31 |
$repository = abj_service('options_repository'); |
| 32 |
return array($repository, $repository->getOptions()); |
| 33 |
}; |
| 34 |
$resolved = $tracer === null |
| 35 |
? $optionsRead() |
| 36 |
: $tracer->traceOperation('options_read', $optionsRead); |
| 37 |
$repository = $resolved[0]; |
| 38 |
$options = $resolved[1]; |
| 39 |
$options['perpage'] = $showRows; |
| 40 |
$repository->updateOptions($options); |
| 41 |
} finally { |
| 42 |
if ($tracer !== null) { |
| 43 |
$tracer->finish(); |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|