You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Cloud/CloudTemplateStoragePublica...

50 lines
1.8 KiB
PHP

<?php
namespace App\Services\Cloud;
use App\Models\CloudTemplateImportIntent;
/** Continues template business publication after required storage copies exist. */
final class CloudTemplateStoragePublicationConsumer
{
public function finalizeReady(string $intentId): bool
{
if (preg_match('/^[a-f0-9]{32}$/D', $intentId) !== 1) {
throw new CloudError('云模板发布归属标识无效', 422);
}
$connection = (new CloudTemplateImportIntent())->getConnection();
return $connection->transaction(static function () use (
$intentId
): bool {
$intent = CloudTemplateImportIntent::query()
->where('id', $intentId)->lockForUpdate()->first();
if (!$intent instanceof CloudTemplateImportIntent) {
throw new CloudError('云模板发布归属记录不存在', 409);
}
if ((string) $intent->state !== 'source_ready') {
if (in_array((string) $intent->state,
['distributing', 'ready', 'distribution_failed'], true)) {
return false;
}
throw new CloudError(
'云模板发布归属状态不允许最终化',
409
);
}
(new CloudTemplateImportPublication())->finalizeReadyIntent(
(string) $intent->id,
[
'user_id' => (int) $intent->user_id,
'is_admin' => true,
'is_super_admin' => true,
'can_manage' => true,
'session_id' => 'template-storage-publication',
'request_idempotency_key' =>
'template-import-' . (string) $intent->id,
]
);
return true;
}, 3);
}
}