Merge branch 'develop'

This commit is contained in:
snipe 2017-10-31 11:50:47 -07:00
commit b5f1e10b45
2 changed files with 23 additions and 13 deletions

View file

@ -266,17 +266,23 @@ class Asset extends Depreciable
throw new \Exception("Asset assignment Loop for Asset ID: ".$first_asset->id); 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 $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->assignedType() == self::LOCATION) {
return $this->assignedTo; if ($this->assignedTo) {
return $this->assignedTo;
}
} }
if ($this->assignedType() == self::USER) { if ($this->assignedType() == self::USER) {
if (!$this->assignedTo->userLoc) { if (($this->assignedTo) && $this->assignedTo->userLoc) {
//this makes no sense return $this->assignedTo->userLoc;
return $this->defaultLoc;
} }
return $this->assignedTo->userLoc; //this makes no sense
return $this->defaultLoc;
} }
} }

View file

@ -45,7 +45,7 @@ class MigrateDenormedAssetLocations extends Migration
} }
// Assigned to locations // with('assetloc')-> //can't eager-load polymorphic relationships // 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: '); \Log::info('Location-assigned assets: ');
foreach ($assigned_location_assets as $assigned_location_asset) { foreach ($assigned_location_assets as $assigned_location_asset) {
$assigned_location_asset->location_id=$assigned_location_asset->assignedTo->id; $assigned_location_asset->location_id=$assigned_location_asset->assignedTo->id;
@ -55,16 +55,20 @@ class MigrateDenormedAssetLocations extends Migration
} }
// Assigned to assets // 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: '); \Log::info('Asset-assigned assets: ');
foreach ($assigned_asset_assets as $assigned_asset_asset) { foreach ($assigned_asset_assets as $assigned_asset_asset) {
\Log::info('This asset is: '.$assigned_asset_asset->assignedTo->asset_tag); \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); \Log::info('They are in '.$assigned_asset_asset->assignedTo->location->name);
} }
\Log::info('User location is: '.$assigned_asset_asset->assetloc->name); if ($assigned_asset_asset->assetloc) {
\Log::info('Setting asset '.$assigned_asset_asset->id.' location to '.$assigned_asset_asset->assetloc->id.' ('.$assigned_asset_asset->assetloc->name.')'); \Log::info('User location is: '.$assigned_asset_asset->assetloc->name);
$assigned_asset_asset->location_id=$assigned_asset_asset->assetloc->id; \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(); $assets = Asset::get();
foreach ($assets as $asset) { 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"); \Log::info('MISMATCH MISMATCH '.$asset->id. "doesn't match its location");
} }
} }