Skip to content

A free open source IT asset/license management system

bulk changes that should make this work

spencerrlongg59ccc70303f0
diff --git a/app/Actions/Manufacturers/DeleteManufacturerAction.php b/app/Actions/Manufacturers/DeleteManufacturerAction.php
index fc84b1d72d..e586c166ef 100644
--- a/app/Actions/Manufacturers/DeleteManufacturerAction.php
+++ b/app/Actions/Manufacturers/DeleteManufacturerAction.php
@@ -20,9 +20,8 @@ class DeleteManufacturerAction
* @throws ModelStillHasLicenses
* @throws ModelStillHasConsumables
*/
- static function run(?Manufacturer $manufacturer): bool
+ static function run(Manufacturer $manufacturer): bool
{
- Manufacturer::firstOrFail($manufacturer->id);
$manufacturer->loadCount([
'assets as assets_count',
'accessories as accessories_count',
diff --git a/app/Http/Controllers/BulkManufacturersController.php b/app/Http/Controllers/BulkManufacturersController.php
index ed9f80580d..c01de8db37 100644
--- a/app/Http/Controllers/BulkManufacturersController.php
+++ b/app/Http/Controllers/BulkManufacturersController.php
@@ -18,12 +18,20 @@ class BulkManufacturersController extends Controller
{
public function destroy(Request $request)
{
+ // hm, we actually probably need to do this on a per model basis below, but that makes this a little dirtier so leaving like this for now.
+ $this->authorize('delete', Manufacturer::class);
+
$errors = [];
foreach ($request->ids as $id) {
+ $manufacturer = Manufacturer::find($id);
+ if (is_null($manufacturer)) {
+ $errors[] = 'Manufacturer not found';
+ continue;
+ }
try {
- DeleteManufacturerAction::run(manufacturer: $id);
+ DeleteManufacturerAction::run(manufacturer: $manufacturer);
} catch (ModelStillHasAccessories|ModelStillHasAssets|ModelStillHasComponents|ModelStillHasConsumables|ModelStillHasLicenses $e) {
- $errors[] = `{$id} still has {$id->thing}`;
+ $errors[] = `{$manufacturer->name} still has models`;
} catch (\Exception $e) {
report($e);
$errors[] = 'Something went wrong';