462 lines
24 KiB
PHP
462 lines
24 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Projects;
|
|
|
|
use App\Actions\Notifications\NormalizeNotificationFilters;
|
|
use App\Models\Project;
|
|
use App\Models\TicketStatus;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class DuplicateProjectConfiguration
|
|
{
|
|
public const COPY_PROJECT_SETTINGS = 'project_settings';
|
|
|
|
public const COPY_BOARD_COLUMNS = 'board_columns';
|
|
|
|
public const COPY_TICKET_STATUSES = 'ticket_statuses';
|
|
|
|
public const COPY_STATUS_TRANSITIONS = 'status_transitions';
|
|
|
|
public const COPY_TICKET_TYPES = 'ticket_types';
|
|
|
|
public const COPY_TICKET_PRIORITIES = 'ticket_priorities';
|
|
|
|
public const COPY_TICKET_FIELDS = 'ticket_fields';
|
|
|
|
public const COPY_TICKET_LINK_TYPES = 'ticket_link_types';
|
|
|
|
public const COPY_REPOSITORY_CONNECTIONS = 'repository_connections';
|
|
|
|
public const COPY_NOTIFICATION_ACTIONS = 'notification_actions';
|
|
|
|
public const COPY_BOARD_WORKFLOW = 'board_workflow';
|
|
|
|
public function __construct(
|
|
private readonly ProjectTemplateOverrideManager $projectTemplateOverrideManager,
|
|
private readonly ProjectConfigurationIdentity $projectConfigurationIdentity,
|
|
) {}
|
|
|
|
/** @return list<string> */
|
|
public static function copyableAreas(): array
|
|
{
|
|
return [
|
|
self::COPY_PROJECT_SETTINGS,
|
|
self::COPY_BOARD_COLUMNS,
|
|
self::COPY_TICKET_STATUSES,
|
|
self::COPY_STATUS_TRANSITIONS,
|
|
self::COPY_TICKET_TYPES,
|
|
self::COPY_TICKET_PRIORITIES,
|
|
self::COPY_TICKET_FIELDS,
|
|
self::COPY_TICKET_LINK_TYPES,
|
|
self::COPY_REPOSITORY_CONNECTIONS,
|
|
self::COPY_NOTIFICATION_ACTIONS,
|
|
];
|
|
}
|
|
|
|
/** @return list<string> */
|
|
public static function acceptedCopyAreas(): array
|
|
{
|
|
return [...self::copyableAreas(), self::COPY_BOARD_WORKFLOW];
|
|
}
|
|
|
|
/** @return list<array{value: string, label: string, description: string}> */
|
|
public static function copyAreaOptions(): array
|
|
{
|
|
return [
|
|
['value' => self::COPY_PROJECT_SETTINGS, 'label' => 'Project settings', 'description' => 'General project preferences like story points and author visibility.'],
|
|
['value' => self::COPY_BOARD_COLUMNS, 'label' => 'Board columns', 'description' => 'Columns and their order on the project board.'],
|
|
['value' => self::COPY_TICKET_STATUSES, 'label' => 'Ticket statuses', 'description' => 'Statuses and their assignment to board columns.'],
|
|
['value' => self::COPY_STATUS_TRANSITIONS, 'label' => 'Status transitions', 'description' => 'Allowed moves between ticket statuses.'],
|
|
['value' => self::COPY_TICKET_TYPES, 'label' => 'Ticket types', 'description' => 'Available ticket types, including parent types.'],
|
|
['value' => self::COPY_TICKET_PRIORITIES, 'label' => 'Ticket priorities', 'description' => 'Available ticket priorities.'],
|
|
['value' => self::COPY_TICKET_FIELDS, 'label' => 'Custom ticket fields', 'description' => 'Custom field definitions without ticket values.'],
|
|
['value' => self::COPY_TICKET_LINK_TYPES, 'label' => 'Ticket link types', 'description' => 'Relationship labels between tickets.'],
|
|
['value' => self::COPY_REPOSITORY_CONNECTIONS, 'label' => 'Repository connections', 'description' => 'Repositories linked to the project.'],
|
|
['value' => self::COPY_NOTIFICATION_ACTIONS, 'label' => 'Notification actions', 'description' => 'Notification rules and delivery settings.'],
|
|
];
|
|
}
|
|
|
|
/** @param list<string> $copyAreas @return list<string> */
|
|
public function normalizeCopyAreas(array $copyAreas): array
|
|
{
|
|
if (in_array(self::COPY_BOARD_WORKFLOW, $copyAreas, true)) {
|
|
$copyAreas = [
|
|
...array_diff($copyAreas, [self::COPY_BOARD_WORKFLOW]),
|
|
self::COPY_BOARD_COLUMNS,
|
|
self::COPY_TICKET_STATUSES,
|
|
self::COPY_STATUS_TRANSITIONS,
|
|
];
|
|
}
|
|
|
|
return array_values(array_intersect(self::copyableAreas(), array_unique($copyAreas)));
|
|
}
|
|
|
|
/** @param array<string, mixed> $configuration @return array<string, mixed> */
|
|
public function normalizeConfiguration(array $configuration): array
|
|
{
|
|
$workflow = $configuration[self::COPY_BOARD_WORKFLOW] ?? null;
|
|
|
|
if (is_array($workflow)) {
|
|
$statuses = $workflow['ticket_statuses'] ?? [];
|
|
$configuration[self::COPY_BOARD_COLUMNS] ??= $workflow['board_columns'] ?? [];
|
|
$configuration[self::COPY_TICKET_STATUSES] ??= array_map(
|
|
static fn (array $status): array => array_diff_key($status, ['allowed_target_indexes' => true]),
|
|
$statuses,
|
|
);
|
|
$configuration[self::COPY_STATUS_TRANSITIONS] ??= array_map(
|
|
static fn (array $status): array => $status['allowed_target_indexes'] ?? [],
|
|
$statuses,
|
|
);
|
|
unset($configuration[self::COPY_BOARD_WORKFLOW]);
|
|
}
|
|
|
|
return $this->projectConfigurationIdentity->normalize($configuration);
|
|
}
|
|
|
|
/** @param list<string> $copyAreas @return array<string, mixed> */
|
|
public function export(Project $sourceProject, array $copyAreas): array
|
|
{
|
|
$selectedAreas = $this->normalizeCopyAreas($copyAreas);
|
|
|
|
if ($selectedAreas === []) {
|
|
return [];
|
|
}
|
|
|
|
$sourceProject->load([
|
|
'boardColumns', 'notificationActions', 'repositoryConnections', 'ticketFieldDefinitions',
|
|
'ticketLinkTypes', 'ticketPriorities', 'ticketStatuses.allowedTargetStatuses', 'ticketTypes',
|
|
]);
|
|
$configuration = [];
|
|
|
|
if (in_array(self::COPY_PROJECT_SETTINGS, $selectedAreas, true)) {
|
|
$configuration[self::COPY_PROJECT_SETTINGS] = [
|
|
'show_author' => $sourceProject->show_author,
|
|
'show_story_points' => $sourceProject->show_story_points,
|
|
];
|
|
}
|
|
|
|
$columnKeys = $sourceProject->boardColumns->values()->mapWithKeys(
|
|
static fn ($column): array => [$column->id => $column->configuration_key],
|
|
);
|
|
$statusKeys = $sourceProject->ticketStatuses->values()->mapWithKeys(
|
|
static fn ($status): array => [$status->id => $status->configuration_key],
|
|
);
|
|
|
|
if (in_array(self::COPY_BOARD_COLUMNS, $selectedAreas, true)) {
|
|
$configuration[self::COPY_BOARD_COLUMNS] = $sourceProject->boardColumns->values()->map(
|
|
static fn ($column): array => ['configuration_key' => $column->configuration_key, 'name' => $column->name, 'position' => $column->position],
|
|
)->all();
|
|
}
|
|
|
|
if (in_array(self::COPY_TICKET_STATUSES, $selectedAreas, true)) {
|
|
$configuration[self::COPY_TICKET_STATUSES] = $sourceProject->ticketStatuses->values()->map(
|
|
static fn ($status): array => [
|
|
'configuration_key' => $status->configuration_key,
|
|
'board_column_key' => $status->board_column_id === null ? null : $columnKeys->get($status->board_column_id),
|
|
'name' => $status->name,
|
|
'position' => $status->position,
|
|
],
|
|
)->all();
|
|
}
|
|
|
|
if (in_array(self::COPY_STATUS_TRANSITIONS, $selectedAreas, true)) {
|
|
$configuration[self::COPY_STATUS_TRANSITIONS] = $sourceProject->ticketStatuses->values()->map(
|
|
static fn ($status): array => [
|
|
'status_key' => $status->configuration_key,
|
|
'target_keys' => $status->allowedTargetStatuses->pluck('id')->map(
|
|
static fn (int $id): ?string => $statusKeys->get($id),
|
|
)->filter()->sort()->values()->all(),
|
|
],
|
|
)->all();
|
|
}
|
|
|
|
$simpleAreas = [
|
|
self::COPY_TICKET_TYPES => fn ($item): array => ['name' => $item->name, 'position' => $item->position, 'is_parent' => $item->is_parent],
|
|
self::COPY_TICKET_PRIORITIES => fn ($item): array => ['name' => $item->name, 'position' => $item->position],
|
|
self::COPY_TICKET_FIELDS => fn ($item): array => ['field_type' => $item->field_type, 'label' => $item->label, 'position' => $item->position],
|
|
self::COPY_TICKET_LINK_TYPES => fn ($item): array => ['label' => $item->label, 'counterpart_label' => $item->counterpart_label, 'position' => $item->position],
|
|
self::COPY_REPOSITORY_CONNECTIONS => fn ($item): array => [
|
|
'provider' => $item->provider->value, 'base_url' => $item->base_url,
|
|
'provider_repository_id' => $item->provider_repository_id, 'owner_name' => $item->owner_name,
|
|
'repository_name' => $item->repository_name, 'repository_full_name' => $item->repository_full_name,
|
|
'repository_url' => $item->repository_url,
|
|
],
|
|
self::COPY_NOTIFICATION_ACTIONS => fn ($item): array => [
|
|
'name' => $item->name, 'enabled' => $item->enabled, 'event_type' => $item->event_type->value,
|
|
'channel' => $item->channel->value, 'channel_configuration' => $item->channel_configuration ?? [],
|
|
'message_template' => $item->message_template, 'delivery_url' => $item->delivery_url,
|
|
'filters' => $this->mapNotificationFilters($item->filters ?? [], $statusKeys->all()),
|
|
],
|
|
];
|
|
$relations = [
|
|
self::COPY_TICKET_TYPES => 'ticketTypes', self::COPY_TICKET_PRIORITIES => 'ticketPriorities',
|
|
self::COPY_TICKET_FIELDS => 'ticketFieldDefinitions', self::COPY_TICKET_LINK_TYPES => 'ticketLinkTypes',
|
|
self::COPY_REPOSITORY_CONNECTIONS => 'repositoryConnections', self::COPY_NOTIFICATION_ACTIONS => 'notificationActions',
|
|
];
|
|
|
|
foreach ($simpleAreas as $area => $mapper) {
|
|
if (in_array($area, $selectedAreas, true)) {
|
|
$configuration[$area] = $sourceProject->{$relations[$area]}->values()->map(
|
|
static fn ($item): array => ['configuration_key' => $item->configuration_key, ...$mapper($item)],
|
|
)->all();
|
|
}
|
|
}
|
|
|
|
return $configuration;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $configuration
|
|
* @param array<int|string, int|string> $statusReplacements
|
|
* @return list<string> Areas which retain referenced project configuration.
|
|
*/
|
|
public function apply(Project $targetProject, array $configuration, array $statusReplacements = [], bool $adoptExisting = false): array
|
|
{
|
|
return DB::transaction(function () use ($targetProject, $configuration, $statusReplacements, $adoptExisting): array {
|
|
$targetProject = Project::query()->whereKey($targetProject->id)->lockForUpdate()->firstOrFail();
|
|
|
|
return $this->applyLocked($targetProject, $configuration, $statusReplacements, $adoptExisting);
|
|
}, 3);
|
|
}
|
|
|
|
/** @param array<string, mixed> $configuration @param array<int|string, int|string> $statusReplacements @return list<string> */
|
|
private function applyLocked(Project $targetProject, array $configuration, array $statusReplacements, bool $adoptExisting): array
|
|
{
|
|
$configuration = $this->normalizeConfiguration($configuration);
|
|
$blockedAreas = $this->projectTemplateOverrideManager->withoutRecording(function () use ($targetProject, $configuration, $statusReplacements, $adoptExisting): array {
|
|
$blockedAreas = [];
|
|
if (isset($configuration[self::COPY_PROJECT_SETTINGS])) {
|
|
$targetProject->forceFill($configuration[self::COPY_PROJECT_SETTINGS])->saveQuietly();
|
|
}
|
|
|
|
if (isset($configuration[self::COPY_BOARD_COLUMNS])) {
|
|
$currentStatuses = $targetProject->ticketStatuses()->withCount('tickets')->get();
|
|
$nextStatuses = collect($configuration[self::COPY_TICKET_STATUSES] ?? [])->keyBy('configuration_key');
|
|
$columnKeys = array_column($configuration[self::COPY_BOARD_COLUMNS], 'configuration_key');
|
|
$statusesCanChange = isset($configuration[self::COPY_TICKET_STATUSES]) && $currentStatuses->every(
|
|
static fn ($status): bool => $nextStatuses->has($status->configuration_key)
|
|
|| $status->tickets_count === 0 || array_key_exists($status->id, $statusReplacements),
|
|
);
|
|
$canDeleteColumn = static fn (Model $column): bool => $currentStatuses->where('board_column_id', $column->id)->every(
|
|
static function ($status) use ($column, $statusesCanChange, $nextStatuses, $columnKeys): bool {
|
|
if (! $statusesCanChange) {
|
|
return false;
|
|
}
|
|
$next = $nextStatuses->get($status->configuration_key);
|
|
$nextColumn = $next['board_column_key'] ?? null;
|
|
|
|
return $next === null || ($nextColumn !== $column->configuration_key
|
|
&& ($nextColumn === null || in_array($nextColumn, $columnKeys, true)));
|
|
},
|
|
);
|
|
if ($this->syncModels($targetProject, self::COPY_BOARD_COLUMNS, $configuration[self::COPY_BOARD_COLUMNS],
|
|
$canDeleteColumn, $adoptExisting)) {
|
|
$blockedAreas[] = self::COPY_BOARD_COLUMNS;
|
|
}
|
|
}
|
|
|
|
if (isset($configuration[self::COPY_TICKET_STATUSES])) {
|
|
$columns = $targetProject->boardColumns()->get()->keyBy('configuration_key');
|
|
$existingStatuses = $targetProject->ticketStatuses()->get()->keyBy('configuration_key');
|
|
$items = collect($configuration[self::COPY_TICKET_STATUSES])->map(static function (array $item) use ($columns, $existingStatuses): array {
|
|
$columnKey = $item['board_column_key'] ?? null;
|
|
$item['board_column_id'] = $columnKey === null
|
|
? null
|
|
: ($columns->get($columnKey)?->id ?? $existingStatuses->get($item['configuration_key'])?->board_column_id);
|
|
$item['slug'] = Str::slug($item['name']);
|
|
unset($item['board_column_key']);
|
|
|
|
return $item;
|
|
})->all();
|
|
$templateKeys = array_column($items, 'configuration_key');
|
|
$canDelete = static fn (Model $status): bool => ! $status->tickets()->exists()
|
|
|| array_key_exists($status->id, $statusReplacements);
|
|
$beforeDelete = function (Model $status) use ($statusReplacements, $targetProject, $templateKeys): void {
|
|
$replacement = $statusReplacements[$status->id] ?? null;
|
|
if ($replacement === null) {
|
|
return;
|
|
}
|
|
$replacementStatus = $targetProject->ticketStatuses()->whereIn('configuration_key', $templateKeys)
|
|
->where('configuration_key', (string) $replacement)->first();
|
|
if ($replacementStatus === null && is_numeric($replacement)) {
|
|
$replacementStatus = $targetProject->ticketStatuses()->whereIn('configuration_key', $templateKeys)->find($replacement);
|
|
}
|
|
if ($replacementStatus === null) {
|
|
throw ValidationException::withMessages([
|
|
'status_replacements.'.$status->id => 'Choose a replacement from the current template.',
|
|
]);
|
|
}
|
|
$status->tickets()->update(['ticket_status_id' => $replacementStatus->id]);
|
|
$this->transferStatusTransitions($targetProject, $status, $replacementStatus, $statusReplacements, $templateKeys);
|
|
};
|
|
if ($this->syncModels($targetProject, self::COPY_TICKET_STATUSES, $items, $canDelete, $adoptExisting, $beforeDelete)) {
|
|
$blockedAreas[] = self::COPY_TICKET_STATUSES;
|
|
}
|
|
}
|
|
|
|
if (isset($configuration[self::COPY_STATUS_TRANSITIONS])) {
|
|
$statuses = $targetProject->ticketStatuses()->get()->keyBy('configuration_key');
|
|
foreach ($configuration[self::COPY_STATUS_TRANSITIONS] as $transition) {
|
|
$status = $statuses->get($transition['status_key']);
|
|
if ($status !== null) {
|
|
$status->allowedTargetStatuses()->sync(collect($transition['target_keys'])->map(
|
|
static fn (string $key): ?int => $statuses->get($key)?->id,
|
|
)->filter()->all());
|
|
}
|
|
}
|
|
}
|
|
|
|
$guards = [
|
|
self::COPY_TICKET_TYPES => static fn (Model $item): bool => ! $item->tickets()->exists(),
|
|
self::COPY_TICKET_PRIORITIES => static fn (Model $item): bool => ! $item->tickets()->exists(),
|
|
self::COPY_TICKET_FIELDS => static fn (Model $item): bool => ! $item->ticketFieldValues()->exists(),
|
|
self::COPY_TICKET_LINK_TYPES => static fn (Model $item): bool => ! $item->ticketLinks()->exists(),
|
|
self::COPY_REPOSITORY_CONNECTIONS => null,
|
|
self::COPY_NOTIFICATION_ACTIONS => null,
|
|
];
|
|
foreach ($guards as $area => $canDelete) {
|
|
if (! isset($configuration[$area])) {
|
|
continue;
|
|
}
|
|
$items = $configuration[$area];
|
|
if ($area === self::COPY_NOTIFICATION_ACTIONS) {
|
|
$statusIds = $targetProject->ticketStatuses()->pluck('id', 'configuration_key')->all();
|
|
$items = array_map(fn (array $item): array => [
|
|
...$item, 'filters' => $this->mapNotificationFilters($item['filters'] ?? [], $statusIds),
|
|
], $items);
|
|
}
|
|
if ($this->syncModels($targetProject, $area, $items, $canDelete, $adoptExisting)) {
|
|
$blockedAreas[] = $area;
|
|
}
|
|
}
|
|
|
|
foreach ($targetProject->configurationRelations() as $relation) {
|
|
$targetProject->{$relation}()->update(['project_template_id' => $targetProject->project_template_id]);
|
|
}
|
|
|
|
return $blockedAreas;
|
|
});
|
|
foreach ($blockedAreas as $area) {
|
|
$this->projectTemplateOverrideManager->mark($targetProject->fresh(), $area);
|
|
}
|
|
|
|
return $blockedAreas;
|
|
}
|
|
|
|
/** @param list<string> $copyAreas */
|
|
public function handle(Project $sourceProject, Project $targetProject, array $copyAreas): void
|
|
{
|
|
$this->apply($targetProject, $this->export($sourceProject, $copyAreas), adoptExisting: true);
|
|
}
|
|
|
|
/** @param list<array<string, mixed>> $filters @param array<int|string, int|string> $mapping @return list<array<string, mixed>> */
|
|
public function mapNotificationFilters(array $filters, array $mapping): array
|
|
{
|
|
return array_map(static function (array $filter) use ($mapping): array {
|
|
if (! in_array($filter['attribute'], ['status.from.id', 'status.to.id'], true)) {
|
|
return $filter;
|
|
}
|
|
$map = static fn (string $value): string => (string) ($mapping[$value] ?? $value);
|
|
$filter['value'] = is_array($filter['value'])
|
|
? array_map($map, $filter['value'])
|
|
: ($filter['value'] === null ? null : $map($filter['value']));
|
|
|
|
return $filter;
|
|
}, app(NormalizeNotificationFilters::class)->handle($filters));
|
|
}
|
|
|
|
/** @param array<int|string, int|string> $replacements @param list<string> $templateKeys */
|
|
private function transferStatusTransitions(Project $project, TicketStatus $removed, TicketStatus $replacement, array $replacements, array $templateKeys): void
|
|
{
|
|
$statuses = $project->ticketStatuses()->get();
|
|
$targets = $statuses->whereIn('configuration_key', $templateKeys);
|
|
$mapping = [];
|
|
foreach ($statuses as $status) {
|
|
if (in_array($status->configuration_key, $templateKeys, true)) {
|
|
$mapping[$status->id] = $status->id;
|
|
|
|
continue;
|
|
}
|
|
$target = $replacements[$status->id] ?? null;
|
|
if (is_scalar($target)) {
|
|
$mapping[$status->id] = $targets->firstWhere('configuration_key', (string) $target)?->id
|
|
?? (is_numeric($target) ? $targets->firstWhere('id', (int) $target)?->id : null);
|
|
}
|
|
}
|
|
$mapping[$removed->id] = $replacement->id;
|
|
$edges = DB::table('ticket_status_transitions')->where('from_ticket_status_id', $removed->id)
|
|
->orWhere('to_ticket_status_id', $removed->id)->get();
|
|
foreach ($edges as $edge) {
|
|
$from = $mapping[$edge->from_ticket_status_id] ?? null;
|
|
$to = $mapping[$edge->to_ticket_status_id] ?? null;
|
|
if ($from !== null && $to !== null && $from !== $to) {
|
|
$statuses->firstWhere('id', $from)->allowedTargetStatuses()->syncWithoutDetaching([$to]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param list<array<string, mixed>> $items
|
|
*/
|
|
private function syncModels(Project $project, string $area, array $items, ?callable $canDelete, bool $adoptExisting, ?callable $beforeDelete = null): bool
|
|
{
|
|
$relation = ProjectConfigurationIdentity::relations()[$area];
|
|
$models = $project->{$relation}()->get();
|
|
$byKey = $models->keyBy('configuration_key');
|
|
$matched = [];
|
|
$assignments = [];
|
|
foreach ($items as $item) {
|
|
$model = $byKey->get($item['configuration_key']);
|
|
if ($model === null && $adoptExisting) {
|
|
$candidates = $models->filter(fn (Model $candidate): bool => ! in_array($candidate->id, $matched, true)
|
|
&& $this->projectConfigurationIdentity->signature($area, $candidate->attributesToArray()) === $this->projectConfigurationIdentity->signature($area, $item));
|
|
$model = $candidates->count() === 1 ? $candidates->first() : null;
|
|
}
|
|
if ($model !== null) {
|
|
$matched[] = $model->id;
|
|
if ($area === self::COPY_TICKET_FIELDS && $model->field_type !== $item['field_type'] && $model->ticketFieldValues()->exists()) {
|
|
return true;
|
|
}
|
|
if ($area === self::COPY_TICKET_TYPES && $model->is_parent && ! ($item['is_parent'] ?? false)
|
|
&& $model->tickets()->whereHas('childTickets')->exists()) {
|
|
return true;
|
|
}
|
|
}
|
|
$assignments[] = [$model, $item];
|
|
}
|
|
$removed = $models->reject(static fn (Model $model): bool => in_array($model->id, $matched, true));
|
|
foreach ($removed as $model) {
|
|
if ($canDelete !== null && ! $canDelete($model)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if ($area === self::COPY_REPOSITORY_CONNECTIONS) {
|
|
foreach ($models as $model) {
|
|
$model->forceFill(['provider_repository_id' => 'template-sync-'.Str::uuid()])->saveQuietly();
|
|
}
|
|
}
|
|
|
|
if ($models->isNotEmpty() && $models->first()->getAttribute('position') !== null) {
|
|
$offset = max((int) $models->max('position'), (int) collect($items)->max('position')) + $models->count() + count($items) + 1;
|
|
foreach ($models->values() as $index => $model) {
|
|
$model->forceFill(['position' => $offset + $index])->saveQuietly();
|
|
}
|
|
}
|
|
foreach ($assignments as [$model, $item]) {
|
|
$model === null ? $project->{$relation}()->create($item) : $model->forceFill($item)->saveQuietly();
|
|
}
|
|
foreach ($removed as $model) {
|
|
if ($beforeDelete !== null) {
|
|
$beforeDelete($model);
|
|
}
|
|
$model->deleteQuietly();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|