Files
laravel-manager-packagist/src/Console/CostsPriceCommand.php
T
2026-12-06 12:23:34 +00:00

38 lines
1.5 KiB
PHP

<?php
namespace IriksIT\Manager\Console;
use Illuminate\Console\Command;
use IriksIT\Manager\Support\Costs\Ledger;
/**
* Prices the rows of the site's TOKENS.md that have no kept price yet and keeps the answer. Run after a deploy, so a release is priced once
* and the owner's screen never has to wait for a price source.
*/
class CostsPriceCommand extends Command
{
protected $signature = 'manager:costs-price {--retry : Ask again for rows the price source could not or would not price}';
protected $description = 'Ask the price source once what the rows of TOKENS.md cost that have no kept price yet, and keep the answer';
public function handle(Ledger $ledger): int
{
if ($this->option('retry')) {
$ledger->retry();
}
$items = $ledger->items(true);
$kept = count(array_filter($items, fn (array $item) => $item['priced_by'] === 'service'));
$fixed = count(array_filter($items, fn (array $item) => $item['priced_by'] === 'config'));
$open = count(array_filter($items, fn (array $item) => $item['tokens'] > 0 && $item['priced_by'] === null));
$this->info(count($items)." rows: {$kept} with a kept price, {$fixed} priced with the fixed rates, {$open} without a price.");
if ($open > 0) {
$this->line('Rows without a price are not asked again for an hour (or until --retry) when the price source could not answer, and never when it answered without one.');
}
return self::SUCCESS;
}
}