3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 03:06:23 +00:00

Created better maintenance names (ones that look realistic)

This commit is contained in:
snipe
2026-08-14 13:40:06 +01:00
parent 6640192b36
commit d1e2e78bcc
2 changed files with 78 additions and 13 deletions

View File

@ -23,6 +23,43 @@ class MaintenanceFactory extends Factory
*
* @return array
*/
/**
* Short, realistic maintenance names so seeded / demo rows look
* plausible in the list, calendar, and other views instead of the
* Faker `sentence(3)` output ("Ipsum quos aut voluptatum.") that
* was there before.
*/
private const NAMES = [
'Battery replacement',
'Screen repair',
'Keyboard replacement',
'Fan replacement',
'Firmware update',
'OS reinstall',
'Cleaning',
'RAM upgrade',
'Hard drive replacement',
'Warranty repair',
'Annual service',
'Diagnostic check',
'Screen calibration',
'Cable replacement',
'Charging port repair',
];
/**
* Define the model's default state.
*
* Default state is a plain-active maintenance (no expected end,
* no completion) so existing feature tests that call
* ->factory()->create() and rely on that shape still pass. The
* ->realistic() state below is what the seeder uses for
* demo/dev data — anchored dates, expected end, and sometimes
* completed_at populated so the calendar and list views show a
* plausible mix.
*
* @return array
*/
public function definition()
{
$maintenanceType = MaintenanceType::factory()->create();
@ -39,14 +76,42 @@ class MaintenanceFactory extends Factory
'supplier_id' => Supplier::factory(),
'maintenance_type_id' => $maintenanceType->id,
'asset_maintenance_type' => $maintenanceType->name,
'name' => $this->faker->sentence(3),
'name' => $this->faker->randomElement(self::NAMES),
'start_date' => $this->faker->dateTime()->format('Y-m-d H:i:s'),
'is_warranty' => $this->faker->boolean(),
'notes' => $this->faker->paragraph(),
'url' => $this->faker->url(),
'cost' => $this->faker->randomFloat(),
'cost' => $this->faker->randomFloat(2, 5, 500),
'created_by' => User::factory()->superuser(),
'image' => $this->faker->numberBetween(1, 11).'.png',
];
}
/**
* Seeder-friendly state that produces a maintenance with
* start_date anchored around today, an expected_completion_date
* a few days out, and a ~40% chance of already being completed
* (for past-start rows only). Produces a plausible mix on the
* calendar / list views so demo installs don't render as
* "everything from 1974".
*/
public function realistic(): static
{
return $this->state(function () {
$startDate = $this->faker->dateTimeBetween('-6 months', '+3 months');
$startCarbon = \Carbon\Carbon::instance($startDate);
$expectedEnd = (clone $startCarbon)->addDays($this->faker->numberBetween(1, 21));
$isCompletable = $startCarbon->isPast() && $this->faker->boolean(40);
$completedAt = $isCompletable
? $this->faker->dateTimeBetween($startCarbon, min($expectedEnd, \Carbon\Carbon::now()))
: null;
return [
'start_date' => $startCarbon->format('Y-m-d H:i:s'),
'expected_completion_date' => $expectedEnd->format('Y-m-d H:i:s'),
'completed_at' => $completedAt?->format('Y-m-d H:i:s'),
];
});
}
}

View File

@ -12,17 +12,17 @@ class MaintenanceSeeder extends Seeder
public function run()
{
Maintenance::truncate();
Maintenance::factory()->create(['image' => '1.png']);
Maintenance::factory()->create(['image' => '2.png']);
Maintenance::factory()->create(['image' => '3.png']);
Maintenance::factory()->create(['image' => '4.png']);
Maintenance::factory()->create(['image' => '5.png']);
Maintenance::factory()->create(['image' => '6.png']);
Maintenance::factory()->create(['image' => '7.png']);
Maintenance::factory()->create(['image' => '8.png']);
Maintenance::factory()->create(['image' => '9.png']);
Maintenance::factory()->create(['image' => '10.png']);
Maintenance::factory()->create(['image' => '11.png']);
Maintenance::factory()->realistic()->create(['image' => '1.png']);
Maintenance::factory()->realistic()->create(['image' => '2.png']);
Maintenance::factory()->realistic()->create(['image' => '3.png']);
Maintenance::factory()->realistic()->create(['image' => '4.png']);
Maintenance::factory()->realistic()->create(['image' => '5.png']);
Maintenance::factory()->realistic()->create(['image' => '6.png']);
Maintenance::factory()->realistic()->create(['image' => '7.png']);
Maintenance::factory()->realistic()->create(['image' => '8.png']);
Maintenance::factory()->realistic()->create(['image' => '9.png']);
Maintenance::factory()->realistic()->create(['image' => '10.png']);
Maintenance::factory()->realistic()->create(['image' => '11.png']);
$src = public_path('/img/demo/maintenances/');
$dst = 'maintenances'.'/';