fixed missing features
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions\Tickets;
|
||||
|
||||
use App\Enums\TicketWorklogEntryType;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketFieldDefinition;
|
||||
use App\Models\TicketFieldValue;
|
||||
@@ -13,6 +14,7 @@ class UpdateProjectTicket
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CreateTicketWorklogEntry $createTicketWorklogEntry,
|
||||
private readonly SyncProjectTicketFieldValues $syncProjectTicketFieldValues,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -179,36 +181,19 @@ class UpdateProjectTicket
|
||||
$ticket->save();
|
||||
}
|
||||
|
||||
foreach ($fieldValueAttributes as $fieldValueAttribute) {
|
||||
$fieldDefinition = $fieldDefinitions->get((int) $fieldValueAttribute['ticket_field_definition_id']);
|
||||
$fieldValueChangeSet = $this->syncProjectTicketFieldValues->handle(
|
||||
$ticket,
|
||||
$fieldDefinitions,
|
||||
$existingFieldValues,
|
||||
$fieldValueAttributes,
|
||||
);
|
||||
|
||||
if ($fieldDefinition === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existingFieldValue = $existingFieldValues->get($fieldDefinition->id);
|
||||
|
||||
if ($fieldDefinition->field_type === 'user') {
|
||||
$this->syncUserFieldValue(
|
||||
$changes,
|
||||
$existingFieldValue,
|
||||
$fieldDefinition,
|
||||
$fieldValueAttribute,
|
||||
$summaryLabels,
|
||||
$ticket,
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->syncNumberFieldValue(
|
||||
$changes,
|
||||
$existingFieldValue,
|
||||
$fieldDefinition,
|
||||
$fieldValueAttribute,
|
||||
$summaryLabels,
|
||||
$ticket,
|
||||
);
|
||||
if ($fieldValueChangeSet['changes'] !== []) {
|
||||
$changes['field_values'] = $fieldValueChangeSet['changes'];
|
||||
$summaryLabels = [
|
||||
...$summaryLabels,
|
||||
...$fieldValueChangeSet['summary_labels'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($summaryLabels === []) {
|
||||
@@ -218,7 +203,7 @@ class UpdateProjectTicket
|
||||
$this->createTicketWorklogEntry->handle(
|
||||
$ticket->fresh(),
|
||||
$actor,
|
||||
'updated',
|
||||
TicketWorklogEntryType::Updated,
|
||||
$this->buildSummary($summaryLabels),
|
||||
$changes,
|
||||
);
|
||||
@@ -273,98 +258,6 @@ class UpdateProjectTicket
|
||||
$summaryLabels[] = $summaryLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $changes
|
||||
* @param array{value_user_id?: int|string|null} $fieldValueAttribute
|
||||
* @param array<int, string> $summaryLabels
|
||||
*/
|
||||
private function syncUserFieldValue(
|
||||
array &$changes,
|
||||
?TicketFieldValue $existingFieldValue,
|
||||
TicketFieldDefinition $fieldDefinition,
|
||||
array $fieldValueAttribute,
|
||||
array &$summaryLabels,
|
||||
Ticket $ticket,
|
||||
): void {
|
||||
$newUserId = $fieldValueAttribute['value_user_id'] ?? null;
|
||||
$newUserId = $newUserId === null || $newUserId === '' ? null : (int) $newUserId;
|
||||
|
||||
if ($existingFieldValue?->value_user_id === $newUserId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$oldUserName = $existingFieldValue?->userValue?->name;
|
||||
$newUserName = $newUserId === null ? null : User::query()->find($newUserId)?->name;
|
||||
|
||||
$changes['field_values'][$fieldDefinition->id] = [
|
||||
'field' => $fieldDefinition->label,
|
||||
'from' => $oldUserName,
|
||||
'to' => $newUserName,
|
||||
];
|
||||
$summaryLabels[] = "{$fieldDefinition->label} field";
|
||||
|
||||
if ($newUserId === null) {
|
||||
$existingFieldValue?->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket->fieldValues()->updateOrCreate(
|
||||
[
|
||||
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||
],
|
||||
[
|
||||
'value_number' => null,
|
||||
'value_user_id' => $newUserId,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $changes
|
||||
* @param array{value_number?: float|int|string|null} $fieldValueAttribute
|
||||
* @param array<int, string> $summaryLabels
|
||||
*/
|
||||
private function syncNumberFieldValue(
|
||||
array &$changes,
|
||||
?TicketFieldValue $existingFieldValue,
|
||||
TicketFieldDefinition $fieldDefinition,
|
||||
array $fieldValueAttribute,
|
||||
array &$summaryLabels,
|
||||
Ticket $ticket,
|
||||
): void {
|
||||
$newNumber = $fieldValueAttribute['value_number'] ?? null;
|
||||
$newNumber = $newNumber === null || $newNumber === '' ? null : (float) $newNumber;
|
||||
$oldNumber = $existingFieldValue?->value_number;
|
||||
|
||||
if ($oldNumber === $newNumber) {
|
||||
return;
|
||||
}
|
||||
|
||||
$changes['field_values'][$fieldDefinition->id] = [
|
||||
'field' => $fieldDefinition->label,
|
||||
'from' => $this->formatNumber($oldNumber),
|
||||
'to' => $this->formatNumber($newNumber),
|
||||
];
|
||||
$summaryLabels[] = "{$fieldDefinition->label} field";
|
||||
|
||||
if ($newNumber === null) {
|
||||
$existingFieldValue?->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket->fieldValues()->updateOrCreate(
|
||||
[
|
||||
'ticket_field_definition_id' => $fieldDefinition->id,
|
||||
],
|
||||
[
|
||||
'value_number' => $newNumber,
|
||||
'value_user_id' => null,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $summaryLabels
|
||||
*/
|
||||
@@ -386,13 +279,4 @@ class UpdateProjectTicket
|
||||
|
||||
return 'Updated '.$uniqueLabels->implode(', ').', and '.$lastLabel.'.';
|
||||
}
|
||||
|
||||
private function formatNumber(?float $value): ?string
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return rtrim(rtrim(number_format($value, 2, '.', ''), '0'), '.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user