mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
Merge branch 'develop'
This commit is contained in:
commit
b5f1e10b45
|
@ -266,17 +266,23 @@ class Asset extends Depreciable
|
|||
throw new \Exception("Asset assignment Loop for Asset ID: ".$first_asset->id);
|
||||
}
|
||||
$assigned_to=Asset::find($this->assigned_to); //have to do this this way because otherwise it errors
|
||||
return $assigned_to->assetLoc(); // Recurse until we have a final location
|
||||
if ($assigned_to) {
|
||||
return $assigned_to->assetLoc();
|
||||
} // Recurse until we have a final location
|
||||
}
|
||||
if ($this->assignedType() == self::LOCATION) {
|
||||
if ($this->assignedTo) {
|
||||
return $this->assignedTo;
|
||||
}
|
||||
|
||||
}
|
||||
if ($this->assignedType() == self::USER) {
|
||||
if (!$this->assignedTo->userLoc) {
|
||||
if (($this->assignedTo) && $this->assignedTo->userLoc) {
|
||||
return $this->assignedTo->userLoc;
|
||||
}
|
||||
//this makes no sense
|
||||
return $this->defaultLoc;
|
||||
}
|
||||
return $this->assignedTo->userLoc;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class MigrateDenormedAssetLocations extends Migration
|
|||
}
|
||||
|
||||
// Assigned to locations // with('assetloc')-> //can't eager-load polymorphic relationships
|
||||
$assigned_location_assets = Asset::where('assigned_type',Location::class)->get();
|
||||
$assigned_location_assets = Asset::where('assigned_type',Location::class)->whereNotNull('assigned_to')->get();
|
||||
\Log::info('Location-assigned assets: ');
|
||||
foreach ($assigned_location_assets as $assigned_location_asset) {
|
||||
$assigned_location_asset->location_id=$assigned_location_asset->assignedTo->id;
|
||||
|
@ -55,16 +55,20 @@ class MigrateDenormedAssetLocations extends Migration
|
|||
}
|
||||
|
||||
// Assigned to assets
|
||||
$assigned_asset_assets = Asset::with('assetloc')->where('assigned_type',Asset::class)->get();
|
||||
$assigned_asset_assets = Asset::where('assigned_type',Asset::class)->whereNotNull('assigned_to')->with('assetloc')->get();
|
||||
\Log::info('Asset-assigned assets: ');
|
||||
foreach ($assigned_asset_assets as $assigned_asset_asset) {
|
||||
\Log::info('This asset is: '.$assigned_asset_asset->assignedTo->asset_tag);
|
||||
if ($assigned_asset_asset->assignedTo->location) {
|
||||
if (($assigned_asset_asset->assignedTo) && ($assigned_asset_asset->assignedTo->location)) {
|
||||
\Log::info('They are in '.$assigned_asset_asset->assignedTo->location->name);
|
||||
}
|
||||
if ($assigned_asset_asset->assetloc) {
|
||||
\Log::info('User location is: '.$assigned_asset_asset->assetloc->name);
|
||||
\Log::info('Setting asset '.$assigned_asset_asset->id.' location to '.$assigned_asset_asset->assetloc->id.' ('.$assigned_asset_asset->assetloc->name.')');
|
||||
$assigned_asset_asset->location_id=$assigned_asset_asset->assetloc->id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,7 @@ class MigrateDenormedAssetLocations extends Migration
|
|||
$assets = Asset::get();
|
||||
|
||||
foreach ($assets as $asset) {
|
||||
if (($asset) && ($asset->location_id != $asset->assetLoc()->id)) {
|
||||
if (($asset) && ($asset->assetLoc()) && ($asset->location_id != $asset->assetLoc()->id)) {
|
||||
\Log::info('MISMATCH MISMATCH '.$asset->id. "doesn't match its location");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue