bulk changes that should make this work

This commit is contained in:
spencerrlongg
2025-07-10 16:02:39 -05:00
parent f1584b722d
commit 59ccc70303
2 changed files with 11 additions and 4 deletions

View File

@@ -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',

View File

@@ -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';