Skip to content

Commit cdec567

Browse files
fix: Regenerate the UUID for all models
1 parent 1f791b5 commit cdec567

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/CLI/Commands/UUID/Duplicates.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ protected static function check(CLI $cli, ModelWithContent $model, array &$uuids
2525
$duplicates[] = $uuid;
2626

2727
if ($cli->arg('fix') === true) {
28-
$model->uuid()->clear();
29-
$model->update([
30-
'uuid' => Uuid::generate()
31-
]);
32-
$model->uuid()->populate(true);
28+
29+
// regenerate the UUID for the first model
30+
static::regenerate($uuids[$uuid]);
31+
32+
// regenerate the UUID for this model
33+
static::regenerate($model);
34+
3335
$cli->out('✅ The duplicate UUID ' . $uuid . ' for ' . $model->id() . ' has been regenerated');
3436
} else {
3537
$cli->error('The UUID ' . $uuid . ' for ' . $model->id() . ' exists (' . $uuids[$uuid] . ')');
3638
}
3739
}
3840

39-
$uuids[$uuid] = $model->id();
41+
$uuids[$uuid] = $model;
4042
}
4143

4244
public static function command(CLI $cli): void
@@ -88,4 +90,13 @@ public static function command(CLI $cli): void
8890
exit(1);
8991
}
9092
}
93+
94+
protected static function regenerate(ModelWithContent $model): void
95+
{
96+
$model->uuid()->clear();
97+
$model->update([
98+
'uuid' => Uuid::generate()
99+
]);
100+
$model->uuid()->populate(true);
101+
}
91102
}

0 commit comments

Comments
 (0)