41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Services\ProjectTranslationServiceHash;
|
|
|
|
use App\Dto\Service\ProjectTranslationServiceHash\Hashes;
|
|
use App\Dto\Service\ProjectTranslationServiceHash\HashStatusWaiting;
|
|
use App\Enums\ProjectTranslationServiceHashes\Status;
|
|
use App\Repositories\ProjectTranslationServiceHashRepository;
|
|
|
|
final readonly class CompletionChecker
|
|
{
|
|
public function __construct(
|
|
private ProjectTranslationServiceHashRepository $hashRepository,
|
|
private ProjectTranslationServiceHashCommandHandler $commandHandler,
|
|
) { }
|
|
|
|
public function execute(Hashes $hashesDto): HashStatusWaiting
|
|
{
|
|
$hashes = $this->hashRepository->getHashesByIds($hashesDto->getIds())->all();
|
|
$hashStatusWaiting = new HashStatusWaiting();
|
|
$hashSuccessIds = [];
|
|
foreach ($hashes as $hash) {
|
|
$dataHash = $hashesDto->getHash($hash->id);
|
|
if ($dataHash === null) {
|
|
continue;
|
|
}
|
|
|
|
$isWaiting = false;
|
|
if ($hash->status === Status::Waiting && $hash->hash === $dataHash['hash'] && $hash->field === $dataHash['field']) {
|
|
$isWaiting = true;
|
|
$hashSuccessIds[] = $hash->id;
|
|
}
|
|
$hashStatusWaiting->add($hash['field'], $isWaiting);
|
|
}
|
|
|
|
$this->commandHandler->handleSetStatusById($hashSuccessIds, Status::Success);
|
|
|
|
return $hashStatusWaiting;
|
|
}
|
|
}
|