2024-02-22 13:21:52 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Traits;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
2024-05-29 04:38:15 -07:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-02-22 13:21:52 -08:00
|
|
|
|
2024-02-27 12:06:29 -08:00
|
|
|
trait MigratesLegacyAssetLocations
|
2024-02-22 13:21:52 -08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This is just meant to correct legacy issues where some user data would have 0
|
|
|
|
* as a location ID, which isn't valid. Later versions of Snipe-IT have stricter validation
|
|
|
|
* rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
|
|
|
|
* people (and their data) in the long run
|
|
|
|
* @param Asset $asset
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function migrateLegacyLocations(Asset $asset): void
|
|
|
|
{
|
|
|
|
if ($asset->rtd_location_id == '0') {
|
2024-05-29 04:38:15 -07:00
|
|
|
Log::debug('Manually override the RTD location IDs');
|
|
|
|
Log::debug('Original RTD Location ID: ' . $asset->rtd_location_id);
|
2024-02-22 13:21:52 -08:00
|
|
|
$asset->rtd_location_id = '';
|
2024-05-29 04:38:15 -07:00
|
|
|
Log::debug('New RTD Location ID: ' . $asset->rtd_location_id);
|
2024-02-22 13:21:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($asset->location_id == '0') {
|
2024-05-29 04:38:15 -07:00
|
|
|
Log::debug('Manually override the location IDs');
|
|
|
|
Log::debug('Original Location ID: ' . $asset->location_id);
|
2024-02-22 13:21:52 -08:00
|
|
|
$asset->location_id = '';
|
2024-05-29 04:38:15 -07:00
|
|
|
Log::debug('New Location ID: ' . $asset->location_id);
|
2024-02-22 13:21:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|