-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fixed #8709 - Bulk Deletion of Categories, Suppliers, Manufa... #17573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
ee5aac8
a0431e1
1745648
5e81c63
1cee7e4
13c971b
5da79cd
db63ad1
d5ca543
5f835aa
4d8c5a8
f1584b7
59ccc70
7cdfaa9
f590fcf
b61419c
3eefeec
d0e068f
0dcdfc5
5cd5392
6159ee8
78ca1d1
3052029
e33b1b6
b934f43
643d44a
a091baf
c429964
c39d484
fdb0651
7b6c0c3
1d88cf4
51f6927
c450c0d
526bb2c
1d24b79
36f5099
32882f8
b9f4dc1
24bb45a
5fdb999
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Categories; | ||
|
|
||
| use App\Exceptions\ModelIsNotDeletable; | ||
| use App\Exceptions\ModelStillHasAccessories; | ||
| use App\Exceptions\ModelStillHasAssetModels; | ||
| use App\Exceptions\ModelStillHasAssets; | ||
| use App\Exceptions\ModelStillHasComponents; | ||
| use App\Exceptions\ModelStillHasConsumables; | ||
| use App\Exceptions\ModelStillHasLicenses; | ||
| use App\Helpers\Helper; | ||
| use App\Models\Category; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class DestroyCategoryAction | ||
| { | ||
| /** | ||
| * @throws ModelStillHasAssets | ||
| * @throws ModelStillHasAssetModels | ||
| * @throws ModelStillHasComponents | ||
| * @throws ModelStillHasAccessories | ||
| * @throws ModelStillHasLicenses | ||
| * @throws ModelStillHasConsumables | ||
| */ | ||
| static function run(Category $category): bool | ||
| { | ||
| $category->loadCount([ | ||
| 'assets as assets_count', | ||
| 'accessories as accessories_count', | ||
| 'consumables as consumables_count', | ||
| 'components as components_count', | ||
| 'licenses as licenses_count', | ||
| 'models as models_count' | ||
| ]); | ||
|
|
||
| if ($category->assets_count > 0) { | ||
| throw new ModelStillHasAssets($category); | ||
| } | ||
| if ($category->accessories_count > 0) { | ||
| throw new ModelStillHasAccessories($category); | ||
| } | ||
| if ($category->consumables_count > 0) { | ||
| throw new ModelStillHasConsumables($category); | ||
| } | ||
| if ($category->components_count > 0) { | ||
| throw new ModelStillHasComponents($category); | ||
| } | ||
| if ($category->licenses_count > 0) { | ||
| throw new ModelStillHasLicenses($category); | ||
| } | ||
| if ($category->models_count > 0) { | ||
| throw new ModelStillHasAssetModels($category); | ||
| } | ||
|
|
||
| Storage::disk('public')->delete('categories'.'/'.$category->image); | ||
| $category->delete(); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Manufacturers; | ||
|
|
||
| use App\Exceptions\ModelStillHasAccessories; | ||
| use App\Exceptions\ModelStillHasAssets; | ||
| use App\Exceptions\ModelStillHasComponents; | ||
| use App\Exceptions\ModelStillHasConsumables; | ||
| use App\Exceptions\ModelStillHasLicenses; | ||
| use App\Models\Manufacturer; | ||
| use Illuminate\Support\Facades\Log; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class DeleteManufacturerAction | ||
| { | ||
| /** | ||
| * @throws ModelStillHasAssets | ||
| * @throws ModelStillHasComponents | ||
| * @throws ModelStillHasAccessories | ||
| * @throws ModelStillHasLicenses | ||
| * @throws ModelStillHasConsumables | ||
| */ | ||
| static function run(Manufacturer $manufacturer): bool | ||
| { | ||
| $manufacturer->loadCount([ | ||
| 'assets as assets_count', | ||
| 'accessories as accessories_count', | ||
| 'consumables as consumables_count', | ||
| 'components as components_count', | ||
| 'licenses as licenses_count', | ||
| ]); | ||
|
|
||
| if ($manufacturer->assets_count > 0) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda feel like all these checks could get put in something like: And then you can make |
||
| throw new ModelStillHasAssets($manufacturer); | ||
| } | ||
| if ($manufacturer->accessories_count > 0) { | ||
| throw new ModelStillHasAccessories($manufacturer); | ||
| } | ||
| if ($manufacturer->consumables_count > 0) { | ||
| throw new ModelStillHasConsumables($manufacturer); | ||
| } | ||
| if ($manufacturer->components_count > 0) { | ||
| throw new ModelStillHasComponents($manufacturer); | ||
| } | ||
| if ($manufacturer->licenses_count > 0) { | ||
| throw new ModelStillHasLicenses($manufacturer); | ||
| } | ||
|
|
||
| if ($manufacturer->image) { | ||
| try { | ||
| Storage::disk('public')->delete('manufacturers/'.$manufacturer->image); | ||
| } catch (\Exception $e) { | ||
| Log::info($e); | ||
| } | ||
| } | ||
|
|
||
| $manufacturer->delete(); | ||
| //dd($manufacturer); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Suppliers; | ||
|
|
||
| use App\Models\Supplier; | ||
| use App\Exceptions\ModelStillHasAssets; | ||
| use App\Exceptions\ModelStillHasMaintenances; | ||
| use App\Exceptions\ModelStillHasLicenses; | ||
| use Illuminate\Support\Facades\Log; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class DestroySupplierAction | ||
| { | ||
| /** | ||
| * @throws ModelStillHasLicenses | ||
| * @throws ModelStillHasAssets | ||
| * @throws ModelStillHasMaintenances | ||
| */ | ||
| static function run(Supplier $supplier): bool | ||
| { | ||
| $supplier->loadCount([ | ||
| 'maintenances as maintenances_count', | ||
| 'assets as assets_count', | ||
| 'licenses as licenses_count' | ||
spencerrlongg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ]); | ||
| if ($supplier->assets_count > 0) { | ||
| throw new ModelStillHasAssets($supplier); | ||
| } | ||
|
|
||
| if ($supplier->maintenances_count > 0) { | ||
| throw new ModelStillHasMaintenances($supplier); | ||
| } | ||
|
|
||
| if ($supplier->licenses_count > 0) { | ||
| throw new ModelStillHasLicenses($supplier); | ||
| } | ||
|
|
||
| if ($supplier->image) { | ||
| try { | ||
| Storage::disk('public')->delete('suppliers/'.$supplier->image); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we restore these categories, etc, the image will be broken |
||
| } catch (\Exception $e) { | ||
| Log::info($e->getMessage()); | ||
| } | ||
| } | ||
|
|
||
| $supplier->delete(); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasAccessories extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasAssetModels extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasAssets extends ModelStillHasChildren | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasChildren extends Exception | ||
| { | ||
| //public function __construct($message, $code = 0, Exception $previous = null, $parent, $children) | ||
| //{ | ||
| // trans() | ||
| // | ||
| //} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasComponents extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasConsumables extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasLicenses extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class ModelStillHasMaintenances extends ModelStillHasChildren | ||
| { | ||
| // | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.