@@ -1562,6 +1562,11 @@ static public function test_locations_fmcs($artisan, $location_id = null, $new_c
15621562 $ locations = Location::all ();
15631563 }
15641564
1565+ // Bail out early if there are no locations
1566+ if ($ locations ->count () == 0 ) {
1567+ return [];
1568+ }
1569+
15651570 foreach ($ locations as $ location ) {
15661571 // in case of an update of a single location, use the newly requested company_id
15671572 if ($ new_company_id ) {
@@ -1600,14 +1605,17 @@ static public function test_locations_fmcs($artisan, $location_id = null, $new_c
16001605 $ items = collect ([])->push ($ location ->$ keyword );
16011606 }
16021607
1608+ $ count = 0 ;
16031609 foreach ($ items as $ item ) {
16041610
1611+
16051612 if ($ item && $ item ->company_id != $ location_company ) {
1613+
16061614 $ mismatched [] = [
16071615 class_basename (get_class ($ item )),
16081616 $ item ->id ,
16091617 $ item ->name ?? $ item ->asset_tag ?? $ item ->serial ?? $ item ->username ,
1610- str_replace ('App \\Models \\' , '' , $ item ->assigned_type ) ?? null ,
1618+ $ item -> assigned_type ? str_replace ('App \\Models \\' , '' , $ item ->assigned_type ) : null ,
16111619 $ item ->company_id ?? null ,
16121620 $ item ->company ->name ?? null ,
16131621// $item->defaultLoc->id ?? null,
@@ -1619,6 +1627,15 @@ class_basename(get_class($item)),
16191627 $ location_company ?? null ,
16201628 ];
16211629
1630+ $ count ++;
1631+
1632+ // Bail early if this is not being run via artisan
1633+ if ((!$ artisan ) && ($ count > 0 )) {
1634+ return $ mismatched ;
1635+ }
1636+
1637+
1638+
16221639 }
16231640 }
16241641 }
0 commit comments