Files
orderPRO/src/Modules/Printing/PrintApiKeyRepository.php
Jacek Pyziak 02d06298ea feat(19-ui-integration): przycisk Drukuj, bulk print, kolejka wydruku
- Przycisk "Drukuj" w prepare.php i show.php z AJAX + duplikat protection
- Bulk print z listy zamówień (checkboxy + header action)
- Kolejka wydruku w Ustawienia > Drukowanie (filtr statusu, retry)
- POST /api/print/jobs/bulk endpoint (package_ids + order_ids)
- ensureLabel() auto-download przez ShipmentProviderRegistry
- Apaczka carrier_id = nazwa usługi, kolumna Przewoznik
- Tab persistence (localStorage), label file_exists check
- Fix use statement ApaczkaApiClient, redirect po utworzeniu przesyłki
- Phase 17 (receipt duplicate guard) + Phase 18 (print queue backend) docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 21:16:54 +01:00

80 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Printing;
use PDO;
final class PrintApiKeyRepository
{
public function __construct(
private readonly PDO $pdo
) {
}
public function create(string $name, string $keyHash, string $keyPrefix): int
{
$statement = $this->pdo->prepare(
'INSERT INTO print_api_keys (name, key_hash, key_prefix) VALUES (:name, :key_hash, :key_prefix)'
);
$statement->execute([
'name' => $name,
'key_hash' => $keyHash,
'key_prefix' => $keyPrefix,
]);
return (int) $this->pdo->lastInsertId();
}
/**
* @return array<string, mixed>|null
*/
public function findByKeyHash(string $keyHash): ?array
{
$statement = $this->pdo->prepare(
'SELECT * FROM print_api_keys WHERE key_hash = :key_hash LIMIT 1'
);
$statement->execute(['key_hash' => $keyHash]);
$row = $statement->fetch(PDO::FETCH_ASSOC);
return is_array($row) ? $row : null;
}
/**
* @return list<array<string, mixed>>
*/
public function listAll(): array
{
$statement = $this->pdo->query(
'SELECT id, name, key_prefix, is_active, last_used_at, created_at FROM print_api_keys ORDER BY created_at DESC'
);
$rows = $statement !== false ? $statement->fetchAll(PDO::FETCH_ASSOC) : [];
return is_array($rows) ? $rows : [];
}
public function deactivate(int $id): void
{
$statement = $this->pdo->prepare(
'UPDATE print_api_keys SET is_active = 0 WHERE id = :id'
);
$statement->execute(['id' => $id]);
}
public function delete(int $id): void
{
$statement = $this->pdo->prepare(
'DELETE FROM print_api_keys WHERE id = :id'
);
$statement->execute(['id' => $id]);
}
public function updateLastUsed(int $id): void
{
$statement = $this->pdo->prepare(
'UPDATE print_api_keys SET last_used_at = NOW() WHERE id = :id'
);
$statement->execute(['id' => $id]);
}
}