mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Cleaner re-implementation of loop-detection for asset-assigned-assets (#4553)
* Cleaner re-implementation of loop-detection for asset-assigned-assets * Get rid of the other static and pass it along recursively too.
This commit is contained in:
parent
d7f2bceea2
commit
4584990cc3
|
@ -109,7 +109,7 @@ class SyncAssetLocations extends Command
|
||||||
$assigned_asset_asset->unsetEventDispatcher();
|
$assigned_asset_asset->unsetEventDispatcher();
|
||||||
$assigned_asset_asset->save();
|
$assigned_asset_asset->save();
|
||||||
} else {
|
} else {
|
||||||
$output['warn'][] ='Asset Assigned asset ' . $assigned_asset_asset->assetLoc()->id. ' ('.$assigned_asset_asset->asset_tag.') does not seem to have a valid location';
|
$output['warn'][] ='Asset Assigned asset ' . $assigned_asset_asset->id. ' ('.$assigned_asset_asset->asset_tag.') does not seem to have a valid location';
|
||||||
}
|
}
|
||||||
|
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
|
|
|
@ -257,13 +257,10 @@ class Asset extends Depreciable
|
||||||
/**
|
/**
|
||||||
* Get the asset's location based on the assigned user
|
* Get the asset's location based on the assigned user
|
||||||
**/
|
**/
|
||||||
public function assetLoc()
|
public function assetLoc($iterations = 1,$first_asset = null)
|
||||||
{
|
{
|
||||||
static $iterations=0;
|
|
||||||
static $first_asset;
|
|
||||||
if (!empty($this->assignedType())) {
|
if (!empty($this->assignedType())) {
|
||||||
if ($this->assignedType() == self::ASSET) {
|
if ($this->assignedType() == self::ASSET) {
|
||||||
$iterations++;
|
|
||||||
if(!$first_asset) {
|
if(!$first_asset) {
|
||||||
$first_asset=$this;
|
$first_asset=$this;
|
||||||
}
|
}
|
||||||
|
@ -272,7 +269,7 @@ class Asset extends Depreciable
|
||||||
}
|
}
|
||||||
$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
|
||||||
if ($assigned_to) {
|
if ($assigned_to) {
|
||||||
return $assigned_to->assetLoc();
|
return $assigned_to->assetLoc($iterations + 1, $first_asset);
|
||||||
} // Recurse until we have a final location
|
} // Recurse until we have a final location
|
||||||
}
|
}
|
||||||
if ($this->assignedType() == self::LOCATION) {
|
if ($this->assignedType() == self::LOCATION) {
|
||||||
|
|
Loading…
Reference in a new issue